Skip to content

Commit 039f395

Browse files
committed
implement changes from pull request comment
1 parent b7736d5 commit 039f395

5 files changed

Lines changed: 43 additions & 21 deletions

File tree

frontend/locale/de_DE/LC_MESSAGES/django.po

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ msgstr "Neuen Kurs anlegen"
104104
msgid "Add Content"
105105
msgstr "Inhalte hinzufügen"
106106

107-
#: frontend/templates/frontend/course/view.html:83
107+
#: frontend/templates/frontend/course/view.html:78
108108
msgid "No topics yet"
109109
msgstr "Bisher keine Themen"
110110

@@ -226,7 +226,11 @@ msgstr "Kommentar erfolgreich bearbeitet."
226226

227227
#: frontend/views/content.py:28
228228
msgid "Content '{cleaned_data['type']}' successfully added"
229-
msgstr "Inhalt '{cleaned_data['title']}' erfolgreich hinzugefügt"
229+
msgstr "Inhalt '{cleaned_data['type']}' erfolgreich hinzugefügt"
230+
231+
#: frontend/views/content.py:35
232+
msgid "An error occurred while processing the request"
233+
msgstr "Es trat ein Fehler beim Verarbeiten der Anfrage auf"
230234

231235
#: frontend/views/course.py:26
232236
msgid "Course '{cleaned_data['title']}' successfully created"

frontend/templates/frontend/content/detail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
{# url 'readingmode' course.id topic.id content.id #}{% if ending %}{{ ending }}{% endif %}">{% fa5_icon 'eye' 'far' %}
2424
Reading Mode</a>
2525
{% if user.is_authenticated %}
26-
{% if content.type|check_markdown %}
26+
{% if content.type|is_content_editable %}
2727
<a class="dropdown-item"
28-
href="{% url 'edit_md_file' course.id topic.id content.id %}">{% fa5_icon 'pencil-alt' 'fas' %}
28+
href="{#{% url 'edit_md_file' course.id topic.id content.id %}#}">{% fa5_icon 'pencil-alt' 'fas' %}
2929
Edit</a>
3030

3131
{% endif %}

frontend/templates/frontend/course/view.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,11 @@
2727

2828
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
2929
{% if user.is_authenticated %}
30-
<a class="dropdown-item" href="{# url 'favourite_content' course.id topic.id content.id #}?onDetailPage=True">
30+
<a class="dropdown-item" href="{# url 'favourite_content' course.id topic.id content.id ?onDetailPage=True#}">
3131
{% if favourite %}{% fa5_icon 'bookmark' 'fas' %} Unsave {% else %}{% fa5_icon 'bookmark' 'far' %} Save{% endif %}</a>
32-
<div class="dropdown-divider"></div>
3332

34-
{% if content.type|check_markdown %}
35-
<a class="dropdown-item"
36-
href="{% url 'edit_md_file' course.id topic.id content.id %}">{% fa5_icon 'pencil-alt' 'fas' %}
37-
Edit</a>
33+
<div class="dropdown-divider"></div>
3834

39-
{% endif %}
4035
{% if isCurrentUserOwner or user.is_superuser or content.author == user %}
4136
<a href="{% url 'frontend:course-delete' pk=course.pk %}" class="dropdown-item text-danger"
4237
>{% fa5_icon 'trash' 'fas' %} Delete</a>

frontend/templatetags/cc_frontend_tags.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,21 @@ def content_card(type):
8989

9090

9191
@register.filter
92-
def check_markdown(type):
93-
# TODO: implement markdown check
92+
def is_content_editable(type):
93+
# TODO: implement check
9494
return False
9595

9696

9797
@register.inclusion_tag("frontend/course/dropdown_topic.html")
9898
def add_content_button(user, course_id, topic_id):
99+
"""
100+
generate dropdown-button containing list of available content types
101+
:param User user: the user
102+
:param int course_id: id of the course
103+
:param int topic_id: id of the topic
104+
:return: dropdown button as html div
105+
:rtype: dict
106+
"""
99107
# generate list of tuple (content type, content verbose name) for add content dropdown
100-
content_data = [(content_type, content_model.DESC) for content_type, content_model in zip(CONTENT_TYPES.keys(), CONTENT_TYPES.values())]
108+
content_data = [(content_type, content_model.DESC) for content_type, content_model in CONTENT_TYPES.items()]
101109
return {'user': user, 'course_id': course_id, 'topic_id': topic_id, 'content_data': content_data}

frontend/views/content.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from django.contrib import messages
12
from django.contrib.auth.mixins import LoginRequiredMixin
23
from django.contrib.messages.views import SuccessMessageMixin
34
from django.http import HttpResponseRedirect, Http404, HttpResponseBadRequest
45
from django.shortcuts import get_object_or_404
5-
from django.urls import reverse_lazy
6+
from django.urls import reverse_lazy, reverse
67
from django.utils import timezone
78
from django.utils.translation import gettext_lazy as _
89
from django.views.generic import DetailView, CreateView
@@ -26,24 +27,37 @@ class AddContentView(SuccessMessageMixin, LoginRequiredMixin, CreateView): # py
2627
def get_success_message(self, cleaned_data):
2728
return _(f"Content '{cleaned_data['type']}' successfully added")
2829

30+
def handle_error(self):
31+
"""
32+
create error message and return to course page
33+
"""
34+
course_id = self.kwargs['course_id']
35+
messages.error(self.request, _('An error occurred while processing the request'))
36+
return HttpResponseRedirect(reverse('frontend:course', args=(course_id,)))
37+
2938
def get_context_data(self, **kwargs):
3039
context = super().get_context_data(**kwargs)
3140

3241
if "type" in self.kwargs:
3342
content_type = self.kwargs['type']
3443
if content_type in CONTENT_TYPE_FORMS:
3544
context['content_type_form'] = CONTENT_TYPE_FORMS.get(content_type)
45+
else:
46+
return self.handle_error()
47+
else:
48+
return self.handle_error()
3649
return context
3750

3851
def post(self, request, *args, **kwargs):
3952
add_content_form = AddContentForm(request.POST)
40-
content_type = self.kwargs['type']
41-
if content_type in CONTENT_TYPE_FORMS:
42-
content_type_form = CONTENT_TYPE_FORMS.get(content_type)(request.POST, request.FILES)
53+
if "type" in self.kwargs:
54+
content_type = self.kwargs['type']
55+
if content_type in CONTENT_TYPE_FORMS:
56+
content_type_form = CONTENT_TYPE_FORMS.get(content_type)(request.POST, request.FILES)
57+
else:
58+
return self.handle_error()
4359
else:
44-
return HttpResponseBadRequest('Invalid Post Request')
45-
# use for HTTPResponseRedirect
46-
course_id = self.kwargs['course_id']
60+
return self.handle_error()
4761

4862
if add_content_form.is_valid() and content_type_form.is_valid():
4963
# save author etc.
@@ -58,6 +72,7 @@ def post(self, request, *args, **kwargs):
5872
content_type_data.content = content
5973
content_type_data.save()
6074

75+
course_id = self.kwargs['course_id']
6176
topic_id = self.kwargs['topic_id']
6277
return HttpResponseRedirect(reverse_lazy('frontend:content', args=(course_id, topic_id, content.id,)))
6378

0 commit comments

Comments
 (0)