mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 02:54:20 +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)
|
moderator = models.ForeignKey(User, related_name="moderated_posters", verbose_name=_("moderator"), null=True, blank=True)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
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:
|
if not self.is_moderated:
|
||||||
for u in RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID).first().users.all():
|
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"),
|
Notification(user=u, url=reverse("com:poster_moderate_list"),
|
||||||
type="POSTER_MODERATION").save()
|
type="POSTER_MODERATION").save()
|
||||||
return super(Poster, self).save(*args, **kwargs)
|
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):
|
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)
|
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()
|
'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):
|
def __init__(self, *args, **kwargs):
|
||||||
self.user = kwargs.pop('user', None)
|
self.user = kwargs.pop('user', None)
|
||||||
super(PosterForm, self).__init__(*args, **kwargs)
|
super(PosterForm, self).__init__(*args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user