Skip to content

Commit 08f8770

Browse files
authored
Merge pull request #39 from DataManagementLab/#7_Frontend_Visualize_Coursebook
#7 frontend visualize coursebook
2 parents ffc0067 + 487d549 commit 08f8770

8 files changed

Lines changed: 126 additions & 53 deletions

File tree

frontend/locale/de_DE/LC_MESSAGES/django.po

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ msgstr "Soll der folgende Kommentar wirklich gelöscht werden?"
3535

3636
#: frontend/templates/frontend/content/addcontent.html:23
3737
#: frontend/templates/frontend/course/create.html:29
38+
#: frontend/templates/frontend/course/duplicate.html:29
3839
#: frontend/templates/frontend/course/edit.html:29
3940
msgid "Create"
4041
msgstr "Erzeugen"
4142

4243
#: frontend/templates/frontend/content/addcontent.html:24
43-
#: frontend/templates/frontend/content/detail.html:80
44+
#: frontend/templates/frontend/content/detail.html:86
4445
#: frontend/templates/frontend/course/create.html:30
46+
#: frontend/templates/frontend/course/duplicate.html:30
4547
#: frontend/templates/frontend/course/edit.html:30
4648
#: frontend/templates/frontend/profile/profile_edit.html:19
4749
msgid "Cancel"
@@ -52,23 +54,31 @@ msgstr "Abbrechen"
5254
msgid "Actions"
5355
msgstr "Aktionen"
5456

55-
#: frontend/templates/frontend/content/detail.html:43
57+
#: frontend/templates/frontend/content/detail.html:33
58+
#: frontend/templates/frontend/content/detail.html:35
59+
#: frontend/templates/frontend/course/coursebook.html:16
60+
#, fuzzy
61+
#| msgid "Courses"
62+
msgid "Coursebook"
63+
msgstr "Kurse"
64+
65+
#: frontend/templates/frontend/content/detail.html:49
5666
msgid "Back to course "
5767
msgstr "Zurück zum Kurs "
5868

59-
#: frontend/templates/frontend/content/detail.html:49
69+
#: frontend/templates/frontend/content/detail.html:55
6070
msgid "By"
6171
msgstr "Von"
6272

63-
#: frontend/templates/frontend/content/detail.html:59
73+
#: frontend/templates/frontend/content/detail.html:65
6474
msgid "Created at"
6575
msgstr "Erstellt am"
6676

67-
#: frontend/templates/frontend/content/detail.html:67
77+
#: frontend/templates/frontend/content/detail.html:73
6878
msgid "Delete"
6979
msgstr "Löschen"
7080

71-
#: frontend/templates/frontend/content/detail.html:71
81+
#: frontend/templates/frontend/content/detail.html:77
7282
#, python-format
7383
msgid ""
7484
"\n"
@@ -81,27 +91,20 @@ msgstr ""
8191
"Diese Aktion kann nicht rückgängig gemacht werden.\n"
8292
" "
8393

84-
#: frontend/templates/frontend/content/detail.html:83
85-
#: frontend/templates/frontend/course/create.html:30
86-
#: frontend/templates/frontend/course/duplicate.html:30
87-
#: frontend/templates/frontend/profile/profile_edit.html:19
88-
msgid "Cancel"
89-
msgstr "Abbrechen"
90-
91-
#: frontend/templates/frontend/content/detail.html:86
94+
#: frontend/templates/frontend/content/detail.html:89
9295
msgid "Confirm"
9396
msgstr "Bestätigen"
9497

95-
#: frontend/templates/frontend/content/detail.html:99
98+
#: frontend/templates/frontend/content/detail.html:105
9699
#: frontend/templates/frontend/course/topic_contents.html:29
97100
msgid "Rating"
98101
msgstr "Bewertung"
99102

100-
#: frontend/templates/frontend/content/detail.html:109
103+
#: frontend/templates/frontend/content/detail.html:115
101104
msgid "Comments"
102105
msgstr "Kommentare"
103106

104-
#: frontend/templates/frontend/content/detail.html:115
107+
#: frontend/templates/frontend/content/detail.html:121
105108
msgid "Add comment"
106109
msgstr "Kommentar hinzufügen"
107110

@@ -117,31 +120,30 @@ msgstr "Nächste"
117120
msgid "Previous"
118121
msgstr "Vorherige"
119122

123+
#: frontend/templates/frontend/course/coursebook.html:10
124+
msgid "Export"
125+
msgstr "Exportieren"
126+
127+
#: frontend/templates/frontend/course/coursebook.html:22
128+
#, fuzzy
129+
#| msgid "Your Courses"
130+
msgid "Your coursebook is empty"
131+
msgstr "Dein Kursbuch ist leer"
132+
120133
#: frontend/templates/frontend/course/create.html:11
121134
msgid "Create a new course"
122135
msgstr "Neuen Kurs anlegen"
123136

124-
#: frontend/templates/frontend/course/create.html:29
125-
#: frontend/templates/frontend/course/duplicate.html:29
126-
msgid "Create"
127-
msgstr "Erzeugen"
137+
#: frontend/templates/frontend/course/dropdown_topic.html:10
138+
msgid "Add Content"
139+
msgstr "Inhalte hinzufügen"
128140

129141
#: frontend/templates/frontend/course/duplicate.html:11
130142
#: frontend/templates/frontend/course/duplicate.html:19
131-
#: frontend/templates/frontend/course/view.html:25
143+
#: frontend/templates/frontend/course/view.html:31
132144
msgid "Duplicate Course"
133145
msgstr "Kurs duplizieren"
134146

135-
#: frontend/templates/frontend/course/view.html:36
136-
#: frontend/templates/frontend/course/view.html:27
137-
msgid "Delete Course"
138-
msgstr "Kurs löschen"
139-
140-
#: frontend/templates/frontend/course/view.html:63
141-
#: frontend/templates/frontend/course/dropdown_topic.html:10
142-
msgid "Add Content"
143-
msgstr "Inhalte hinzufügen"
144-
145147
#: frontend/templates/frontend/course/edit.html:11
146148
msgid "Edit course"
147149
msgstr "Kurs bearbeiten"
@@ -150,6 +152,10 @@ msgstr "Kurs bearbeiten"
150152
msgid "Edit Course"
151153
msgstr "Kurs hinzufügen"
152154

155+
#: frontend/templates/frontend/course/view.html:36
156+
msgid "Delete Course"
157+
msgstr "Kurs löschen"
158+
153159
#: frontend/templates/frontend/course/view.html:76
154160
msgid "No topics yet"
155161
msgstr "Bisher keine Themen"
@@ -287,6 +293,14 @@ msgstr "Kommentar erfolgreich gelöscht."
287293
msgid "Successfully edited Comment."
288294
msgstr "Kommentar erfolgreich bearbeitet."
289295

296+
#: frontend/views/content.py:28
297+
msgid "Content '{cleaned_data['type']}' successfully added"
298+
msgstr "Inhalt '{cleaned_data['type']}' erfolgreich hinzugefügt"
299+
300+
#: frontend/views/content.py:35
301+
msgid "An error occurred while processing the request"
302+
msgstr "Es trat ein Fehler beim Verarbeiten der Anfrage auf"
303+
290304
#: frontend/views/course.py:27
291305
msgid ""
292306
"Course '{cleaned_data['title']}' successfully created. All settings and "
@@ -299,19 +313,7 @@ msgstr ""
299313
msgid "Course '{cleaned_data['title']}' successfully created"
300314
msgstr "Kurs '{cleaned_data['title']}' erfolgreich angelegt"
301315

302-
#: frontend/views/content.py:28
303-
msgid "Content '{cleaned_data['type']}' successfully added"
304-
msgstr "Inhalt '{cleaned_data['type']}' erfolgreich hinzugefügt"
305-
306-
#: frontend/views/content.py:35
307-
msgid "An error occurred while processing the request"
308-
msgstr "Es trat ein Fehler beim Verarbeiten der Anfrage auf"
309-
310-
#: frontend/views/course.py:26
311-
msgid "Course '{cleaned_data['title']}' successfully created"
312-
msgstr "Kurs '{cleaned_data['title']}' erfolgreich angelegt"
313-
314-
#: frontend/views/course.py:52
316+
#: frontend/views/course.py:88
315317
msgid "Course '{cleaned_data['title']}' successfully edited"
316318
msgstr "Kurs '{cleaned_data['title']}' erfolgreich bearbeitet"
317319

frontend/templates/frontend/content/detail.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727
<a class="dropdown-item"
2828
href="{#{% url 'edit_md_file' course.id topic.id content.id %}#}">{% fa5_icon 'pencil-alt' 'fas' %}
2929
Edit</a>
30+
{% endif %}
3031

32+
{% if favorite %}
33+
<a class="dropdown-item" href="{% url 'frontend:coursebook-remove' course.id topic.id content.id %}">{% fa5_icon 'minus' 'far' %} {% trans 'Coursebook' %}</a>
34+
{% else %}
35+
<a class="dropdown-item" href="{% url 'frontend:coursebook-add' course.id topic.id content.id %}">{% fa5_icon 'plus' 'far' %} {% trans 'Coursebook' %}</a>
3136
{% endif %}
37+
3238
{% if isCurrentUserOwner or user.is_superuser or content.author == user %}
3339
<a href="#" class="dropdown-item text-danger" data-toggle="modal"
3440
data-target="#deleteContentModal">{% fa5_icon 'trash' 'fas' %} Delete</a>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% load i18n %}
2+
{# Load the tag library #}
3+
{% load bootstrap4 %}
4+
{% load fontawesome_5 %}
5+
{% load cc_frontend_tags %}
6+
7+
<div class="mt-3">
8+
{% with user|get_coursebook:course as topic_contents %}
9+
{% if topic_contents|length > 0 %}
10+
<a href="" class="btn btn-primary float-right text-right">{% trans 'Export' %}</a>
11+
{% endif %}
12+
<button class="btn btn-primary float-left mr-1" type="button" data-toggle="collapse" data-target="#collapseCoursebook"
13+
aria-expanded="false" aria-controls="collapseCoursebook">
14+
{% fa5_icon 'bars' 'fas' %}
15+
</button>
16+
<h2>{% trans 'Coursebook' %}</h2>
17+
<div class="collapse show" id="collapseCoursebook">
18+
<div class="card card-body">
19+
{% if topic_contents|length > 0 %}
20+
{% include "frontend/course/topic_contents.html" %}
21+
{% else %}
22+
<p>{% trans 'Your coursebook is empty' %}</p>
23+
{% endif %}
24+
</div>
25+
</div>
26+
{% endwith %}
27+
</div>

frontend/templates/frontend/course/view.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ <h5 style="margin-top: 20px;">
8484
<!-- TODO Add image? -->
8585
</div>
8686

87+
{% include 'frontend/course/coursebook.html' %}
88+
8789
{% for entry in structure %}
8890
<div style="margin-top: 30px;">
8991
{% with forloop.counter as outer_index %}

frontend/templatetags/cc_frontend_tags.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django import template
22
from django.conf import settings
33

4+
from base.models import Favorite
45
from collab_coursebook.settings import ALLOW_PUBLIC_COURSE_EDITING_BY_EVERYONE
56
from content.models import CONTENT_TYPES
67

@@ -115,3 +116,10 @@ def add_content_button(user, course_id, topic_id):
115116
# generate list of tuple (content type, content verbose name) for add content dropdown
116117
content_data = [(content_type, content_model.DESC) for content_type, content_model in CONTENT_TYPES.items()]
117118
return {'user': user, 'course_id': course_id, 'topic_id': topic_id, 'content_data': content_data}
119+
120+
121+
@register.filter
122+
def get_coursebook(user, course):
123+
favorites = Favorite.objects.filter(user=user.profile, course=course)
124+
coursebook = [favorite.content for favorite in favorites]
125+
return coursebook

frontend/urls.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from content.models import CONTENT_TYPES
44
from frontend import views
55
from frontend.views.search import SearchView
6+
from frontend.views.coursebook import add_to_coursebook, remove_from_coursebook
67

78
app_name = "frontend"
89

@@ -25,8 +26,12 @@
2526
])),
2627
path('<int:course_id>/topic/<int:topic_id>/content/', include([
2728
re_path(r'add/(?P<type>' + '|'.join([key for key in CONTENT_TYPES.keys()]) + ')/$', views.content.AddContentView.as_view(), name='content-add'),
28-
path('<int:content_id>/comment/<int:pk>/delete/', views.DeleteComment.as_view(), name='comment-delete'),
29-
path('<int:content_id>/comment/<int:pk>/edit/', views.EditComment.as_view(), name='comment-edit'),
29+
path('<int:content_id>/', include([
30+
path('comment/<int:pk>/delete/', views.DeleteComment.as_view(), name='comment-delete'),
31+
path('comment/<int:pk>/edit/', views.EditComment.as_view(), name='comment-edit'),
32+
path('coursebook/add/', views.coursebook.add_to_coursebook, name='coursebook-add'),
33+
path('coursebook/remove/', views.coursebook.remove_from_coursebook, name='coursebook-remove'),
34+
])),
3035
path('<pk>/', views.ContentView.as_view(), name='content'),
3136
path('<pk>/read/', views.content.ContentReadingModeView.as_view(), name='content-reading-mode'),
3237
])),

frontend/views/content.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,9 @@ def get_context_data(self, **kwargs):
192192

193193
if self.request.user.is_authenticated:
194194
context['user_rate'] = content.get_user_rate(self.request.user.profile)
195-
"""
196-
if Favourite.objects.filter(course=course, user=get_user(self.request),
197-
content_list=content).count() > 0:
198-
context['favourite'] = True
199-
"""
195+
196+
context['favorite'] = Favorite.objects.filter(course=course, user=get_user(self.request),
197+
content=content).count() > 0
200198
return context
201199

202200

@@ -222,7 +220,8 @@ def get_context_data(self, **kwargs):
222220
topic = Topic.objects.get(pk=topic_id)
223221
if self.request.GET.get('coursebook'):
224222
course = get_object_or_404(Course, {"pk": self.kwargs['course_id']})
225-
contents = [f.content for f in Favorite.objects.filter(course=course, user=self.request.user.profile)] #models.get_coursebook_flat(get_user(self.request), course)
223+
contents = [f.content for f in Favorite.objects.filter(course=course,
224+
user=self.request.user.profile)] # models.get_coursebook_flat(get_user(self.request), course)
226225
else:
227226
contents = topic.get_contents(self.request.GET.get('s'), self.request.GET.get('f'))
228227

frontend/views/coursebook.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from django.http import HttpResponseRedirect
2+
from django.shortcuts import get_object_or_404
3+
from django.urls import reverse
4+
from base.models import Course, Favorite, Topic, Content
5+
6+
7+
def add_to_coursebook(request, *args, **kwargs):
8+
user = request.user.profile
9+
course = get_object_or_404(Course, pk=kwargs['course_id'])
10+
topic = get_object_or_404(Topic, pk=kwargs['topic_id'])
11+
content = get_object_or_404(Content, pk=kwargs['content_id'])
12+
13+
Favorite.objects.create(content=content, user=user, course=course)
14+
return HttpResponseRedirect(reverse('frontend:content', args=(course.id, topic.id, content.id,)))
15+
16+
17+
def remove_from_coursebook(request, *args, **kwargs):
18+
user = request.user.profile
19+
course = get_object_or_404(Course, pk=kwargs['course_id'])
20+
topic = get_object_or_404(Topic, pk=kwargs['topic_id'])
21+
content = get_object_or_404(Content, pk=kwargs['content_id'])
22+
23+
Favorite.objects.filter(course=course, user=user, content=content).delete()
24+
return HttpResponseRedirect(reverse('frontend:content', args=(course.id, topic.id, content.id,)))

0 commit comments

Comments
 (0)