Fix datetime forms for posters

This commit is contained in:
Antoine Bartuccio 2017-12-22 12:53:43 +01:00
parent c014a6e379
commit 43b4579a98
Signed by: klmp200
GPG Key ID: E7245548C53F904B
2 changed files with 9 additions and 2 deletions

View File

@ -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)

View File

@ -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)