mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
Fix datetime forms for posters
This commit is contained in:
parent
c014a6e379
commit
43b4579a98
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user