Club views and discussions fixes

This commit is contained in:
gnikwo 2017-11-01 18:12:33 +01:00
parent 693c3ed27e
commit 21b24f2891
No known key found for this signature in database
GPG Key ID: 7498D7DF2F867695
14 changed files with 182 additions and 42 deletions

View File

@ -11,6 +11,7 @@
<li> <a href="{{ url('trombi:detail', trombi_id=object.trombi.id) }}">{% trans %}Edit Trombi{% endtrans %}</a></li>
{% else %}
<li> <a href="{{ url('trombi:create', club_id=object.id) }}">{% trans %}New Trombi{% endtrans %}</a></li>
<li> <a href="{{ url('club:poster_list', club_id=object.id) }}">{% trans %}Posters{% endtrans %}</a></li>
{% endif %}
</ul>
<h4>{% trans %}Counters:{% endtrans %}</h4>

View File

@ -50,4 +50,7 @@ urlpatterns = [
url(r'^(?P<mailing_id>[0-9]+)/mailing/delete$', MailingDeleteView.as_view(), name='mailing_delete'),
url(r'^(?P<mailing_subscription_id>[0-9]+)/mailing/delete/subscription$', MailingSubscriptionDeleteView.as_view(), name='mailing_subscription_delete'),
url(r'^membership/(?P<membership_id>[0-9]+)/set_old$', MembershipSetOldView.as_view(), name='membership_set_old'),
url(r'^(?P<club_id>[0-9]+)/poster$', PosterListView.as_view(), name='poster_list'),
url(r'^(?P<club_id>[0-9]+)/poster/create$', PosterCreateView.as_view(), name='poster_create'),
url(r'^(?P<club_id>[0-9]+)/poster/(?P<poster_id>[0-9]+)/edit$', PosterEditView.as_view(), name='poster_edit'),
]

View File

@ -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

View File

@ -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)

View File

@ -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"

View File

@ -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):

View File

@ -9,7 +9,7 @@
<div id="title">
<div id="links" class="left">
<a id="list" class="link" href="{{ url("com:poster_list") }}">{% trans %}List{% endtrans %}</a>
<a id="list" class="link" href="{{ url(poster_list_url_name) }}">{% trans %}List{% endtrans %}</a>
</div>
<h3>{% trans %}Posters - edit{% endtrans %}</h3>
<div id="links" class="right">

View File

@ -16,26 +16,28 @@
<div id="title">
<h3>{% trans %}Posters{% endtrans %}</h3>
<div id="links" class="right">
<a id="create" class="link" href="{{ url("com:poster_create") }}">{% trans %}Create{% endtrans %}</a>
<a id="moderation" class="link" href="{{ url("com:poster_moderate_list") }}">{% trans %}Moderation{% endtrans %}</a>
<a id="create" class="link" href="{{ url(poster_create_url_name) }}">{% trans %}Create{% endtrans %}</a>
{% if app == "com" %}
<a id="moderation" class="link" href="{{ url("com:poster_moderate_list") }}">{% trans %}Moderation{% endtrans %}</a>
{% endif %}
</div>
</div>
<div id="posters">
{% if posters.count() == 0 %}
{% if poster_list.count() == 0 %}
<div id="no-posters">{% trans %}No posters{% endtrans %}</div>
{% else %}
{% for poster in posters %}
{% for poster in poster_list %}
<div class="poster">
<div class="name">{{ poster.name }}</div>
<div class="image"><img src="{{ static(poster.file.url) }}"></img></div>
<div class="image"><img src="{{ poster.file.url }}"></img></div>
<div class="dates">
<div class="begin">{{ poster.date_begin | date("d/M/Y H:m") }}</div>
<div class="end">{{ poster.date_end | date("d/M/Y H:m") }}</div>
</div>
<a class="edit" href="{{ url("com:poster_edit", poster.id) }}">{% trans %}Edit{% endtrans %}</a>
<a class="edit" href="{{ url(poster_edit_url_name, poster.id) }}">{% trans %}Edit{% endtrans %}</a>
</div>
{% endfor %}

View File

@ -24,7 +24,7 @@
{% for poster in object_list %}
<div class="poster">
<div class="name"> {{ poster.name }} </div>
<div class="image"> <img src="{{ static(poster.file.url) }}"></img> </div>
<div class="image"> <img src="{{ poster.file.url }}"></img> </div>
<a class="moderate" href="{{ url(moderation_url, object_id=poster.id) }}">Moderate</a>
</div>
{% endfor %}

View File

@ -9,7 +9,7 @@
<div id="title">
<div id="links" class="left">
<a id="list" class="link" href="{{ url("com:poster_list") }}">{% trans %}List{% endtrans %}</a>
<a id="list" class="link" href="{{ url(screen_list_url_name) }}">{% trans %}List{% endtrans %}</a>
</div>
<h3>{% trans %}Screen - edit{% endtrans %}</h3>
<div id="links" class="right">

View File

@ -10,7 +10,7 @@
<div id="title">
<h3>{% trans %}Screens{% endtrans %}</h3>
<div id="links" class="right">
<a id="create" class="link" href="{{ url("com:screen_create") }}">{% trans %}Create{% endtrans %}</a>
<a id="create" class="link" href="{{ url(screen_create_url_name) }}">{% trans %}Create{% endtrans %}</a>
</div>
</div>
@ -23,8 +23,7 @@
{% for screen in screen_list %}
<div class="screen">
<div class="name">{{ screen.name }}</div>
<div class="club">Club: {{ screen.club }}</div>
<a class="edit" href="{{ url("com:screen_edit", screen.id) }}">{% trans %}Edit{% endtrans %}</a>
<a class="edit" href="{{ url(screen_edit_url_name, screen.id) }}">{% trans %}Edit{% endtrans %}</a>
<a class="slideshow" href="{{ url("com:screen_slideshow", screen.id) }}" target="_blank">{% trans %}Slideshow{% endtrans %}</a>
</div>
{% endfor %}

View File

@ -10,7 +10,7 @@
<div id="slides">
{% for poster in posters %}
<div class="slide {% if loop.first %}center{% else %}right{% endif %}">
<img src="{{ static(poster.file.url) }}"></img>
<img src="{{ poster.file.url }}"></img>
</div>
{% endfor %}
</div>

View File

@ -87,6 +87,8 @@
<li><a href="{{ url('com:info_edit') }}">{% trans %}Edit information message{% endtrans %}</a></li>
<li><a href="{{ url('core:file_moderation') }}">{% trans %}Moderate files{% endtrans %}</a></li>
<li><a href="{{ url('com:mailing_admin') }}">{% trans %}Mailing lists administration{% endtrans %}</a></li>
<li><a href="{{ url('com:poster_list') }}">{% trans %}Posters{% endtrans %}</a></li>
<li><a href="{{ url('com:screen_list') }}">{% trans %}Screens{% endtrans %}</a></li>
{% endif %}
{% if user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) %}
<li><a href="{{ url('sas:moderation') }}">{% trans %}Moderate pictures{% endtrans %}</a></li>

View File

@ -37,12 +37,12 @@ from ajax_select.fields import AutoCompleteSelectField
import re
from core.models import User, Page, SithFile, Gift
from com.models import Poster, Screen
from core.utils import resize_image
from io import BytesIO
from PIL import Image
# Widgets
class SelectSingle(Select):