Verified Commit 43b4579a authored by Sli's avatar Sli
Browse files

Fix datetime forms for posters

parent c014a6e3
Pipeline #1448 passed with stage
in 6 minutes
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment