diff --git a/club/templates/club/club_tools.jinja b/club/templates/club/club_tools.jinja index 5207a315..e35c9bc2 100644 --- a/club/templates/club/club_tools.jinja +++ b/club/templates/club/club_tools.jinja @@ -11,6 +11,7 @@
  • {% trans %}Edit Trombi{% endtrans %}
  • {% else %}
  • {% trans %}New Trombi{% endtrans %}
  • +
  • {% trans %}Posters{% endtrans %}
  • {% endif %}

    {% trans %}Counters:{% endtrans %}

    diff --git a/club/urls.py b/club/urls.py index a4022b16..153b17a7 100644 --- a/club/urls.py +++ b/club/urls.py @@ -50,4 +50,7 @@ urlpatterns = [ url(r'^(?P[0-9]+)/mailing/delete$', MailingDeleteView.as_view(), name='mailing_delete'), url(r'^(?P[0-9]+)/mailing/delete/subscription$', MailingSubscriptionDeleteView.as_view(), name='mailing_subscription_delete'), url(r'^membership/(?P[0-9]+)/set_old$', MembershipSetOldView.as_view(), name='membership_set_old'), + url(r'^(?P[0-9]+)/poster$', PosterListView.as_view(), name='poster_list'), + url(r'^(?P[0-9]+)/poster/create$', PosterCreateView.as_view(), name='poster_create'), + url(r'^(?P[0-9]+)/poster/(?P[0-9]+)/edit$', PosterEditView.as_view(), name='poster_edit'), ] diff --git a/club/views.py b/club/views.py index 4841c56e..fa6ab2db 100644 --- a/club/views.py +++ b/club/views.py @@ -37,12 +37,13 @@ from ajax_select.fields import AutoCompleteSelectField from django.core.exceptions import PermissionDenied from django.shortcuts import get_object_or_404, redirect -from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, PageEditViewBase -from core.views.forms import SelectDate, SelectDateTime +from core.views import CanCreateMixin, CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, PageEditViewBase +from core.views.forms import SelectDate, SelectDateTime, PosterForm from club.models import Club, Membership, Mailing, MailingSubscription from sith.settings import SITH_MAXIMUM_FREE_ROLE from counter.models import Selling, Counter from core.models import User, PageRev +from com.models import Poster from django.conf import settings @@ -141,6 +142,11 @@ class ClubTabsMixin(TabedViewMixin): 'slug': 'mailing', 'name': _("Mailing list"), }) + tab_list.append({ + 'url': reverse('club:poster_list', kwargs={'club_id': self.object.id}), + 'slug': 'posters', + 'name': _("Posters list"), + }) if self.request.user.is_owner(self.object): tab_list.append({ 'url': reverse('club:club_prop', kwargs={'club_id': self.object.id}), @@ -592,3 +598,75 @@ class MailingAutoCleanView(View): def get(self, request, *args, **kwargs): self.mailing.subscriptions.all().delete() return redirect('club:mailing', club_id=self.mailing.club.id) + + +class PosterListView(CanViewMixin, ListView): + """List communication posters""" + current_tab = "posters" + model = Poster + template_name = 'core/poster_list.jinja' + + def dispatch(self, request, *args, **kwargs): + self.club = get_object_or_404(Club, pk=kwargs['club_id']) + return super(PosterListView, self).dispatch(request, *args, **kwargs) + + def get_queryset(self): + return Poster.objects.filter(club=self.club.id) + + def get_context_data(self, **kwargs): + kwargs = super(PosterListView, self).get_context_data(**kwargs) + kwargs['club'] = self.club + kwargs['app'] = "club" + kwargs['poster_create_url_name'] = "club:poster_create" + kwargs['poster_edit_url_name'] = "club:poster_edit" + kwargs['poster_list_url_name'] = "club:poster_list" + return kwargs + + +class PosterCreateView(CanCreateMixin, CreateView): + """Create communication poster""" + current_tab = "posters" + form_class = PosterForm + template_name = 'core/create.jinja' + success_url = reverse_lazy('club:poster_list') + + def dispatch(self, request, *args, **kwargs): + self.club = get_object_or_404(Club, pk=kwargs['club_id']) + self.request = request + return super(PosterCreateView, self).dispatch(request, *args, **kwargs) + + def get_initial(self): + initials = super(PosterCreateView, self).get_initial() + initials['user'] = self.request.user + + def get_context_data(self, **kwargs): + kwargs = super(PosterCreateView, self).get_context_data(**kwargs) + kwargs['club'] = self.club + kwargs['app'] = "club" + kwargs['poster_create_url_name'] = "club:poster_create" + kwargs['poster_edit_url_name'] = "club:poster_edit" + kwargs['poster_list_url_name'] = "club:poster_list" + return kwargs + +class PosterEditView(CanEditMixin, UpdateView): + """Edit communication poster""" + pk_url_kwarg = "poster_id" + current_tab = "posters" + form_class = PosterForm + template_name = 'core/poster_edit.jinja' + success_url = reverse_lazy('club:poster_list') + + def dispatch(self, request, *args, **kwargs): + self.club = get_object_or_404(Club, pk=kwargs['club_id']) + self.request = request + return super(PosterCreateView, self).dispatch(request, *args, **kwargs) + + def get_context_data(self, **kwargs): + kwargs = super(PosterEditView, self).get_context_data(**kwargs) + kwargs['club'] = self.club + kwargs['app'] = "club" + kwargs['poster_create_url_name'] = "club:poster_create" + kwargs['poster_edit_url_name'] = "club:poster_edit" + kwargs['poster_list_url_name'] = "club:poster_list" + return kwargs + diff --git a/com/models.py b/com/models.py index 26844330..e7796159 100644 --- a/com/models.py +++ b/com/models.py @@ -200,7 +200,7 @@ class Screen(models.Model): return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) def __str__(self): - return "%s: %s" % (self.club, self.name) + return "%s" % (self.name) class Poster(models.Model): name = models.CharField(_("name"), blank=False, null=False, max_length=128, default="") @@ -218,7 +218,7 @@ class Poster(models.Model): return super(Poster, self).save(*args, **kwargs) def is_owned_by(self, user): - return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) + return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or Club.objects.filter(id__in=user.get_clubs_with_rights()) def can_be_moderated_by(self, user): return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) diff --git a/com/views.py b/com/views.py index d891de8d..723a2036 100644 --- a/com/views.py +++ b/com/views.py @@ -42,7 +42,7 @@ from datetime import timedelta from com.models import Sith, News, NewsDate, Weekmail, WeekmailArticle, Screen, Poster from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin, QuickNotifMixin -from core.views.forms import SelectDateTime +from core.views.forms import SelectDateTime, PosterForm from core.models import Notification, RealGroup, User from club.models import Club, Mailing @@ -104,7 +104,7 @@ class ComTabsMixin(TabedViewMixin): class IsComAdminMixin(View): def dispatch(self, request, *args, **kwargs): - if not (request.user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or request.user.is_root): + if not (request.user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)): raise PermissionDenied return super(IsComAdminMixin, self).dispatch(request, *args, **kwargs) @@ -135,14 +135,6 @@ class IndexEditView(ComEditView): success_url = reverse_lazy('com:index_edit') -class ModerateListView(ListView): - """Generic view for moderation pages""" - - -class ModerateView(View): - """Generic view for moderation pages""" - - class WeekmailDestinationEditView(ComEditView): fields = ['weekmail_destinations'] current_tab = "weekmail_destinations" @@ -497,32 +489,52 @@ class PosterListView(IsComAdminMixin, ComTabsMixin, ListView): """List communication posters""" current_tab = "posters" model = Poster - template_name = 'com/poster_list.jinja' + template_name = 'core/poster_list.jinja' + queryset = Poster.objects.all().order_by('-date_begin') def get_context_data(self, **kwargs): kwargs = super(PosterListView, self).get_context_data(**kwargs) - kwargs['posters'] = Poster.objects.all().order_by('-date_begin') + kwargs['app'] = "com" + kwargs['poster_create_url_name'] = "com:poster_create" + kwargs['poster_edit_url_name'] = "com:poster_edit" + kwargs['poster_list_url_name'] = "com:poster_list" return kwargs class PosterCreateView(IsComAdminMixin, ComTabsMixin, CreateView): """Create communication poster""" current_tab = "posters" - model = Poster - fields = ['name', 'file', 'screens', 'date_begin', 'date_end'] + form_class = PosterForm template_name = 'core/create.jinja' success_url = reverse_lazy('com:poster_list') + def get_context_data(self, **kwargs): + kwargs = super(PosterEditView, self).get_context_data(**kwargs) + kwargs['app'] = "com" + kwargs['poster_create_url_name'] = "com:poster_create" + kwargs['poster_edit_url_name'] = "com:poster_edit" + kwargs['poster_list_url_name'] = "com:poster_list" + return kwargs + class PosterEditView(IsComAdminMixin, ComTabsMixin, UpdateView): """Edit communication poster""" pk_url_kwarg = "poster_id" current_tab = "posters" - model = Poster - fields = ['name', 'file', 'screens', 'date_begin', 'date_end'] - template_name = 'com/poster_edit.jinja' + form_class = PosterForm + template_name = 'core/poster_edit.jinja' success_url = reverse_lazy('com:poster_list') + def get_context_data(self, **kwargs): + kwargs = super(PosterEditView, self).get_context_data(**kwargs) + kwargs['app'] = "com" + kwargs['poster_create_url_name'] = "com:poster_create" + kwargs['poster_edit_url_name'] = "com:poster_edit" + kwargs['poster_list_url_name'] = "com:poster_list" + return kwargs + + def get_queryset(self): + return Poster.objects.all() class PosterDeleteView(IsComAdminMixin, ComTabsMixin, DeleteView): """Delete communication poster""" @@ -537,15 +549,20 @@ class PosterModerateListView(IsComAdminMixin, ComTabsMixin, ListView): """Moderate list communication poster""" current_tab = "posters" model = Poster - template_name = 'com/poster_moderate.jinja' + template_name = 'core/poster_moderate.jinja' + def get_context_data(self, **kwargs): kwargs = super(PosterModerateListView, self).get_context_data(**kwargs) kwargs['moderation_url'] = 'com:poster_moderate' kwargs['object_list'] = Poster.objects.filter(is_moderated=False).all() + kwargs['app'] = "com" + kwargs['poster_create_url_name'] = "com:poster_create" + kwargs['poster_edit_url_name'] = "com:poster_edit" + kwargs['poster_list_url_name'] = "com:poster_list" return kwargs -class PosterModerateView(IsComAdminMixin, ComTabsMixin, ModerateView): +class PosterModerateView(IsComAdminMixin, ComTabsMixin, View): """Moderate communication poster""" def get(self, request, *args, **kwargs): obj = get_object_or_404(Poster, pk=kwargs['object_id']) @@ -556,19 +573,36 @@ class PosterModerateView(IsComAdminMixin, ComTabsMixin, ModerateView): return redirect('com:poster_moderate_list') raise PermissionDenied + def get_context_data(self, **kwargs): + kwargs = super(PosterModerateListView, self).get_context_data(**kwargs) + kwargs['app'] = "com" + kwargs['poster_create_url_name'] = "com:poster_create" + kwargs['poster_edit_url_name'] = "com:poster_edit" + kwargs['poster_list_url_name'] = "com:poster_list" + return kwargs + class ScreenListView(IsComAdminMixin, ComTabsMixin, ListView): """List communication screens""" current_tab = "screens" model = Screen - template_name = 'com/screen_list.jinja' + template_name = 'core/screen_list.jinja' + + + def get_context_data(self, **kwargs): + kwargs = super(ScreenListView, self).get_context_data(**kwargs) + kwargs['app'] = "com" + kwargs['screen_create_url_name'] = "com:screen_create" + kwargs['screen_edit_url_name'] = "com:screen_edit" + kwargs['screen_list_url_name'] = "com:screen_list" + return kwargs class ScreenSlideshowView(DetailView): """Slideshow of actives posters""" pk_url_kwarg = "screen_id" model = Screen - template_name = 'com/screen_slideshow.jinja' + template_name = 'core/screen_slideshow.jinja' def get_context_data(self, **kwargs): kwargs = super(ScreenSlideshowView, self).get_context_data(**kwargs) @@ -580,21 +614,39 @@ class ScreenCreateView(IsComAdminMixin, ComTabsMixin, CreateView): """Create communication screen""" current_tab = "screens" model = Screen - fields = ['name', 'club'] + fields = ['name', ] template_name = 'core/create.jinja' success_url = reverse_lazy('com:screen_list') + def get_context_data(self, **kwargs): + kwargs = super(ScreenCreateView, self).get_context_data(**kwargs) + kwargs['app'] = "com" + kwargs['screen_create_url_name'] = "com:screen_create" + kwargs['screen_edit_url_name'] = "com:screen_edit" + kwargs['screen_list_url_name'] = "com:screen_list" + return kwargs + + class ScreenEditView(IsComAdminMixin, ComTabsMixin, UpdateView): """Edit communication screen""" pk_url_kwarg = "screen_id" current_tab = "screens" model = Screen - fields = ['name', 'club'] - template_name = 'com/screen_edit.jinja' + fields = ['name', ] + template_name = 'core/screen_edit.jinja' success_url = reverse_lazy('com:screen_list') + def get_context_data(self, **kwargs): + kwargs = super(ScreenEditView, self).get_context_data(**kwargs) + kwargs['app'] = "com" + kwargs['screen_create_url_name'] = "com:screen_create" + kwargs['screen_edit_url_name'] = "com:screen_edit" + kwargs['screen_list_url_name'] = "com:screen_list" + return kwargs + + class ScreenDeleteView(IsComAdminMixin, ComTabsMixin, DeleteView): """Delete communication screen""" pk_url_kwarg = "screen_id" diff --git a/core/models.py b/core/models.py index af5ae973..4e41c576 100644 --- a/core/models.py +++ b/core/models.py @@ -518,6 +518,9 @@ class User(AbstractBaseUser): infos.save() return infos + def get_clubs_with_rights(self): + return [m.club.id for m in self.memberships.filter(end_date__gte=timezone.now()).all() if m.club.has_rights_in_club(self)] + class AnonymousUser(AuthAnonymousUser): def __init__(self, request): diff --git a/com/templates/com/poster_edit.jinja b/core/templates/core/poster_edit.jinja similarity index 87% rename from com/templates/com/poster_edit.jinja rename to core/templates/core/poster_edit.jinja index 5b9cca1c..02f140f8 100644 --- a/com/templates/com/poster_edit.jinja +++ b/core/templates/core/poster_edit.jinja @@ -9,7 +9,7 @@

    {% trans %}Posters - edit{% endtrans %}