]> git.parisson.com Git - teleforma.git/commitdiff
Refactoring of suggestions into a mixin
authorYoan Le Clanche <yoanl@pilotsystems.net>
Mon, 21 Dec 2020 14:37:05 +0000 (15:37 +0100)
committerYoan Le Clanche <yoanl@pilotsystems.net>
Mon, 21 Dec 2020 14:37:05 +0000 (15:37 +0100)
teleforma/models/core.py
teleforma/models/pro.py

index 2be29f75669b18ac44629b3b22a833fd106bebc3..4c6542f3af81980c4858e784502592f8f509d88d 100755 (executable)
@@ -530,6 +530,26 @@ class Media(MediaBase):
         ordering = ['rank']
 
 
+class SuggestionsMixin(Model):
+    suggested_seminars = models.ManyToManyField('Seminar', related_name="%(class)ss_related",
+                                                verbose_name=_('suggested seminars'),
+                                                blank=True, null=True)
+    suggested_conferences = models.ManyToManyField('Conference', related_name="%(class)ss_related",
+                                                   verbose_name=_('suggested conferences'),
+                                                   blank=True, null=True)
+
+    class Meta(MetaCore):
+        abstract = True
+
+    @property
+    def visible_suggested_seminars(self):
+        return self.suggested_seminars.published()
+
+    def visible_suggested_conferences(self):
+        return self.suggested_conferences.published().filter(date_begin__gte=datetime.datetime.today())
+
+
+
 class WebclassMixin(Model):
     webclass                        = models.BooleanField(_('Web class'), default=False)
     webclass_max_participants       = models.IntegerField(_('Web class : nombre maxium de participants'), blank=True, null=True)
@@ -677,7 +697,7 @@ class WebclassMixin(Model):
     #         raise ValidationError("Dates are incorrect")
 
 
-class Conference(Displayable, WebclassMixin):
+class Conference(Displayable, WebclassMixin, SuggestionsMixin):
 
     sub_title       = models.CharField(_('sub title'), max_length=1024, blank=True)
     public_id       = models.CharField(_('public id'), max_length=255, blank=True)
@@ -713,12 +733,6 @@ class Conference(Displayable, WebclassMixin):
 
     notes           = generic.GenericRelation(Note)
 
-    suggested_seminars = models.ManyToManyField('Seminar', related_name="conference_suggested_seminars",
-                                                verbose_name=_('suggested seminars'),
-                                                blank=True, null=True)
-    suggested_conferences = models.ManyToManyField('Conference', related_name="conference_suggested_conferences",
-                                                   verbose_name=_('suggested conferences'),
-                                                   blank=True, null=True)
     additional_info         = tinymce.models.HTMLField(
                                     "Informations complémentaires", 
                                     help_text="Affiché sur la page formation du shop",
@@ -815,10 +829,6 @@ class Conference(Displayable, WebclassMixin):
         url = reverse('teleforma-conference-detail', kwargs={'pk':self.id})
         return "%s%s" % (settings.TELEFORMA_MASTER_HOST, url)
 
-    @property
-    def suggestions(self):
-        return (list(self.suggested_seminars.all()) + list(self.suggested_conferences.all()))[:3]
-
     def set_as_read(self, user):
         """ set as read for user """
         if user not in self.readers.all():
index ceb09c44179ee3fc12603424ced84d52150f59db..d15c8227542622f92406c92a289a2b50dd84156e 100644 (file)
@@ -56,7 +56,7 @@ class SeminarType(models.Model):
         verbose_name = _('Seminar type')
 
 
-class Seminar(ClonableMixin, Displayable):
+class Seminar(ClonableMixin, Displayable, SuggestionsMixin):
 
     # title, description, keywords, dates and status are given by Displayable
     # status values : 1: draft, 2: published
@@ -107,12 +107,6 @@ class Seminar(ClonableMixin, Displayable):
     date_added      = models.DateTimeField(_('date added'), auto_now_add=True)
     date_modified   = models.DateTimeField(_('date modified'), auto_now=True)
     date_forced     = models.DateTimeField(_('date forced'), null=True, blank=True)
-    suggested_seminars = models.ManyToManyField('Seminar', related_name="seminar_suggested_seminars",
-                                    verbose_name=_('suggested seminars'),
-                                    blank=True, null=True)
-    suggested_conferences = models.ManyToManyField('Conference', related_name="seminar_suggested_conferences",
-                                                verbose_name=_('suggested conferences'),
-                                                blank=True, null=True)
     additional_info           = tinymce.models.HTMLField(
                                     "Informations complémentaires", 
                                     help_text="Affiché sur la page formation du shop",