Skip to content

Commit f7efbf2

Browse files
committed
Merge branch 'main' into #26_pdf
# Conflicts: # requirements.txt
2 parents 9c31d28 + 146c8db commit f7efbf2

37 files changed

Lines changed: 413 additions & 103 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: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from fontawesome_5.fields import IconField
66

77
from base.models import Profile
8+
from .social import Rating
89

910

1011
class Category(models.Model):
@@ -42,6 +43,7 @@ class Course(models.Model):
4243
description: short description of the course
4344
owner: people that may change the structure of the course
4445
"""
46+
4547
class Meta:
4648
verbose_name = _("Course")
4749
verbose_name_plural = _("Courses")
@@ -53,15 +55,17 @@ class Meta:
5355
creation_date = models.DateTimeField(verbose_name=_('Creation Date'), auto_now_add=True, blank=True)
5456

5557
image = models.ImageField(verbose_name=_("Title Image"), blank=True, upload_to='uploads/courses/%Y/%m/%d/')
56-
topics = models.ManyToManyField("Topic", verbose_name=_("Topics"), through='CourseStructureEntry', related_name="courses", blank=True)
58+
topics = models.ManyToManyField("Topic", verbose_name=_("Topics"), through='CourseStructureEntry',
59+
related_name="courses", blank=True)
5760

5861
owners = models.ManyToManyField(Profile, related_name='owned_courses', verbose_name=_("Owners"))
5962
restrict_changes = models.BooleanField(verbose_name=_("Edit Restriction"),
60-
help_text=_("Is the course protected and can only be edited by the owners?"), blank=True, default=False)
63+
help_text=_("Is the course protected and can only be edited by the owners?"),
64+
blank=True, default=False)
6165

6266
category = models.ForeignKey(Category, verbose_name=_("Category"), related_name="courses", on_delete=models.CASCADE)
6367
period = models.ForeignKey(Period, verbose_name=_("Period"), related_name="courses",
64-
blank=True, null=True, on_delete=models.SET_NULL)
68+
blank=True, null=True, on_delete=models.SET_NULL)
6569

6670
def __str__(self):
6771
return self.title
@@ -74,6 +78,7 @@ class Topic(models.Model):
7478
title: Name of the topic
7579
category: category this topic belongs to
7680
"""
81+
7782
class Meta:
7883
verbose_name = _("Topic")
7984
verbose_name_plural = _("Topics")
@@ -125,6 +130,7 @@ class Content(models.Model):
125130
author: user that created the content
126131
parent_topic: the topic the content belongs to/describes
127132
"""
133+
128134
class Meta:
129135
verbose_name = _("Content")
130136
verbose_name_plural = _("Contents")
@@ -139,8 +145,10 @@ class Meta:
139145
language = models.CharField(verbose_name=_("Language"), max_length=30, choices=settings.LANGUAGES)
140146
tags = models.ManyToManyField(Tag, verbose_name=_("Tags"), related_name='contents', blank=True)
141147

142-
readonly = models.BooleanField(verbose_name=_("Readonly"), help_text=_("Can this content be updated?"), default=False)
143-
public = models.BooleanField(verbose_name=_("Show in public courses?"), help_text=_("May this content be displayed in courses that don't require registration?"), default=False)
148+
readonly = models.BooleanField(verbose_name=_("Readonly"), help_text=_("Can this content be updated?"),
149+
default=False)
150+
public = models.BooleanField(verbose_name=_("Show in public courses?"), help_text=_(
151+
"May this content be displayed in courses that don't require registration?"), default=False)
144152

145153
creation_date = models.DateTimeField(verbose_name=_('Creation Date'), auto_now_add=True, blank=True)
146154
preview = models.ImageField(verbose_name=_("Rendered preview"), blank=True, null=True)
@@ -161,15 +169,10 @@ def get_rate_num(self):
161169
return self.get_rate()
162170

163171
def get_rate(self):
164-
"""
165-
return the average rating and 0 if there are no ratings
166-
:return: rating
167-
:rtype: float
168-
"""
169-
rating = self.ratings.aggregate(Avg('rating'))['rating__avg']
170-
if rating is None:
171-
return 0
172-
return round(rating, 2) # pylint: disable=no-member
172+
rating = Rating.objects.filter(content_id=self.id).aggregate(Avg('rating'))['rating__avg']
173+
if rating is not None:
174+
return rating
175+
return -1
173176

174177
def get_rate_count(self):
175178
"""
@@ -196,19 +199,23 @@ def get_user_rate(self, user):
196199
:rtype: int
197200
"""
198201
if self.user_already_rated(user):
199-
# TODO FIX
200-
return 0 #self.ratings.get(user_id=user.pk).rating # pylint: disable=no-member
202+
content_id = self.id
203+
return self.ratings.get(user=user).rating_set.first().rating
201204
return 0
202205

203-
def rate_content(self, user, rate):
206+
def rate_content(self, user, rating):
204207
"""
205208
Rate content
209+
:param rating: Rating of Content by User
210+
:param content: Content
206211
:param User user: user
207-
:param int rate: rating
208212
:return: nothing
209213
"""
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
214+
Rating.objects.filter(user_id=user.user.id, content_id=self.id).delete()
215+
rating = Rating.objects.create(user=user, content=self, rating=rating) # user = profile
216+
rating.save()
217+
# pylint: disable=no-member
218+
self.save()
212219

213220
def get_index_in_course(self, course):
214221
"""
@@ -227,6 +234,7 @@ class CourseStructureEntry(models.Model):
227234
index: position that is meant (e.g. "1#2" -> second undertopic of the first topic)
228235
topic: topic at specified position/index
229236
"""
237+
230238
class Meta:
231239
verbose_name = _("Course Structure Entry")
232240
verbose_name_plural = _("Course Structure Entries")

base/models/profile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.utils.translation import gettext_lazy as _
66

77

8+
89
class Profile(models.Model):
910
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
1011
bio = models.TextField(verbose_name=_("Biography"), blank=True)
@@ -24,3 +25,4 @@ def create_user_profile(sender, instance, created, **kwargs):
2425
@receiver(post_save, sender=User)
2526
def save_user_profile(sender, instance, **kwargs):
2627
instance.profile.save()
28+

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"

collab_coursebook/settings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@
4848
'frontend',
4949
'content',
5050
'export',
51+
'debug_toolbar',
5152
]
5253

5354
MIDDLEWARE = [
55+
'debug_toolbar.middleware.DebugToolbarMiddleware',
5456
'django.middleware.security.SecurityMiddleware',
5557
'django.contrib.sessions.middleware.SessionMiddleware',
58+
'django.middleware.locale.LocaleMiddleware',
5659
'django.middleware.common.CommonMiddleware',
5760
'django.middleware.csrf.CsrfViewMiddleware',
5861
'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -151,6 +154,11 @@
151154
MEDIA_URL = '/media/'
152155
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
153156

157+
# Used for Debug Toolbar
158+
INTERNAL_IPS = [
159+
'127.0.0.1',
160+
]
161+
154162
# Settings for Bootstrap
155163
BOOTSTRAP4 = {
156164
# Use custom CSS

collab_coursebook/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from django.urls import path, include
2020

2121
import django_cas_ng.views
22+
import debug_toolbar
2223

2324
urlpatterns = [
2425
path('admin/', admin.site.urls),
@@ -27,4 +28,6 @@
2728
path('accounts/logout/', django_cas_ng.views.LogoutView.as_view(), name='cas_ng_logout'),
2829
path('accounts/callback/', django_cas_ng.views.CallbackView.as_view(), name='cas_ng_proxy_callback'),
2930
path('', include('frontend.urls', namespace='frontend')),
31+
path('i18n/', include('django.conf.urls.i18n')),
32+
path('__debug__/', include(debug_toolbar.urls)),
3033
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

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"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% load cc_export_tags %}
2+
{% autoescape off %}
3+
4+
\textbf{Image}
5+
\Image{ {{content.description|tex_escape}} }{% templatetag openbrace %}{{content.imagecontent.image.path}}{% templatetag closebrace%}
6+
\newline
7+
{{content.description|tex_escape}}
8+
\newline
9+
10+
{% endautoescape %}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% load cc_export_tags %}
2+
{% autoescape off %}
3+
\textbf{YouTube video}
4+
\newline
5+
\href{ {{ content.ytvideocontent.url }} }{ {{ content.ytvideocontent.url }} }
6+
\newline
7+
{{content.description|tex_escape}}
8+
\newline
9+
{% endautoescape %}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{% load cc_export_tags %}
2+
{% autoescape off %}
3+
4+
\documentclass[a4paper]{article}
5+
6+
\usepackage[utf8]{inputenc}
7+
\usepackage[T1]{fontenc}
8+
\usepackage[ngerman]{babel}
9+
\usepackage{graphicx}
10+
\usepackage{float}
11+
\usepackage{grffile}
12+
\usepackage{hyperref}
13+
\usepackage[left=1cm, right=1cm, top=2cm, bottom=2cm]{geometry}
14+
15+
%% Generate a latex graphic
16+
% 1: caption
17+
% 2: image path
18+
\newcommand{\Image}[2]{
19+
\begin{figure}[H]
20+
\centering
21+
\includegraphics[width=\textwidth]{#2}
22+
\caption{#1}
23+
\end{figure}
24+
}
25+
26+
\begin{document}
27+
28+
\title{ {{ course.title|tex_escape }} }
29+
\author{ {{user|tex_escape}} }
30+
\maketitle
31+
32+
% \end{document} gets appended in code
33+
34+
{% endautoescape %}

0 commit comments

Comments
 (0)