]> git.parisson.com Git - teleforma.git/commitdiff
Merge branch 'prodev' of git.parisson.com:git/teleforma into prodev
authorYoan Le Clanche <yoanl@pilotsystems.net>
Mon, 21 Dec 2020 14:40:25 +0000 (15:40 +0100)
committerYoan Le Clanche <yoanl@pilotsystems.net>
Mon, 21 Dec 2020 14:40:25 +0000 (15:40 +0100)
1  2 
teleforma/models/core.py
teleforma/models/pro.py

index 4c6542f3af81980c4858e784502592f8f509d88d,9428d1e566e43cf270214e7f3f897b1b7b062f29..a9d4ab63f0f2a53d2a4361bef73237f9e936c85e
@@@ -530,24 -530,39 +530,58 @@@ 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 ProductCodeMixin(Model):
+     product_code = models.CharField("Code produit", max_length=8, blank=True, null=True)
+     class Meta(MetaCore):
+         abstract = True
+     def save(self, **kwargs):
+         # generate a new code if code does not exists
+         if not self.product_code:
+             prefix = ""
+             klass = None
+             current = None
+             if self.__class__.__name__ == 'Seminar':
+                 prefix = "SEMI"
+                 from teleforma.models.pro import Seminar
+                 klass = Seminar
+             elif self.__class__.__name__ == 'Conference':
+                 prefix = "CONF"
+                 klass = Conference
+             else:
+                 raise NotImplemented
+             if klass:
+                 sorted_objs = klass.objects.filter(product_code__isnull=False).order_by('-product_code')
+                 if sorted_objs.count():
+                     current = sorted_objs[0].product_code
+             if current:
+                 new_code = int(current[4:]) + 1
+             else:
+                 new_code = 1
+             new_code = str(new_code)
+             code = prefix + new_code.zfill(4)
+             self.product_code = code
+         super(ProductCodeMixin, self).save(**kwargs)
  
  
  class WebclassMixin(Model):
      #         raise ValidationError("Dates are incorrect")
  
  
- class Conference(Displayable, WebclassMixin, SuggestionsMixin):
 -class Conference(Displayable, ProductCodeMixin, WebclassMixin):
++class Conference(Displayable, WebclassMixin, ProductCodeMixin, SuggestionsMixin):
 +
      sub_title       = models.CharField(_('sub title'), max_length=1024, blank=True)
      public_id       = models.CharField(_('public id'), max_length=255, blank=True)
      department      = models.ForeignKey('Department', related_name='conference', verbose_name=_('department'),
index d15c8227542622f92406c92a289a2b50dd84156e,b2ea302503e5a3cf00bffbe19af68071bf05c455..af5f5844109747827d0f2bff48de200f015f76e6
@@@ -56,7 -56,7 +56,7 @@@ class SeminarType(models.Model)
          verbose_name = _('Seminar type')
  
  
- class Seminar(ClonableMixin, Displayable, SuggestionsMixin):
 -class Seminar(ClonableMixin, Displayable, ProductCodeMixin):
++class Seminar(ClonableMixin, Displayable, ProductCodeMixin, SuggestionsMixin):
  
      # title, description, keywords, dates and status are given by Displayable
      # status values : 1: draft, 2: published