Skip to content

Commit 1675fb8

Browse files
implement rate_content
1 parent 655bbe9 commit 1675fb8

8 files changed

Lines changed: 30 additions & 23 deletions

File tree

base/locale/de_DE/LC_MESSAGES/django.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-06-05 11:48+0000\n"
11+
"POT-Creation-Date: 2020-06-22 14:54+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"

base/models/content.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,18 @@ def get_user_rate(self, user):
203203
def rate_content(self, user, rate):
204204
"""
205205
Rate content
206+
:param content: Content
206207
:param User user: user
207208
:param int rate: rating
208209
:return: nothing
209210
"""
210-
self.ratings.filter(user_id=user.pk, content_id=self.id).delete() # pylint: disable=no-member
211-
self.ratings.objects.create(user=user, content_id=self.pk, rating=rate) # pylint: disable=no-member
211+
#print(self.ratings.)
212+
# self.ratings (Content) != Rating
213+
214+
#self.ratings.objects.create(user=user, content_id=self.pk, rating=rate) # pylint: disable=no-member
215+
216+
self.ratings.filter(user_id=user.user.pk, content=self).delete() # pylint: disable=no-member
217+
self.ratings.objects.create(user=user, content=self, rating=rate) # pylint: disable=no-member
212218

213219
def get_index_in_course(self, course):
214220
"""

collab_coursebook/locale/de_DE/LC_MESSAGES/django.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-06-05 11:48+0000\n"
11+
"POT-Creation-Date: 2020-06-22 14:54+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"

content/locale/de_DE/LC_MESSAGES/django.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-06-05 11:48+0000\n"
11+
"POT-Creation-Date: 2020-06-22 14:54+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"

frontend/forms/content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ class TranslateForm(forms.Form):
1313
widget=forms.Select(choices=TRANSLATE_CHOICE,
1414
attrs={'class': 'form-control',
1515
'style': 'width:auto',
16-
'onchange': 'this.form.submit();'}))
16+
'onchange': 'this.form.submit();'}))

frontend/locale/de_DE/LC_MESSAGES/django.po

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-06-05 11:48+0000\n"
11+
"POT-Creation-Date: 2020-06-22 14:54+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -98,12 +98,10 @@ msgid "Create"
9898
msgstr "Erzeugen"
9999

100100
#: frontend/templates/frontend/course/view.html:26
101-
#: frontend/templates/frontend/course/view_course.html:36
102101
msgid "Delete Course"
103102
msgstr "Kurs löschen"
104103

105104
#: frontend/templates/frontend/course/view.html:62
106-
#: frontend/templates/frontend/course/view_course.html:58
107105
msgid "No topics yet"
108106
msgstr "Bisher keine Themen"
109107

@@ -227,6 +225,6 @@ msgstr "Kommentar erfolgreich bearbeitet."
227225
msgid "Course '{cleaned_data['title']}' successfully created"
228226
msgstr "Kurs '{cleaned_data['title']}' erfolgreich angelegt"
229227

230-
#: frontend/views/profile.py:26
228+
#: frontend/views/profile.py:25
231229
msgid "Profile updated"
232230
msgstr "Profil aktualisiert"

frontend/templates/frontend/content/detail.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,17 @@ <h5 class="modal-title" id="deleteContentModalLabel">{% trans "Delete" %} <i>{{
9898
{{ content.description|linebreaks }}
9999
</div>
100100
</div>
101-
101+
ratings
102102
<h5><a name="rating">{% trans "Rating" %}</a></h5>
103-
<div class="starrating risingstar d-flex justify-content-end flex-row-reverse">
104-
{% for i in 5|rev_range %}
105-
<input type="radio" id="star{{ i }}" name="rating" value="{{ i }}"
106-
{% if i <= user_rate %}class="active" {% endif %}/>
107-
<label for="star{{ i }}" onclick="window.location.href='{% url 'frontend:rating' course.id topic.id content.id i %}'"></label>
108-
{% endfor %}
109-
</div>
103+
<div class="float-right text-right"><a>{% trans "Current" %} {{ content.get_rate_num }}</a> </div>
104+
<div class="starrating risingstar d-flex justify-content-end flex-row-reverse">
105+
{% for i in 5|rev_range %}
106+
<input type="radio" id="star{{ i }}" name="rating" value="{{ i }}"
107+
{% if i <= user_rate %}class="active" {% endif %}/>
108+
<label for="star{{ i }}" onclick="window.location.href='{% url 'frontend:rating' course.id topic.id content.id i %}'"></label>
109+
{% endfor %}
110+
</div>
111+
110112

111113
<h5 style="margin-top: 30px;"><a name="comments">{% trans "Comments" %}</a></h5>
112114
{% if user.is_authenticated %}

frontend/views/content.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,14 @@ def rate_content(request, course_id, topic_id, content_id, pk):
210210
print(course_id,topic_id,content_id,rating)
211211
print(type(get_user(request)))
212212
content = get_object_or_404(Content, pk=content_id)
213-
#print(Content.ratings.filter(user_id=user.pk, content_id=content.pk))
214213
profile = get_user(request)
215-
Rating.objects.filter(user_id=profile, content_id=content_id).delete()
216-
rating_obj = Rating.objects.create(user=profile, content=content, rating=rating) # user = profile
217-
content.ratings.add(rating_obj)
214+
content.rate_content(profile, rating)
215+
218216
# check if content already has rating
219-
#content.rate_content()
217+
#Rating.objects.filter(user_id=profile, content_id=content_id).delete()
218+
#Rating.objects.create(user=profile, content=content, rating=rating) # user = profile; rating_obj =
219+
220+
content.ratings.add(profile)
220221
content.save()
221222

222223
return HttpResponseRedirect(

0 commit comments

Comments
 (0)