diff --git a/com/models.py b/com/models.py index 3069f8bd..b74e7904 100644 --- a/com/models.py +++ b/com/models.py @@ -217,14 +217,16 @@ class Poster(models.Model): moderator = models.ForeignKey(User, related_name="moderated_posters", verbose_name=_("moderator"), null=True, blank=True) def save(self, *args, **kwargs): - if self.date_end and self.date_begin > self.date_end: - raise ValidationError(_("Begin date should be before end date")) if not self.is_moderated: for u in RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID).first().users.all(): Notification(user=u, url=reverse("com:poster_moderate_list"), type="POSTER_MODERATION").save() return super(Poster, self).save(*args, **kwargs) + def clean(self, *args, **kwargs): + if self.date_end and self.date_begin > self.date_end: + raise ValidationError(_("Begin date should be before end date")) + def is_owned_by(self, user): return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or Club.objects.filter(id__in=user.clubs_with_rights) diff --git a/com/views.py b/com/views.py index dc8c1384..a8d906cc 100644 --- a/com/views.py +++ b/com/views.py @@ -61,6 +61,11 @@ class PosterForm(forms.ModelForm): 'is_moderated': forms.HiddenInput() } + date_begin = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("Start date"), + widget=SelectDateTime, required=True, initial=timezone.now().strftime("%Y-%m-%d %H:%M:%S")) + date_end = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("End date"), + widget=SelectDateTime, required=False) + def __init__(self, *args, **kwargs): self.user = kwargs.pop('user', None) super(PosterForm, self).__init__(*args, **kwargs)