diff --git a/collab_coursebook/settings.py b/collab_coursebook/settings.py index acea7854..76b6da21 100644 --- a/collab_coursebook/settings.py +++ b/collab_coursebook/settings.py @@ -166,3 +166,5 @@ "impress_text": "", "impress_url": "" } + +ALLOW_PUBLIC_COURSE_EDITING_BY_EVERYONE = True diff --git a/frontend/locale/de_DE/LC_MESSAGES/django.po b/frontend/locale/de_DE/LC_MESSAGES/django.po index 301ae117..37fcb5d4 100644 --- a/frontend/locale/de_DE/LC_MESSAGES/django.po +++ b/frontend/locale/de_DE/LC_MESSAGES/django.po @@ -50,23 +50,23 @@ msgstr "Abbrechen" msgid "Actions" msgstr "Aktionen" -#: frontend/templates/frontend/content/detail.html:43 +#: frontend/templates/frontend/content/detail.html:46 msgid "Back to course " msgstr "Zurück zum Kurs " -#: frontend/templates/frontend/content/detail.html:49 +#: frontend/templates/frontend/content/detail.html:52 msgid "By" msgstr "Von" -#: frontend/templates/frontend/content/detail.html:59 +#: frontend/templates/frontend/content/detail.html:62 msgid "Created at" msgstr "Erstellt am" -#: frontend/templates/frontend/content/detail.html:67 +#: frontend/templates/frontend/content/detail.html:70 msgid "Delete" msgstr "Löschen" -#: frontend/templates/frontend/content/detail.html:71 +#: frontend/templates/frontend/content/detail.html:74 #, python-format msgid "" "\n" @@ -80,19 +80,26 @@ msgstr "" " " #: frontend/templates/frontend/content/detail.html:83 +#: frontend/templates/frontend/course/create.html:30 +#: frontend/templates/frontend/course/edit.html:30 +#: frontend/templates/frontend/profile/profile_edit.html:19 +msgid "Cancel" +msgstr "Abbrechen" + +#: frontend/templates/frontend/content/detail.html:86 msgid "Confirm" msgstr "Bestätigen" -#: frontend/templates/frontend/content/detail.html:99 +#: frontend/templates/frontend/content/detail.html:102 #: frontend/templates/frontend/course/topic_contents.html:29 msgid "Rating" msgstr "Bewertung" -#: frontend/templates/frontend/content/detail.html:109 +#: frontend/templates/frontend/content/detail.html:112 msgid "Comments" msgstr "Kommentare" -#: frontend/templates/frontend/content/detail.html:115 +#: frontend/templates/frontend/content/detail.html:118 msgid "Add comment" msgstr "Kommentar hinzufügen" @@ -100,10 +107,28 @@ msgstr "Kommentar hinzufügen" msgid "Create a new course" msgstr "Neuen Kurs anlegen" +#: frontend/templates/frontend/course/create.html:29 +#: frontend/templates/frontend/course/edit.html:29 +msgid "Create" +msgstr "Erzeugen" + #: frontend/templates/frontend/course/dropdown_topic.html:10 msgid "Add Content" msgstr "Inhalte hinzufügen" +#: frontend/templates/frontend/course/edit.html:11 +msgid "Edit course" +msgstr "Kurs bearbeiten" + +#: frontend/templates/frontend/course/view.html:26 +msgid "Edit Course" +msgstr "Kurs hinzufügen" + +#: frontend/templates/frontend/course/view.html:27 +msgid "Delete Course" +msgstr "Kurs löschen" + +#: frontend/templates/frontend/course/view.html:63 #: frontend/templates/frontend/course/view.html:78 msgid "No topics yet" msgstr "Bisher keine Themen" @@ -236,6 +261,10 @@ msgstr "Es trat ein Fehler beim Verarbeiten der Anfrage auf" msgid "Course '{cleaned_data['title']}' successfully created" msgstr "Kurs '{cleaned_data['title']}' erfolgreich angelegt" +#: frontend/views/course.py:52 +msgid "Course '{cleaned_data['title']}' successfully edited" +msgstr "Kurs '{cleaned_data['title']}' erfolgreich bearbeitet" + #: frontend/views/profile.py:25 msgid "Profile updated" msgstr "Profil aktualisiert" diff --git a/frontend/templates/frontend/course/edit.html b/frontend/templates/frontend/course/edit.html new file mode 100644 index 00000000..66e69c96 --- /dev/null +++ b/frontend/templates/frontend/course/edit.html @@ -0,0 +1,42 @@ +{% extends 'frontend/base_logged_in.html' %} + +{# Load the tag library #} +{% load bootstrap4 %} +{% load i18n %} +{% load static %} +{% load fontawesome_5 %} + +{# Load CSS and JavaScript #} + +{% block title %}{% trans "Edit course" %} - Collab Coursebook{% endblock %} + +{% block imports %} + + +{% endblock %} + +{% block content %} +

Edit Course

+ +
+ {% csrf_token %} + + {% bootstrap_form form %} + + {{ form.media }} +
+ + + {% fa5_icon 'times' 'fas' %} {% trans "Cancel" %} +
+
+{% endblock %} + +{% block bottom_script %} + + +{% endblock %} diff --git a/frontend/templates/frontend/course/view.html b/frontend/templates/frontend/course/view.html index 3dbcc892..98302716 100644 --- a/frontend/templates/frontend/course/view.html +++ b/frontend/templates/frontend/course/view.html @@ -18,7 +18,6 @@ {% block content %} -
-

{{ course.title }}

@@ -92,7 +90,8 @@
{% with entry.topic as topic_replace %} {% add_content_button user course.id topic_replace.id %} {% endwith %} -

{{ outer_index }}. {{ topic.title }}

+

{{ outer_index }}. {{ entry.topic.title }}

+ {% with entry.topic.contents.all as topic_contents %} {% include "frontend/course/topic_contents.html" %} {% endwith %} diff --git a/frontend/templatetags/cc_frontend_tags.py b/frontend/templatetags/cc_frontend_tags.py index 5fb5897f..59a69512 100644 --- a/frontend/templatetags/cc_frontend_tags.py +++ b/frontend/templatetags/cc_frontend_tags.py @@ -1,6 +1,7 @@ from django import template from django.conf import settings +from collab_coursebook.settings import ALLOW_PUBLIC_COURSE_EDITING_BY_EVERYONE from content.models import CONTENT_TYPES register = template.Library() @@ -88,6 +89,13 @@ def content_card(type): return "content/cards/blank.html" +@register.filter +def check_edit_course_permission(user, course): + # either an user is an owner or the course is public and it is allowed to edit public courses + return (user.profile in course.owners.all()) or (not course.restrict_changes + and ALLOW_PUBLIC_COURSE_EDITING_BY_EVERYONE) + + @register.filter def is_content_editable(type): # TODO: implement check diff --git a/frontend/urls.py b/frontend/urls.py index d93fe702..dc1f43ab 100644 --- a/frontend/urls.py +++ b/frontend/urls.py @@ -18,6 +18,7 @@ path('', views.CourseListView.as_view(), name='courses'), path('/', include([ path('', views.CourseView.as_view(), name='course'), + path('edit/', views.course.EditCourseView.as_view(), name='course-edit'), path('delete/', views.CourseDeleteView.as_view(), name='course-delete'), ])), path('/topic//content/', include([ diff --git a/frontend/views/course.py b/frontend/views/course.py index 20b7e8a1..24a265ac 100644 --- a/frontend/views/course.py +++ b/frontend/views/course.py @@ -3,9 +3,9 @@ from django.contrib.messages.views import SuccessMessageMixin from django.contrib import messages from django.http import HttpResponseRedirect -from django.urls import reverse_lazy +from django.urls import reverse_lazy, reverse from django.views.generic import DetailView -from django.views.generic.edit import FormMixin, CreateView, DeleteView +from django.views.generic.edit import FormMixin, CreateView, DeleteView, UpdateView from django.utils.translation import gettext_lazy as _ from base.models import Course, CourseStructureEntry @@ -36,6 +36,22 @@ def get_initial(self): return initial +class EditCourseView(SuccessMessageMixin, LoginRequiredMixin, UpdateView): + """ + Edit course + """ + model = Course + template_name = 'frontend/course/edit.html' + form_class = AddAndEditCourseForm + + def get_success_url(self): + course_id = self.get_object().id + return reverse('frontend:course', args=(course_id,)) + + def get_success_message(self, cleaned_data): + return _(f"Course '{cleaned_data['title']}' successfully edited") + + class CourseView(DetailView, FormMixin): # pylint: disable=too-many-ancestors """ Displays the course detail page