Commit 80bffd00 authored by Sli's avatar Sli

Merge branch 'bugfix' into 'master'

Bugfix for mailing list and posters

See merge request !141
parents 10dfb2c1 43b4579a
Pipeline #1449 passed with stage
in 7 minutes and 43 seconds
......@@ -296,6 +296,9 @@ class Mailing(models.Model):
def can_view(self, user):
return self.club.has_rights_in_club(user)
def can_be_edited_by(self, user):
return self.club.has_rights_in_club(user)
def delete(self):
for sub in self.subscriptions.all():
sub.delete()
......
......@@ -509,6 +509,9 @@ class ClubMailingView(ClubTabsMixin, ListView):
kwargs['has_objects'] = len(kwargs['object_list']) > 0
return kwargs
def get_object(self):
return self.club
class MailingGenericCreateView(CreateView, SingleObjectMixin):
"""
......
......@@ -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)
......
This diff is collapsed.
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