Skip to content

Commit b7736d5

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

10 files changed

Lines changed: 85 additions & 78 deletions

File tree

content/forms.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django import forms
2+
from content.models import YTVideoContent, ImageContent
3+
4+
5+
class AddContentFormYoutubeVideo(forms.ModelForm):
6+
class Meta:
7+
model = YTVideoContent
8+
exclude = ['content']
9+
10+
11+
class AddContentFormImage(forms.ModelForm):
12+
class Meta:
13+
model = ImageContent
14+
exclude = ['content']
15+
16+
17+
CONTENT_TYPE_FORMS = {
18+
YTVideoContent.TYPE: AddContentFormYoutubeVideo,
19+
ImageContent.TYPE: AddContentFormImage,
20+
}

frontend/forms/addcontent.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,3 @@ class AddContentForm(forms.ModelForm):
1010
class Meta: # pylint: disable=too-few-public-methods
1111
model = Content
1212
exclude = ['topic', 'author', 'creation_date', 'ratings', 'preview', 'type']
13-
14-
15-
class AddContentFormYoutubeVideo(forms.ModelForm):
16-
class Meta:
17-
model = YTVideoContent
18-
exclude = ['content']
19-
20-
21-
class AddContentFormImage(forms.ModelForm):
22-
class Meta:
23-
model = ImageContent
24-
exclude = ['content']

frontend/locale/de_DE/LC_MESSAGES/django.po

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,40 @@ msgstr "Diese Software ist Open Source"
3333
msgid "Are you sure you want to delete the following comment?"
3434
msgstr "Soll der folgende Kommentar wirklich gelöscht werden?"
3535

36+
#: frontend/templates/frontend/content/addcontent.html:23
37+
#: frontend/templates/frontend/course/create.html:29
38+
msgid "Create"
39+
msgstr "Erzeugen"
40+
41+
#: frontend/templates/frontend/content/addcontent.html:24
42+
#: frontend/templates/frontend/content/detail.html:80
43+
#: frontend/templates/frontend/course/create.html:30
44+
#: frontend/templates/frontend/profile/profile_edit.html:19
45+
msgid "Cancel"
46+
msgstr "Abbrechen"
47+
3648
#: frontend/templates/frontend/content/detail.html:18
49+
#: frontend/templates/frontend/course/view.html:25
3750
msgid "Actions"
3851
msgstr "Aktionen"
3952

40-
#: frontend/templates/frontend/content/detail.html:46
53+
#: frontend/templates/frontend/content/detail.html:43
4154
msgid "Back to course "
4255
msgstr "Zurück zum Kurs "
4356

44-
#: frontend/templates/frontend/content/detail.html:52
57+
#: frontend/templates/frontend/content/detail.html:49
4558
msgid "By"
4659
msgstr "Von"
4760

48-
#: frontend/templates/frontend/content/detail.html:62
61+
#: frontend/templates/frontend/content/detail.html:59
4962
msgid "Created at"
5063
msgstr "Erstellt am"
5164

52-
#: frontend/templates/frontend/content/detail.html:70
65+
#: frontend/templates/frontend/content/detail.html:67
5366
msgid "Delete"
5467
msgstr "Löschen"
5568

56-
#: frontend/templates/frontend/content/detail.html:74
69+
#: frontend/templates/frontend/content/detail.html:71
5770
#, python-format
5871
msgid ""
5972
"\n"
@@ -67,43 +80,31 @@ msgstr ""
6780
" "
6881

6982
#: frontend/templates/frontend/content/detail.html:83
70-
#: frontend/templates/frontend/course/create.html:30
71-
#: frontend/templates/frontend/profile/profile_edit.html:19
72-
msgid "Cancel"
73-
msgstr "Abbrechen"
74-
75-
#: frontend/templates/frontend/content/detail.html:86
7683
msgid "Confirm"
7784
msgstr "Bestätigen"
7885

79-
#: frontend/templates/frontend/content/detail.html:102
86+
#: frontend/templates/frontend/content/detail.html:99
8087
#: frontend/templates/frontend/course/topic_contents.html:29
8188
msgid "Rating"
8289
msgstr "Bewertung"
8390

84-
#: frontend/templates/frontend/content/detail.html:112
91+
#: frontend/templates/frontend/content/detail.html:109
8592
msgid "Comments"
8693
msgstr "Kommentare"
8794

88-
#: frontend/templates/frontend/content/detail.html:118
95+
#: frontend/templates/frontend/content/detail.html:115
8996
msgid "Add comment"
9097
msgstr "Kommentar hinzufügen"
9198

9299
#: frontend/templates/frontend/course/create.html:11
93100
msgid "Create a new course"
94101
msgstr "Neuen Kurs anlegen"
95102

96-
#: frontend/templates/frontend/course/create.html:29
97-
msgid "Create"
98-
msgstr "Erzeugen"
99-
100-
#: frontend/templates/frontend/course/view.html:26
101-
#: frontend/templates/frontend/course/view_course.html:36
102-
msgid "Delete Course"
103-
msgstr "Kurs löschen"
103+
#: frontend/templates/frontend/course/dropdown_topic.html:10
104+
msgid "Add Content"
105+
msgstr "Inhalte hinzufügen"
104106

105-
#: frontend/templates/frontend/course/view.html:62
106-
#: frontend/templates/frontend/course/view_course.html:58
107+
#: frontend/templates/frontend/course/view.html:83
107108
msgid "No topics yet"
108109
msgstr "Bisher keine Themen"
109110

@@ -223,10 +224,17 @@ msgstr "Kommentar erfolgreich gelöscht."
223224
msgid "Successfully edited Comment."
224225
msgstr "Kommentar erfolgreich bearbeitet."
225226

227+
#: frontend/views/content.py:28
228+
msgid "Content '{cleaned_data['type']}' successfully added"
229+
msgstr "Inhalt '{cleaned_data['title']}' erfolgreich hinzugefügt"
230+
226231
#: frontend/views/course.py:26
227232
msgid "Course '{cleaned_data['title']}' successfully created"
228233
msgstr "Kurs '{cleaned_data['title']}' erfolgreich angelegt"
229234

230-
#: frontend/views/profile.py:26
235+
#: frontend/views/profile.py:25
231236
msgid "Profile updated"
232237
msgstr "Profil aktualisiert"
238+
239+
#~ msgid "Delete Course"
240+
#~ msgstr "Kurs löschen"

frontend/templates/frontend/content/addcontent.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
</div>
2626

2727
</form>
28-
{% endblock %}
28+
{% endblock %}

frontend/templates/frontend/content/detail.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,7 @@
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-
<a class="dropdown-item" href="{# url 'favourite_content' course.id topic.id content.id #}?onDetailPage=True">
27-
{% if favourite %}{% fa5_icon 'bookmark' 'fas' %} Unsave {% else %}{% fa5_icon 'bookmark' 'far' %} Save{% endif %}</a>
28-
<a class="dropdown-item"
29-
href="{% url 'frontend:content-add' course_id=course.id topic_id=1 type='Image' %}">{% fa5_icon 'camera' 'fas' %}
30-
add image</a>
31-
<a class="dropdown-item"
32-
href="{% url 'frontend:content-add' course_id=course.id topic_id=1 type='YouTubeVideo' %}">{% fa5_icon 'video' 'fas' %}
33-
add youtube video</a>
34-
35-
<div class="dropdown-divider"></div>
36-
{% if markdown %}
26+
{% if content.type|check_markdown %}
3727
<a class="dropdown-item"
3828
href="{% url 'edit_md_file' course.id topic.id content.id %}">{% fa5_icon 'pencil-alt' 'fas' %}
3929
Edit</a>

frontend/templates/frontend/course/dropdown_topic.html

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,19 @@
33
{% load bootstrap4 %}
44
{% load fontawesome_5 %}
55
{% load cc_frontend_tags %}
6+
67
<div class="float-right text-right">
78
<div class="dropdown show">
89
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
910
{% trans "Add Content" %}
1011
</button>
1112
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
1213
{% if user.is_authenticated %}
13-
<a class="dropdown-item"
14-
href="{% url 'frontend:content-add' course_id=course.id topic_id=topic_replace.id type='Image' %}">{% fa5_icon 'camera' 'fas' %}
15-
{% trans "Image" %}</a>
16-
<a class="dropdown-item"
17-
href="{% url 'frontend:content-add' course_id=course.id topic_id=topic_replace.id type='YouTubeVideo' %}">{% fa5_icon 'video' 'fas' %}
18-
{% trans "Youtube Video" %}</a>
19-
<a class="dropdown-item"
20-
href="">{% fa5_icon 'file-pdf' 'fas' %}
21-
{% trans "Pdf File" %}</a>
22-
<a class="dropdown-item"
23-
href="">{% fa5_icon 'file' 'fas' %}
24-
{% trans "Markdown" %}</a>
14+
{% for content in content_data %}
15+
<a class="dropdown-item"
16+
href="{% url 'frontend:content-add' course_id=course_id topic_id=topic_id type=content.0 %}">{% trans content.1 %}</a>
17+
{% endfor %}
2518
{% endif %}
26-
2719
</div>
2820
</div>
2921
</div>

frontend/templates/frontend/course/view.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
<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>
3232
<div class="dropdown-divider"></div>
33-
{% if markdown %}
33+
34+
{% if content.type|check_markdown %}
3435
<a class="dropdown-item"
3536
href="{% url 'edit_md_file' course.id topic.id content.id %}">{% fa5_icon 'pencil-alt' 'fas' %}
3637
Edit</a>
@@ -94,7 +95,7 @@ <h5 style="margin-top: 20px;">
9495
<div style="margin-top: 30px;">
9596
{% with forloop.counter as outer_index %}
9697
{% with entry.topic as topic_replace %}
97-
{% include 'frontend/course/dropdown_topic.html' %}
98+
{% add_content_button user course.id topic_replace.id %}
9899
{% endwith %}
99100
<h3 class="text-info">{{ outer_index }}. {{ topic.title }}</h3>
100101
{% with entry.topic.contents.all as topic_contents %}
@@ -104,7 +105,7 @@ <h3 class="text-info">{{ outer_index }}. {{ topic.title }}</h3>
104105
{% for subtopic in entry.subtopics %}
105106
<div style="margin-top: 15px;">
106107
{% with subtopic as topic_replace %}
107-
{% include 'frontend/course/dropdown_topic.html' %}
108+
{% add_content_button user course.id topic_replace.id %}
108109
{% endwith %}
109110
<h4 class="text-info">{{ outer_index }}.{{ forloop.counter }}. {{ subtopic.title }}</h4>
110111
{% with subtopic.contents.all as topic_contents %}

frontend/templatetags/cc_frontend_tags.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,16 @@ def content_card(type):
8686
if type in CONTENT_TYPES.keys():
8787
return f"content/cards/{type}.html"
8888
return "content/cards/blank.html"
89+
90+
91+
@register.filter
92+
def check_markdown(type):
93+
# TODO: implement markdown check
94+
return False
95+
96+
97+
@register.inclusion_tag("frontend/course/dropdown_topic.html")
98+
def add_content_button(user, course_id, topic_id):
99+
# 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())]
101+
return {'user': user, 'course_id': course_id, 'topic_id': topic_id, 'content_data': content_data}

frontend/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.urls import path, re_path, include
22

3+
from content.models import CONTENT_TYPES
34
from frontend import views
45

56
app_name = "frontend"
@@ -20,7 +21,7 @@
2021
path('delete/', views.CourseDeleteView.as_view(), name='course-delete'),
2122
])),
2223
path('<int:course_id>/topic/<int:topic_id>/content/', include([
23-
re_path(r'add/(?P<type>YouTubeVideo|Image)/$', views.content.AddContentView.as_view(), name='content-add'),
24+
re_path(r'add/(?P<type>' + '|'.join([key for key in CONTENT_TYPES.keys()]) + ')/$', views.content.AddContentView.as_view(), name='content-add'),
2425
path('<int:content_id>/comment/<int:pk>/delete/', views.DeleteComment.as_view(), name='comment-delete'),
2526
path('<int:content_id>/comment/<int:pk>/edit/', views.EditComment.as_view(), name='comment-edit'),
2627
path('<pk>/', views.ContentView.as_view(), name='content'),

frontend/views/content.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
from base.models import Content, Comment, Course, Topic, Favorite
1111
from base.utils import get_user
12-
from content.models import YTVideoContent, ImageContent
1312
from frontend.forms import CommentForm, TranslateForm
14-
from frontend.forms.addcontent import AddContentForm, AddContentFormYoutubeVideo, AddContentFormImage
13+
from frontend.forms.addcontent import AddContentForm
14+
from content.forms import CONTENT_TYPE_FORMS
1515

1616

1717
class AddContentView(SuccessMessageMixin, LoginRequiredMixin, CreateView): # pylint: disable=too-many-ancestors
@@ -31,21 +31,15 @@ def get_context_data(self, **kwargs):
3131

3232
if "type" in self.kwargs:
3333
content_type = self.kwargs['type']
34-
if YTVideoContent.TYPE in content_type:
35-
context['content_type_form'] = AddContentFormYoutubeVideo
36-
elif ImageContent.TYPE in content_type:
37-
context['content_type_form'] = AddContentFormImage
38-
else:
39-
return HttpResponseBadRequest('Invalid Request')
34+
if content_type in CONTENT_TYPE_FORMS:
35+
context['content_type_form'] = CONTENT_TYPE_FORMS.get(content_type)
4036
return context
4137

4238
def post(self, request, *args, **kwargs):
4339
add_content_form = AddContentForm(request.POST)
4440
content_type = self.kwargs['type']
45-
if YTVideoContent.TYPE in content_type:
46-
content_type_form = AddContentFormYoutubeVideo(request.POST)
47-
elif ImageContent.TYPE in content_type:
48-
content_type_form = AddContentFormImage(request.POST, request.FILES)
41+
if content_type in CONTENT_TYPE_FORMS:
42+
content_type_form = CONTENT_TYPE_FORMS.get(content_type)(request.POST, request.FILES)
4943
else:
5044
return HttpResponseBadRequest('Invalid Post Request')
5145
# use for HTTPResponseRedirect

0 commit comments

Comments
 (0)