Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions collab_coursebook/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,5 @@
"impress_text": "",
"impress_url": ""
}

ALLOW_PUBLIC_COURSE_EDITING_BY_EVERYONE = True
45 changes: 37 additions & 8 deletions frontend/locale/de_DE/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -80,30 +80,55 @@ 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"

#: frontend/templates/frontend/course/create.html:11
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"
Expand Down Expand Up @@ -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"
Expand Down
42 changes: 42 additions & 0 deletions frontend/templates/frontend/course/edit.html
Original file line number Diff line number Diff line change
@@ -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 %}
<link rel="stylesheet" href="{% static 'vendor/chosen-js/chosen.css' %}">
<link rel="stylesheet" href="{% static 'css/bootstrap-chosen.css' %}">
{% endblock %}

{% block content %}
<h1>Edit Course</h1>

<form method="post" enctype=multipart/form-data>
{% csrf_token %}

{% bootstrap_form form %}

{{ form.media }}
<div>

<button type="submit" class="btn btn-primary float-right">{% fa5_icon 'plus-circle' 'fas' %} {% trans "Create" %}</button>
<a href="{% url 'frontend:dashboard' %}" class="btn btn-danger">{% fa5_icon 'times' 'fas' %} {% trans "Cancel" %}</a>
</div>
</form>
{% endblock %}

{% block bottom_script %}
<script src="{% static 'vendor/chosen-js/chosen.jquery.js' %}"></script>
<script>
$(function () {
$('.chosen-select').chosen();
});
</script>
{% endblock %}
13 changes: 6 additions & 7 deletions frontend/templates/frontend/course/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

{% block content %}
<!-- Course markings and actions -->

<div class="float-right text-right">
<div class="dropdown show">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Expand All @@ -28,21 +27,20 @@
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
{% if user.is_authenticated %}
<a class="dropdown-item" href="{# url 'favourite_content' course.id topic.id content.id ?onDetailPage=True#}">
{% if favourite %}{% fa5_icon 'bookmark' 'fas' %} Unsave {% else %}{% fa5_icon 'bookmark' 'far' %} Save{% endif %}</a>
{% if course in user.profile.stared_courses.all %}{% fa5_icon 'bookmark' 'fas' %} Unsave {% else %}{% fa5_icon 'bookmark' 'far' %} Save{% endif %}</a>

<div class="dropdown-divider"></div>

{% if isCurrentUserOwner or user.is_superuser or content.author == user %}
<a href="{% url 'frontend:course-delete' pk=course.pk %}" class="dropdown-item text-danger"
>{% fa5_icon 'trash' 'fas' %} Delete</a>
{% if user|check_edit_course_permission:course %}
<a href="{% url 'frontend:course-edit' pk=course.pk %}" class="dropdown-item">{% fa5_icon "pencil-alt" "fas" %} {% trans "Edit Course" %}</a>
<a href="{% url 'frontend:course-delete' pk=course.pk %}" class="dropdown-item">{% fa5_icon "trash" "fas" %} {% trans "Delete Course" %}</a>
{% endif %}
{% endif %}

</div>
</div>
</div>


<!-- Course header: Title, owners, description -->
<h1>{{ course.title }}</h1>

Expand Down Expand Up @@ -92,7 +90,8 @@ <h5 style="margin-top: 20px;">
{% with entry.topic as topic_replace %}
{% add_content_button user course.id topic_replace.id %}
{% endwith %}
<h3 class="text-info">{{ outer_index }}. {{ topic.title }}</h3>
<h3 class="text-info">{{ outer_index }}. {{ entry.topic.title }}</h3>

{% with entry.topic.contents.all as topic_contents %}
{% include "frontend/course/topic_contents.html" %}
{% endwith %}
Expand Down
8 changes: 8 additions & 0 deletions frontend/templatetags/cc_frontend_tags.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions frontend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
path('', views.CourseListView.as_view(), name='courses'),
path('<int:pk>/', 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('<int:course_id>/topic/<int:topic_id>/content/', include([
Expand Down
20 changes: 18 additions & 2 deletions frontend/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down