@@ -42,6 +42,7 @@ class Course(models.Model):
4242 description: short description of the course
4343 owner: people that may change the structure of the course
4444 """
45+
4546 class Meta :
4647 verbose_name = _ ("Course" )
4748 verbose_name_plural = _ ("Courses" )
@@ -53,15 +54,17 @@ class Meta:
5354 creation_date = models .DateTimeField (verbose_name = _ ('Creation Date' ), auto_now_add = True , blank = True )
5455
5556 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 )
57+ topics = models .ManyToManyField ("Topic" , verbose_name = _ ("Topics" ), through = 'CourseStructureEntry' ,
58+ related_name = "courses" , blank = True )
5759
5860 owners = models .ManyToManyField (Profile , related_name = 'owned_courses' , verbose_name = _ ("Owners" ))
5961 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 )
62+ help_text = _ ("Is the course protected and can only be edited by the owners?" ),
63+ blank = True , default = False )
6164
6265 category = models .ForeignKey (Category , verbose_name = _ ("Category" ), related_name = "courses" , on_delete = models .CASCADE )
6366 period = models .ForeignKey (Period , verbose_name = _ ("Period" ), related_name = "courses" ,
64- blank = True , null = True , on_delete = models .SET_NULL )
67+ blank = True , null = True , on_delete = models .SET_NULL )
6568
6669 def __str__ (self ):
6770 return self .title
@@ -74,6 +77,7 @@ class Topic(models.Model):
7477 title: Name of the topic
7578 category: category this topic belongs to
7679 """
80+
7781 class Meta :
7882 verbose_name = _ ("Topic" )
7983 verbose_name_plural = _ ("Topics" )
@@ -125,6 +129,7 @@ class Content(models.Model):
125129 author: user that created the content
126130 parent_topic: the topic the content belongs to/describes
127131 """
132+
128133 class Meta :
129134 verbose_name = _ ("Content" )
130135 verbose_name_plural = _ ("Contents" )
@@ -139,8 +144,10 @@ class Meta:
139144 language = models .CharField (verbose_name = _ ("Language" ), max_length = 30 , choices = settings .LANGUAGES )
140145 tags = models .ManyToManyField (Tag , verbose_name = _ ("Tags" ), related_name = 'contents' , blank = True )
141146
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 )
147+ readonly = models .BooleanField (verbose_name = _ ("Readonly" ), help_text = _ ("Can this content be updated?" ),
148+ default = False )
149+ public = models .BooleanField (verbose_name = _ ("Show in public courses?" ), help_text = _ (
150+ "May this content be displayed in courses that don't require registration?" ), default = False )
144151
145152 creation_date = models .DateTimeField (verbose_name = _ ('Creation Date' ), auto_now_add = True , blank = True )
146153 preview = models .ImageField (verbose_name = _ ("Rendered preview" ), blank = True , null = True )
@@ -166,7 +173,9 @@ def get_rate(self):
166173 :return: rating
167174 :rtype: float
168175 """
169- rating = self .ratings .aggregate (Avg ('rating' ))['rating__avg' ]
176+
177+ rating = self .ratings .aggregate (Avg ('rating' ))['rating__avg' ] # todo something wrong here
178+ print (self .ratings )
170179 if rating is None :
171180 return 0
172181 return round (rating , 2 ) # pylint: disable=no-member
@@ -196,25 +205,27 @@ def get_user_rate(self, user):
196205 :rtype: int
197206 """
198207 if self .user_already_rated (user ):
199- # TODO FIX
200- return 0 #self.ratings.get(user_id=user.pk).rating # pylint: disable=no-member
208+ content_id = self .id
209+ return self .ratings .get (user = user ).rating_set .first ().rating
210+ #user.get_rating_from_content(content_id).rating # todo may change back to ratings
201211 return 0
202212
203- def rate_content (self , user , rate ):
213+ def rate_content (self , user ):
204214 """
205215 Rate content
206216 :param content: Content
207217 :param User user: user
208218 :param int rate: rating
209219 :return: nothing
210220 """
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
221+ # todo delete
222+ #self.ratings.get(user=user).delete()
223+ #self.ratings.add(user)
224+ #self.ratings.filter(user_id=user.pk).delete() # pylint: disable=no-member
225+ # create function won't work
226+ #self.ratings.add
227+ # pylint: disable=no-member
228+ self .save ()
218229
219230 def get_index_in_course (self , course ):
220231 """
@@ -233,6 +244,7 @@ class CourseStructureEntry(models.Model):
233244 index: position that is meant (e.g. "1#2" -> second undertopic of the first topic)
234245 topic: topic at specified position/index
235246 """
247+
236248 class Meta :
237249 verbose_name = _ ("Course Structure Entry" )
238250 verbose_name_plural = _ ("Course Structure Entries" )
0 commit comments