From d80d233e47e6ba1b75f389be48339b9cc8a5ed0c Mon Sep 17 00:00:00 2001 From: patrick Date: Sun, 28 Feb 2021 00:29:26 +0000 Subject: [PATCH 1/3] intern implementation --- fet2020/fet2020/settings.py | 1 + fet2020/fet2020/urls.py | 1 + fet2020/intern/__init__.py | 0 fet2020/intern/admin.py | 57 ++++++++++++++++ fet2020/intern/apps.py | 5 ++ fet2020/intern/forms.py | 49 ++++++++++++++ fet2020/intern/models.py | 101 ++++++++++++++++++++++++++++ fet2020/intern/tests.py | 3 + fet2020/intern/urls.py | 10 +++ fet2020/intern/views.py | 85 +++++++++++++++++++++++ fet2020/static/intern.css | 75 +++++++++++++++++++++ fet2020/templates/intern/docu.html | 75 +++++++++++++++++++++ fet2020/templates/intern/index.html | 29 ++++++++ fet2020/templates/intern/topic.html | 49 ++++++++++++++ fet2020/templates/layout.html | 4 +- 15 files changed, 543 insertions(+), 1 deletion(-) create mode 100644 fet2020/intern/__init__.py create mode 100644 fet2020/intern/admin.py create mode 100644 fet2020/intern/apps.py create mode 100644 fet2020/intern/forms.py create mode 100644 fet2020/intern/models.py create mode 100644 fet2020/intern/tests.py create mode 100644 fet2020/intern/urls.py create mode 100644 fet2020/intern/views.py create mode 100644 fet2020/static/intern.css create mode 100644 fet2020/templates/intern/docu.html create mode 100644 fet2020/templates/intern/index.html create mode 100644 fet2020/templates/intern/topic.html diff --git a/fet2020/fet2020/settings.py b/fet2020/fet2020/settings.py index 8eed5b81..1958da8f 100644 --- a/fet2020/fet2020/settings.py +++ b/fet2020/fet2020/settings.py @@ -81,6 +81,7 @@ INSTALLED_APPS = [ "documents.apps.DocumentsConfig", "blackboard.apps.BlackboardConfig", "tasks.apps.TasksConfig", + "intern.apps.InternConfig", ] MIDDLEWARE = [ diff --git a/fet2020/fet2020/urls.py b/fet2020/fet2020/urls.py index 8f009383..d6014ec0 100644 --- a/fet2020/fet2020/urls.py +++ b/fet2020/fet2020/urls.py @@ -38,6 +38,7 @@ urlpatterns = [ path("member/", include(member_urlpatterns), name="member"), path("blackboard/", include("blackboard.urls"), name="blackboard"), path("tasks/", include("tasks.urls"), name="tasks"), + path("intern/", include("intern.urls"), name="intern"), path( "sitemap.xml", sitemap, diff --git a/fet2020/intern/__init__.py b/fet2020/intern/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/fet2020/intern/admin.py b/fet2020/intern/admin.py new file mode 100644 index 00000000..fe2b8dec --- /dev/null +++ b/fet2020/intern/admin.py @@ -0,0 +1,57 @@ +from django.contrib import admin + +from .models import TopicGroup, Topic, Documentation +from .forms import TopicGroupAdminForm, TopicAdminForm + + +class DocumentationInline(admin.TabularInline): + model = Documentation + extra = 0 + verbose_name = "Dokument" + verbose_name_plural = "Dokument-Übersicht" + + +class TopicInline(admin.TabularInline): + model = Topic + extra = 0 + verbose_name = "Topic" + verbose_name_plural = "Topic-Übersicht" + + +class TopicGroupAdmin(admin.ModelAdmin): + form = TopicGroupAdminForm + model = TopicGroup + search_fields = ("title",) + inlines = (TopicInline,) + + def save_model(self, request, obj, form, change): + obj.created_by = request.user + super().save_model(request, obj, form, change) + + +class TopicAdmin(admin.ModelAdmin): + form = TopicAdminForm + model = Topic + search_fields = ("title",) + inlines = (DocumentationInline,) + + def save_model(self, request, obj, form, change): + obj.created_by = request.user + super().save_model(request, obj, form, change) + + +""" +class DocumentationAdmin(admin.ModelAdmin): + form = DocumentationAdminForm + model = Documentation + + list_display = ["title", "topic"] + + def save_model(self, request, obj, form, change): + obj.created_by = request.user + super().save_model(request, obj, form, change) +""" + +admin.site.register(TopicGroup, TopicGroupAdmin) +admin.site.register(Topic, TopicAdmin) +# admin.site.register(Documentation, DocumentationAdmin) diff --git a/fet2020/intern/apps.py b/fet2020/intern/apps.py new file mode 100644 index 00000000..b2d0203a --- /dev/null +++ b/fet2020/intern/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class InternConfig(AppConfig): + name = "intern" diff --git a/fet2020/intern/forms.py b/fet2020/intern/forms.py new file mode 100644 index 00000000..f2863d49 --- /dev/null +++ b/fet2020/intern/forms.py @@ -0,0 +1,49 @@ +from django import forms +from django.utils.translation import gettext_lazy as _ + +from ckeditor_uploader.widgets import CKEditorUploadingWidget + +from .models import TopicGroup, Topic, Documentation, Document + + +class TopicGroupAdminForm(forms.ModelForm): + class Meta: + model = TopicGroup + fields = [ + "title", + ] + + +class TopicAdminForm(forms.ModelForm): + class Meta: + model = Topic + fields = [ + "title", + "description", + "topic_group", + ] + + widgets = {"description": CKEditorUploadingWidget(config_name="default")} + + +class DocumentationAdminForm(forms.ModelForm): + class Meta: + model = Documentation + fields = [ + "title", + "description", + "topic", + ] + + +class DocumentForm(forms.ModelForm): + class Meta: + model = Document + + fields = [ + "title", + ] + + labels = { + "title": _("Titel des Protokolls"), + } diff --git a/fet2020/intern/models.py b/fet2020/intern/models.py new file mode 100644 index 00000000..8715e6f4 --- /dev/null +++ b/fet2020/intern/models.py @@ -0,0 +1,101 @@ +import logging +from django.db import models +from django.utils.text import slugify +from documents import createPadifNotExists +from urllib.request import URLError + +logger = logging.getLogger(__name__) + + +class TopicGroup(models.Model): + title = models.CharField(max_length=128) + + slug = models.SlugField(unique=True, blank=True) + + objects = models.Manager() + + def save(self, *args, **kwargs): + if not self.slug: + self.slug = slugify(self.title) + + super().save(*args, **kwargs) + + def __str__(self): + return self.title + + +class Topic(models.Model): + title = models.CharField(max_length=128) + + slug = models.SlugField(unique=True, blank=True) + description = models.TextField(null=True, blank=True) + + topic_group = models.ForeignKey(TopicGroup, on_delete=models.CASCADE) + + objects = models.Manager() + + def save(self, *args, **kwargs): + if not self.slug: + self.slug = slugify(self.title) + + super().save(*args, **kwargs) + + def __str__(self): + return self.title + + +class Documentation(models.Model): + title = models.CharField(max_length=128) + + slug = models.SlugField(unique=True, blank=True) + description = models.TextField(null=True, blank=True) + + topic = models.ForeignKey(Topic, on_delete=models.CASCADE) + + objects = models.Manager() + + def save(self, *args, **kwargs): + if not self.slug: + self.slug = slugify(self.title) + + super().save(*args, **kwargs) + + def __str__(self): + return self.title + + +class Document(models.Model): + title = models.CharField(max_length=128) + + etherpad_key = models.CharField(max_length=128, null=True, blank=True) + + documentation = models.ForeignKey(Documentation, on_delete=models.CASCADE) + + objects = models.Manager() + + def save(self, *args, **kwargs): + try: + self.etherpad_key = createPadifNotExists( + self.documentation.topic.slug + + "-" + + self.documentation.slug + + "-" + + slugify(self.title) + ) + except URLError as error: + logger.info( + "Can't create a Etherpad '%s' from the slug. Error: %s", + slugify(self.title), + error, + ) + self.etherpad_key = None + + super().save(*args, **kwargs) + + def __str__(self): + return self.title + + +class Protocol(Document): + event_start = models.DateTimeField(null=True, blank=True) + event_end = models.DateTimeField(null=True, blank=True) diff --git a/fet2020/intern/tests.py b/fet2020/intern/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/fet2020/intern/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/fet2020/intern/urls.py b/fet2020/intern/urls.py new file mode 100644 index 00000000..453b14a6 --- /dev/null +++ b/fet2020/intern/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from . import views + + +urlpatterns = [ + path("", views.index, name="intern"), + path("", views.show_topic, name="topic"), + path("/", views.show_docu, name="docu"), +] diff --git a/fet2020/intern/views.py b/fet2020/intern/views.py new file mode 100644 index 00000000..298d3f9e --- /dev/null +++ b/fet2020/intern/views.py @@ -0,0 +1,85 @@ +import logging + +from django.http import HttpResponseRedirect +from django.shortcuts import render +from documents.api import get_pad_link +from collections import deque + +from .forms import DocumentForm +from .models import TopicGroup, Topic, Documentation, Document + +logger = logging.getLogger(__name__) + + +def index(request): + + topic_group = deque(TopicGroup.objects.all()) + topic = Topic.objects.all() + + context = { + "topic_group": topic_group, + "topic": topic, + } + + return render(request, "intern/index.html", context) + + +def show_topic(request, slug=None): + + topic_group = deque(TopicGroup.objects.all()) + topic = deque(Topic.objects.all()) + active_topic = Topic.objects.filter(slug=slug).first() + docu = deque(Documentation.objects.filter(topic__slug=slug)) + + context = { + "topic_group": topic_group, + "topic": topic, + "active_topic": active_topic, + "docus": docu, + } + + return render(request, "intern/topic.html", context) + + +def show_docu(request, slug=None, foo=None): + + active_docu = Documentation.objects.filter(slug=foo).first() + active_topic = Topic.objects.filter(slug=slug).first() + + if request.method == "POST": + if "btn_input" in request.POST: + form = DocumentForm(request.POST) + + if form.is_valid(): + docu = form.save(commit=False) + docu.created_by = request.user + docu.documentation = active_docu + docu.save() + + return HttpResponseRedirect(request.path) + + form = DocumentForm() + docus = deque(Document.objects.filter(documentation=active_docu)) + documents = deque([]) + + for elem in docus: + try: + documents.append( + { + "title": elem.title, + "etherpad_key": get_pad_link(elem.etherpad_key), + } + ) + except Exception as e: + logger.error( + "Can't get the agenda link from '%s'. Error: %s", elem.etherpad_key, e + ) + + context = { + "formset": form, + "active_topic": active_topic, + "active_docu": active_docu, + "documents": documents, + } + + return render(request, "intern/docu.html", context) diff --git a/fet2020/static/intern.css b/fet2020/static/intern.css new file mode 100644 index 00000000..fa206b30 --- /dev/null +++ b/fet2020/static/intern.css @@ -0,0 +1,75 @@ +.intern-topic { + border-radius: 5px; + margin-top: 1rem !important; + margin-bottom: 1rem !important; + height: 100px; } + @media print, screen and (min-width: 40em) { + .intern-topic { + height: 15vh; } } + @media print, screen and (min-width: 64em) { + .intern-topic { + height: 15vh; } } + +.intern-topic, .intern-topic-large { + background-color: #444; + position: relative; + background-size: cover; + -webkit-box-align: center; + -webkit-align-items: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -webkit-justify-content: center; + -ms-flex-pack: center; + justify-content: center; + vertical-align: middle; + text-align: left; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + width: 100%; } + .intern-topic .intern-topic-text, .intern-topic-large .intern-topic-text { + color: #fefefe; + text-shadow: 1px 1px 2px #0a0a0a; } + + +.internheader { + border-radius: 5px; + margin-top: 1rem !important; + margin-bottom: 1rem !important; + height: 30px; } + @media print, screen and (min-width: 40em) { + .internheader { + height: 5vh; } } + @media print, screen and (min-width: 64em) { + .internheader { + height: 5vh; } } + +.internheader, .internheader-large { + background-color: grey; + position: relative; + background-size: cover; + -webkit-box-align: center; + -webkit-align-items: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -webkit-justify-content: center; + -ms-flex-pack: center; + justify-content: center; + vertical-align: middle; + text-align: left; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + width: 100%; } + .internheader, .internheader-large { + color: #fefefe; + text-shadow: 1px 1px 2px #0a0a0a; } + + +.intern-hero { + background-color: white; +} diff --git a/fet2020/templates/intern/docu.html b/fet2020/templates/intern/docu.html new file mode 100644 index 00000000..41196da4 --- /dev/null +++ b/fet2020/templates/intern/docu.html @@ -0,0 +1,75 @@ +{% extends "layout.html" %} + +{% block content %} +
+ + + +
+ + {{ active_docu.description|safe }} + +
+ +
+ +
+

Neues Protokoll hinzufügen

+ +
+ {% csrf_token %} + +
+ + {{ formset.management_form }} + + {% for form in formset %} +
+ {{ form.label }} + {{ form }} +
+ {% endfor %} + +
+ +
+ +
+ +
+ +
+ +
+ +{% endblock %} diff --git a/fet2020/templates/intern/index.html b/fet2020/templates/intern/index.html new file mode 100644 index 00000000..66908ce2 --- /dev/null +++ b/fet2020/templates/intern/index.html @@ -0,0 +1,29 @@ +{% extends "layout.html" %} + +{% block content %} +
+ + {% regroup topic by topic_group as topic_list %} + + {% for topic in topic_list %} +
+ {{ topic.grouper.title }} +
+ +
+ {% for tp in topic.list %} + + {% endfor %} +
+ {% endfor %} + +
+{% endblock %} diff --git a/fet2020/templates/intern/topic.html b/fet2020/templates/intern/topic.html new file mode 100644 index 00000000..31738a0d --- /dev/null +++ b/fet2020/templates/intern/topic.html @@ -0,0 +1,49 @@ +{% extends "layout.html" %} + +{% block content %} +
+ + + +
+ + {{ active_topic.description|safe }} + + +
+ {% for docu in docus %} + + {% endfor %} +
+ +
+ +
+ +{% endblock %} diff --git a/fet2020/templates/layout.html b/fet2020/templates/layout.html index 26961578..a5477cbd 100644 --- a/fet2020/templates/layout.html +++ b/fet2020/templates/layout.html @@ -9,6 +9,7 @@ FET + {% block extraheader %} {% endblock %} @@ -62,7 +63,8 @@ footer {
  • Admin
  • Tasks
  • -
  • Intern
  • +
  • Intern
  • +
  • Legacy Intern
  • {% endif %}
  • Aktuelles
  • From cacfc83ff1356b965bf7f3da2ad9cbc02857f2b5 Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 15 May 2021 19:39:05 +0000 Subject: [PATCH 2/3] fix merge --- fet2020/templates/layout.html | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/fet2020/templates/layout.html b/fet2020/templates/layout.html index 2b47507c..d62dbbaa 100644 --- a/fet2020/templates/layout.html +++ b/fet2020/templates/layout.html @@ -55,16 +55,10 @@ {% endif %} -<<<<<<< HEAD -
  • Admin
  • -
  • Tasks
  • -
  • Intern
  • -
  • Legacy Intern
  • -=======
  • Admin
  • Tasks
  • -
  • Intern
  • ->>>>>>> origin/master +
  • Intern
  • +
  • Legacy Intern
  • {% endif %}
  • News
  • From 75bd5619d9fd5535692f353fcd978767f756579b Mon Sep 17 00:00:00 2001 From: patrick Date: Sun, 23 May 2021 13:02:39 +0000 Subject: [PATCH 3/3] update template, wordings; add ep cookie --- fet2020/intern/admin.py | 39 ++++++++++---- fet2020/intern/forms.py | 30 +++++++++-- fet2020/intern/models.py | 84 ++++++++++++++++++----------- fet2020/intern/urls.py | 2 +- fet2020/intern/views.py | 63 ++++++++++++---------- fet2020/templates/intern/docu.html | 81 ++++++++++++++++------------ fet2020/templates/intern/topic.html | 38 +++++++------ 7 files changed, 210 insertions(+), 127 deletions(-) diff --git a/fet2020/intern/admin.py b/fet2020/intern/admin.py index fe2b8dec..b856dea9 100644 --- a/fet2020/intern/admin.py +++ b/fet2020/intern/admin.py @@ -1,11 +1,12 @@ from django.contrib import admin -from .models import TopicGroup, Topic, Documentation -from .forms import TopicGroupAdminForm, TopicAdminForm +from .models import TopicGroup, Topic, Documentation, Document +from .forms import TopicGroupAdminForm, TopicAdminForm, DocumentationAdminForm, DocumentAdminForm class DocumentationInline(admin.TabularInline): model = Documentation + form = DocumentationAdminForm extra = 0 verbose_name = "Dokument" verbose_name_plural = "Dokument-Übersicht" @@ -13,17 +14,21 @@ class DocumentationInline(admin.TabularInline): class TopicInline(admin.TabularInline): model = Topic + form = TopicAdminForm extra = 0 - verbose_name = "Topic" - verbose_name_plural = "Topic-Übersicht" + verbose_name = "Thema" + verbose_name_plural = "Themen" + show_change_link = True class TopicGroupAdmin(admin.ModelAdmin): form = TopicGroupAdminForm model = TopicGroup - search_fields = ("title",) + search_fields = ("title", ) inlines = (TopicInline,) + list_display = ["title", "order",] + def save_model(self, request, obj, form, change): obj.created_by = request.user super().save_model(request, obj, form, change) @@ -35,23 +40,39 @@ class TopicAdmin(admin.ModelAdmin): search_fields = ("title",) inlines = (DocumentationInline,) + list_filter = ["archive",] + list_display = ["title", "topic_group", "archive",] + def save_model(self, request, obj, form, change): obj.created_by = request.user super().save_model(request, obj, form, change) -""" class DocumentationAdmin(admin.ModelAdmin): form = DocumentationAdminForm model = Documentation - list_display = ["title", "topic"] + list_display = ["title", "topic",] def save_model(self, request, obj, form, change): obj.created_by = request.user super().save_model(request, obj, form, change) -""" + + +class DocumentAdmin(admin.ModelAdmin): + form = DocumentAdminForm + model = Document + + list_filter = ["documentation",] + list_display = ["title", "date", "documentation",] + ordering = ["-date"] + + def save_model(self, request, obj, form, change): + obj.created_by = request.user + super().save_model(request, obj, form, change) + admin.site.register(TopicGroup, TopicGroupAdmin) admin.site.register(Topic, TopicAdmin) -# admin.site.register(Documentation, DocumentationAdmin) +#admin.site.register(Documentation, DocumentationAdmin) +admin.site.register(Document, DocumentAdmin) diff --git a/fet2020/intern/forms.py b/fet2020/intern/forms.py index f2863d49..e9761345 100644 --- a/fet2020/intern/forms.py +++ b/fet2020/intern/forms.py @@ -1,11 +1,14 @@ +from ckeditor_uploader.widgets import CKEditorUploadingWidget from django import forms from django.utils.translation import gettext_lazy as _ -from ckeditor_uploader.widgets import CKEditorUploadingWidget - from .models import TopicGroup, Topic, Documentation, Document +class DateInput(forms.DateInput): + input_type = "date" + + class TopicGroupAdminForm(forms.ModelForm): class Meta: model = TopicGroup @@ -19,6 +22,7 @@ class TopicAdminForm(forms.ModelForm): model = Topic fields = [ "title", + "archive", "description", "topic_group", ] @@ -31,10 +35,22 @@ class DocumentationAdminForm(forms.ModelForm): model = Documentation fields = [ "title", + "placeholder", "description", "topic", ] + widgets = {"description": CKEditorUploadingWidget(config_name="default")} + + +class DocumentAdminForm(forms.ModelForm): + class Meta: + model = Document + fields = [ + "title", + "documentation", + ] + class DocumentForm(forms.ModelForm): class Meta: @@ -42,8 +58,16 @@ class DocumentForm(forms.ModelForm): fields = [ "title", + "date", ] labels = { - "title": _("Titel des Protokolls"), + "title": _("Titel"), + "date": _("Datum"), + } + + widgets = { + "date": DateInput( + format=("%d-%m-%Y"), + ) } diff --git a/fet2020/intern/models.py b/fet2020/intern/models.py index 8715e6f4..2f2a8955 100644 --- a/fet2020/intern/models.py +++ b/fet2020/intern/models.py @@ -1,19 +1,30 @@ import logging + +from datetime import date +from django.core.validators import ValidationError from django.db import models +from django.db.models.constraints import UniqueConstraint +from django.utils import timezone from django.utils.text import slugify +from django.utils.translation import gettext_lazy as _ + from documents import createPadifNotExists -from urllib.request import URLError logger = logging.getLogger(__name__) class TopicGroup(models.Model): - title = models.CharField(max_length=128) - + title = models.CharField(verbose_name="Titel", max_length=128) slug = models.SlugField(unique=True, blank=True) + order = models.PositiveSmallIntegerField(verbose_name="Reihenfolge", unique=True, null=True, blank=True) + objects = models.Manager() + class Meta: + verbose_name = "Themenbereich" + verbose_name_plural = "Themenbereiche" + def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.title) @@ -25,15 +36,21 @@ class TopicGroup(models.Model): class Topic(models.Model): - title = models.CharField(max_length=128) - + title = models.CharField(verbose_name="Titel", max_length=128) slug = models.SlugField(unique=True, blank=True) + + archive = models.BooleanField(verbose_name="Archiv", default=False) + description = models.TextField(null=True, blank=True) - topic_group = models.ForeignKey(TopicGroup, on_delete=models.CASCADE) + topic_group = models.ForeignKey(TopicGroup, on_delete=models.CASCADE, verbose_name="Themenbereich") objects = models.Manager() + class Meta: + verbose_name = "Thema" + verbose_name_plural = "Themen" + def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.title) @@ -45,9 +62,10 @@ class Topic(models.Model): class Documentation(models.Model): - title = models.CharField(max_length=128) + title = models.CharField(verbose_name="Titel", max_length=128) + slug = models.SlugField(blank=True) + placeholder = models.CharField(verbose_name="Platzhalter", max_length=128, default="Titel") - slug = models.SlugField(unique=True, blank=True) description = models.TextField(null=True, blank=True) topic = models.ForeignKey(Topic, on_delete=models.CASCADE) @@ -61,41 +79,45 @@ class Documentation(models.Model): super().save(*args, **kwargs) def __str__(self): - return self.title + return self.topic.title + " / " + self.title class Document(models.Model): - title = models.CharField(max_length=128) - + title = models.CharField(verbose_name="Titel", max_length=128) etherpad_key = models.CharField(max_length=128, null=True, blank=True) + date = models.DateField(verbose_name="Datum", default=date.today) documentation = models.ForeignKey(Documentation, on_delete=models.CASCADE) objects = models.Manager() + class Meta: + verbose_name = "Dokument" + verbose_name_plural = "Dokumente" + + constraints = [ + UniqueConstraint(fields=['title', 'date'], name='unique_title_and_date'), + ] + + ''' + pre save signal + def clean(self): + pad_name = slugify(self.date + "-" + self.documentation.topic.slug + "-" + self.documentation.slug + "-" + slugify(self.title) + + if len(pad_name) > 50: + print(pad_name) + raise ValidationError( + _('Name zum Erstellen des Etherpads ist zu lange - max. 50 Zeichen. (Länge: %(length)s) (Name: %(pad_name)s)'), + params={'length': len(pad_name), 'pad_name': pad_name}, + ) + ''' + def save(self, *args, **kwargs): - try: - self.etherpad_key = createPadifNotExists( - self.documentation.topic.slug - + "-" - + self.documentation.slug - + "-" - + slugify(self.title) - ) - except URLError as error: - logger.info( - "Can't create a Etherpad '%s' from the slug. Error: %s", - slugify(self.title), - error, - ) - self.etherpad_key = None + self.etherpad_key = createPadifNotExists( + slugify(self.date) + "-" + self.documentation.topic.slug + "-" + self.documentation.slug + "-" + slugify(self.title) + ) super().save(*args, **kwargs) def __str__(self): return self.title - - -class Protocol(Document): - event_start = models.DateTimeField(null=True, blank=True) - event_end = models.DateTimeField(null=True, blank=True) diff --git a/fet2020/intern/urls.py b/fet2020/intern/urls.py index 453b14a6..ff7d36f0 100644 --- a/fet2020/intern/urls.py +++ b/fet2020/intern/urls.py @@ -6,5 +6,5 @@ from . import views urlpatterns = [ path("", views.index, name="intern"), path("", views.show_topic, name="topic"), - path("/", views.show_docu, name="docu"), + path("/", views.show_docu, name="docu"), ] diff --git a/fet2020/intern/views.py b/fet2020/intern/views.py index 298d3f9e..b2c69cd8 100644 --- a/fet2020/intern/views.py +++ b/fet2020/intern/views.py @@ -1,8 +1,11 @@ import logging +from django.contrib import messages +from django.db.models import F, Q from django.http import HttpResponseRedirect from django.shortcuts import render from documents.api import get_pad_link +from documents.etherpadlib import add_ep_cookie from collections import deque from .forms import DocumentForm @@ -12,12 +15,9 @@ logger = logging.getLogger(__name__) def index(request): - - topic_group = deque(TopicGroup.objects.all()) - topic = Topic.objects.all() + topic = deque(Topic.objects.filter(archive=False).order_by(F('topic_group__order').asc(nulls_last=True), 'topic_group', 'title')) context = { - "topic_group": topic_group, "topic": topic, } @@ -25,15 +25,10 @@ def index(request): def show_topic(request, slug=None): - - topic_group = deque(TopicGroup.objects.all()) - topic = deque(Topic.objects.all()) active_topic = Topic.objects.filter(slug=slug).first() - docu = deque(Documentation.objects.filter(topic__slug=slug)) + docu = deque(Documentation.objects.filter(topic__slug=slug).order_by('title')) context = { - "topic_group": topic_group, - "topic": topic, "active_topic": active_topic, "docus": docu, } @@ -41,10 +36,9 @@ def show_topic(request, slug=None): return render(request, "intern/topic.html", context) -def show_docu(request, slug=None, foo=None): - - active_docu = Documentation.objects.filter(slug=foo).first() - active_topic = Topic.objects.filter(slug=slug).first() +def show_docu(request, topic_slug=None, slug=None): + active_docu = Documentation.objects.filter(Q(topic__slug=topic_slug) & Q(slug=slug)).first() + active_topic = Topic.objects.filter(slug=topic_slug).first() if request.method == "POST": if "btn_input" in request.POST: @@ -58,22 +52,28 @@ def show_docu(request, slug=None, foo=None): return HttpResponseRedirect(request.path) - form = DocumentForm() - docus = deque(Document.objects.filter(documentation=active_docu)) + else: + for elem in list(form.errors.values()): + messages.info(request, '; '.join(elem)) + + initial = { + "title": active_docu.placeholder, + } + + form = DocumentForm(initial=initial) + + docus = deque(Document.objects.filter(documentation=active_docu).order_by('-date')) documents = deque([]) + # list of etherpad url-link of any documents for elem in docus: - try: - documents.append( - { - "title": elem.title, - "etherpad_key": get_pad_link(elem.etherpad_key), - } - ) - except Exception as e: - logger.error( - "Can't get the agenda link from '%s'. Error: %s", elem.etherpad_key, e - ) + documents.append( + { + "title": elem.title, + "date": elem.date, + "etherpad_key": get_pad_link(elem.etherpad_key), + } + ) context = { "formset": form, @@ -82,4 +82,11 @@ def show_docu(request, slug=None, foo=None): "documents": documents, } - return render(request, "intern/docu.html", context) + response = render(request, "intern/docu.html", context) + + try: + response = add_ep_cookie(request, response) + except Exception as e: + logger.info("Etherpad Server doesn't work. Error: %s", e) + + return response diff --git a/fet2020/templates/intern/docu.html b/fet2020/templates/intern/docu.html index 41196da4..58f28ed3 100644 --- a/fet2020/templates/intern/docu.html +++ b/fet2020/templates/intern/docu.html @@ -2,9 +2,7 @@ {% block content %}
    -
    + {% if active_docu.description %} +
    + {{ active_docu.description|safe }} +
    - {{ active_docu.description|safe }} +
    + {% endif %} + +
    + {% csrf_token %} + +
    + + {{ formset.management_form }} + + {% for form in formset %} +
    + {{ form }} +
    + {% endfor %} + + {{ formset.non_field_errors }} + +
    + +
    +
    +
    + + {% for message in messages %} +

    {{message}}

    + {% endfor %} + +
    - -
    - -
    -

    Neues Protokoll hinzufügen

    - -
    - {% csrf_token %} - -
    - - {{ formset.management_form }} - - {% for form in formset %} -
    - {{ form.label }} - {{ form }} +
    + {% for document in documents %} + +
    +
    +

    {{ document.title }}

    +
    +
    +

    {{ document.date }}

    +
    +
    +
    + {% endfor %}
    - {% endfor %} - -
    - -
    -
    - - -
    -
    {% endblock %} diff --git a/fet2020/templates/intern/topic.html b/fet2020/templates/intern/topic.html index 31738a0d..4553a16a 100644 --- a/fet2020/templates/intern/topic.html +++ b/fet2020/templates/intern/topic.html @@ -2,9 +2,7 @@ {% block content %}
    -
    - - {{ active_topic.description|safe }} - - -
    - {% for docu in docus %} -
    - -
    -
    - {{ docu.title }} -
    -
    -
    + {% if active_topic.description %} +
    + {{ active_topic.description|safe }}
    - {% endfor %} -
    +
    + {% endif %} +
    + {% for docu in docus %} + + {% endfor %} +
    -
    {% endblock %}