Verified Commit 72d2862e authored by Sli's avatar Sli
Browse files

Posters now working + notifications for com admin

parent cc99ceca
Pipeline #1440 passed with stage
in 8 minutes and 18 seconds
......@@ -88,8 +88,9 @@ class MailingSubscriptionForm(forms.ModelForm):
class ClubTabsMixin(TabedViewMixin):
def get_tabs_title(self):
if isinstance(self.object, PageRev):
self.object =
obj = self.get_object()
if isinstance(obj, PageRev):
self.object =
return self.object.get_display_name()
def get_list_of_tabs(self):
......@@ -601,7 +602,7 @@ class MailingAutoCleanView(View):
return redirect('club:mailing',
class PosterListView(PosterListBaseView, ClubTabsMixin, CanViewMixin):
class PosterListView(PosterListBaseView, CanViewMixin, ClubTabsMixin):
"""List communication posters"""
def get_object(self):
......@@ -610,6 +611,7 @@ class PosterListView(PosterListBaseView, ClubTabsMixin, CanViewMixin):
def get_context_data(self, **kwargs):
kwargs = super(PosterListView, self).get_context_data(**kwargs)
kwargs['app'] = "club"
kwargs['current_tab'] = self.current_tab
kwargs['tabs_title'] = self.get_tabs_title()
kwargs['list_of_tabs'] = self.get_list_of_tabs()
return kwargs
......@@ -618,20 +620,24 @@ class PosterListView(PosterListBaseView, ClubTabsMixin, CanViewMixin):
class PosterCreateView(PosterCreateBaseView, CanCreateMixin):
"""Create communication poster"""
def get_success_url(self, **kwargs):
return reverse_lazy('club:poster_list', kwargs={'club_id':});
pk_url_kwarg = "club_id"
def get_context_data(self, **kwargs):
kwargs = super(PosterCreateView, self).get_context_data(**kwargs)
kwargs['app'] = "club"
return kwargs
def get_object(self):
obj = super(PosterCreateView, self).get_object()
if not obj:
return obj
def get_success_url(self, **kwargs):
return reverse_lazy('club:poster_list', kwargs={'club_id':})
class PosterEditView(ClubTabsMixin, PosterEditBaseView, CanEditMixin):
"""Edit communication poster"""
def get_success_url(self):
return reverse_lazy('club:poster_list', kwargs={'club_id':});
return reverse_lazy('club:poster_list', kwargs={'club_id':})
def get_context_data(self, **kwargs):
kwargs = super(PosterEditView, self).get_context_data(**kwargs)
......@@ -643,5 +649,5 @@ class PosterDeleteView(PosterDeleteBaseView, ClubTabsMixin, CanEditMixin):
"""Delete communication poster"""
def get_success_url(self):
return reverse_lazy('club:poster_list', kwargs={'club_id':});
return reverse_lazy('club:poster_list', kwargs={'club_id':})
......@@ -2,6 +2,7 @@
# Copyright 2016,2017
# - Skia <>
# - Sli <>
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
......@@ -31,6 +32,7 @@ from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.core.mail import EmailMultiAlternatives
from django.core.exceptions import ValidationError
from django.utils import timezone
......@@ -194,7 +196,7 @@ class Screen(models.Model):
def active_posters(self):
now =
return self.posters.filter(is_moderated=True, date_begin__lte=now).filter(Q(date_end__isnull=True)|Q(date_end__gte=now))
return self.posters.filter(is_moderated=True, date_begin__lte=now).filter(Q(date_end__isnull=True) | Q(date_end__gte=now))
def is_owned_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
......@@ -202,6 +204,7 @@ class Screen(models.Model):
def __str__(self):
return "%s" % (
class Poster(models.Model):
name = models.CharField(_("name"), blank=False, null=False, max_length=128, default="")
file = models.ImageField(_("file"), null=False, upload_to="com/posters")
......@@ -215,7 +218,11 @@ class Poster(models.Model):
def save(self, *args, **kwargs):
if self.date_end and self.date_begin > self.date_end:
raise ValidationError
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"),
return super(Poster, self).save(*args, **kwargs)
def is_owned_by(self, user):
......@@ -224,5 +231,12 @@ class Poster(models.Model):
def can_be_moderated_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
def get_display_name(self):
def page(self):
def __str__(self):
......@@ -538,11 +538,9 @@ class PosterCreateBaseView(CreateView):
return Poster.objects.all()
def dispatch(self, request, *args, **kwargs):
if 'club_id' in kwargs and kwargs['club_id']:
try: = Club.objects.get(pk=kwargs['club_id'])
except Club.DoesNotExist:
raise PermissionDenied
if 'club_id' in kwargs: = get_object_or_404(Club, pk=kwargs['club_id'])
return super(PosterCreateBaseView, self).dispatch(request, *args, **kwargs)
def get_form_kwargs(self):
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0027_gift'),
operations = [
field=models.CharField(default='GENERIC', verbose_name='type', max_length=32, choices=[('POSTER_MODERATION', 'A new poster needs to be moderated'), ('MAILING_MODERATION', 'A new mailing list needs to be moderated'), ('NEWS_MODERATION', 'There are %s fresh news to be moderated'), ('FILE_MODERATION', 'New files to be moderated'), ('SAS_MODERATION', 'There are %s pictures to be moderated in the SAS'), ('NEW_PICTURES', "You've been identified on some pictures"), ('REFILLING', 'You just refilled of %s €'), ('SELLING', 'You just bought %s'), ('GENERIC', 'You have a notification')]),
......@@ -562,6 +562,7 @@ SITH_LAUNDERETTE_PRICES = {
('POSTER_MODERATION', _("A new poster needs to be moderated")),
('MAILING_MODERATION', _("A new mailing list needs to be moderated")),
('NEWS_MODERATION', _("There are %s fresh news to be moderated")),
('FILE_MODERATION', _("New files to be moderated")),
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