mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Delete function + club tabs
This commit is contained in:
parent
88d68ea510
commit
91d3e9e4dc
@ -53,4 +53,5 @@ urlpatterns = [
|
|||||||
url(r'^(?P<club_id>[0-9]+)/poster$', PosterListView.as_view(), name='poster_list'),
|
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/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'),
|
url(r'^(?P<club_id>[0-9]+)/poster/(?P<poster_id>[0-9]+)/edit$', PosterEditView.as_view(), name='poster_edit'),
|
||||||
|
url(r'^(?P<club_id>[0-9]+)/poster/(?P<poster_id>[0-9]+)/delete$', PosterDeleteView.as_view(), name='poster_delete'),
|
||||||
]
|
]
|
||||||
|
@ -43,7 +43,7 @@ from club.models import Club, Membership, Mailing, MailingSubscription
|
|||||||
from sith.settings import SITH_MAXIMUM_FREE_ROLE
|
from sith.settings import SITH_MAXIMUM_FREE_ROLE
|
||||||
from counter.models import Selling, Counter
|
from counter.models import Selling, Counter
|
||||||
from core.models import User, PageRev
|
from core.models import User, PageRev
|
||||||
from com.views import PosterListBaseView, PosterCreateBaseView, PosterEditBaseView
|
from com.views import PosterListBaseView, PosterCreateBaseView, PosterEditBaseView, PosterDeleteBaseView
|
||||||
from com.models import Poster
|
from com.models import Poster
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -90,6 +90,8 @@ class ClubTabsMixin(TabedViewMixin):
|
|||||||
def get_tabs_title(self):
|
def get_tabs_title(self):
|
||||||
if isinstance(self.object, PageRev):
|
if isinstance(self.object, PageRev):
|
||||||
self.object = self.object.page.club
|
self.object = self.object.page.club
|
||||||
|
if isinstance(self.object, Poster):
|
||||||
|
self.object = self.club
|
||||||
return self.object.get_display_name()
|
return self.object.get_display_name()
|
||||||
|
|
||||||
def get_list_of_tabs(self):
|
def get_list_of_tabs(self):
|
||||||
@ -601,28 +603,31 @@ class MailingAutoCleanView(View):
|
|||||||
return redirect('club:mailing', club_id=self.mailing.club.id)
|
return redirect('club:mailing', club_id=self.mailing.club.id)
|
||||||
|
|
||||||
|
|
||||||
class PosterListView(CanViewMixin, PosterListBaseView):
|
class PosterListView(PosterListBaseView, CanViewMixin, ClubTabsMixin):
|
||||||
"""List communication posters"""
|
"""List communication posters"""
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super(PosterListView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(PosterListView, self).get_context_data(**kwargs)
|
kwargs = super(PosterListView, self).get_context_data(**kwargs)
|
||||||
kwargs['app'] = "club"
|
kwargs['app'] = "club"
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class PosterCreateView(CanCreateMixin, PosterCreateBaseView):
|
class PosterCreateView(PosterCreateBaseView, CanCreateMixin):
|
||||||
"""Create communication poster"""
|
"""Create communication poster"""
|
||||||
|
|
||||||
def get_success_url(self, **kwargs):
|
def get_success_url(self, **kwargs):
|
||||||
return reverse_lazy('club:poster_list', kwargs={'club_id': self.club.id});
|
return reverse_lazy('club:poster_list', kwargs={'club_id': self.club.id});
|
||||||
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(PosterCreateView, self).get_context_data(**kwargs)
|
kwargs = super(PosterCreateView, self).get_context_data(**kwargs)
|
||||||
kwargs['app'] = "club"
|
kwargs['app'] = "club"
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
class PosterEditView(CanEditMixin, PosterEditBaseView):
|
|
||||||
|
class PosterEditView(ClubTabsMixin, PosterEditBaseView, CanEditMixin):
|
||||||
"""Edit communication poster"""
|
"""Edit communication poster"""
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
@ -633,3 +638,10 @@ class PosterEditView(CanEditMixin, PosterEditBaseView):
|
|||||||
kwargs['app'] = "club"
|
kwargs['app'] = "club"
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
|
class PosterDeleteView(PosterDeleteBaseView, ClubTabsMixin, CanEditMixin):
|
||||||
|
"""Delete communication poster"""
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse_lazy('club:poster_list', kwargs={'club_id': self.club.id});
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ class Poster(models.Model):
|
|||||||
return super(Poster, self).save(*args, **kwargs)
|
return super(Poster, self).save(*args, **kwargs)
|
||||||
|
|
||||||
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.get_clubs_with_rights())
|
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or Club.objects.filter(id__in=user.clubs_with_rights)
|
||||||
|
|
||||||
def can_be_moderated_by(self, user):
|
def can_be_moderated_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)
|
||||||
|
@ -17,7 +17,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<h3>{% trans %}Posters - edit{% endtrans %}</h3>
|
<h3>{% trans %}Posters - edit{% endtrans %}</h3>
|
||||||
<div id="links" class="right">
|
<div id="links" class="right">
|
||||||
<a class="link delete" href="{{ url("com:poster_delete", poster.id) }}">{% trans %}Delete{% endtrans %}</a>
|
{% if app == "com" %}
|
||||||
|
<a class="link delete" href="{{ url(app + ":poster_delete", poster.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||||
|
{% elif app == "club" %}
|
||||||
|
<a class="link delete" href="{{ url(app + ":poster_delete", club.id, poster.id) }}">{% trans %}Delete{% endtrans %}</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
71
com/views.py
71
com/views.py
@ -62,13 +62,11 @@ class PosterForm(forms.ModelForm):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
user = kwargs.pop('user', None)
|
self.user = kwargs.pop('user', None)
|
||||||
super(PosterForm, self).__init__(*args, **kwargs)
|
super(PosterForm, self).__init__(*args, **kwargs)
|
||||||
if user:
|
if self.user:
|
||||||
if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID):
|
if not self.user.is_com_admin:
|
||||||
self.fields['club'].queryset = Club.objects.all()
|
self.fields['club'].queryset = Club.objects.filter(id__in=self.user.clubs_with_rights)
|
||||||
else:
|
|
||||||
self.fields['club'].queryset = Club.objects.filter(id__in=user.get_clubs_with_rights()).all()
|
|
||||||
|
|
||||||
|
|
||||||
class ComTabsMixin(TabedViewMixin):
|
class ComTabsMixin(TabedViewMixin):
|
||||||
@ -511,22 +509,20 @@ class PosterListBaseView(ListView):
|
|||||||
template_name = 'com/poster_list.jinja'
|
template_name = 'com/poster_list.jinja'
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
self.club = None
|
club_id = kwargs.pop('club_id', None)
|
||||||
if 'club_id' in kwargs and kwargs['club_id']:
|
if club_id:
|
||||||
try:
|
self.club = get_object_or_404(Club, pk=club_id)
|
||||||
self.club = Club.objects.get(pk=kwargs['club_id'])
|
|
||||||
except Club.DoesNotExist:
|
|
||||||
pass
|
|
||||||
return super(PosterListBaseView, self).dispatch(request, *args, **kwargs)
|
return super(PosterListBaseView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
if 'club' in self.__dict__ and self.club:
|
if self.request.user.is_com_admin:
|
||||||
return Poster.objects.filter(club=self.club.id)
|
|
||||||
else:
|
|
||||||
return Poster.objects.all().order_by('-date_begin')
|
return Poster.objects.all().order_by('-date_begin')
|
||||||
|
else:
|
||||||
|
return Poster.objects.filter(club=self.club.id)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(PosterListBaseView, self).get_context_data(**kwargs)
|
kwargs = super(PosterListBaseView, self).get_context_data(**kwargs)
|
||||||
|
if not self.request.user.is_com_admin:
|
||||||
kwargs['club'] = self.club
|
kwargs['club'] = self.club
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
@ -541,21 +537,26 @@ class PosterCreateBaseView(CreateView):
|
|||||||
return Poster.objects.all()
|
return Poster.objects.all()
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
self.club = None
|
|
||||||
if 'club_id' in kwargs and kwargs['club_id']:
|
if 'club_id' in kwargs and kwargs['club_id']:
|
||||||
try:
|
try:
|
||||||
self.club = Club.objects.get(pk=kwargs['club_id'])
|
self.club = Club.objects.get(pk=kwargs['club_id'])
|
||||||
except Club.DoesNotExist:
|
except Club.DoesNotExist:
|
||||||
pass
|
raise PermissionDenied
|
||||||
return super(PosterCreateBaseView, self).dispatch(request, *args, **kwargs)
|
return super(PosterCreateBaseView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super(PosterCreateBaseView, self).get_form_kwargs()
|
||||||
|
kwargs.update({'user': self.request.user})
|
||||||
|
return kwargs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(PosterCreateBaseView, self).get_context_data(**kwargs)
|
kwargs = super(PosterCreateBaseView, self).get_context_data(**kwargs)
|
||||||
|
if not self.request.user.is_com_admin:
|
||||||
kwargs['club'] = self.club
|
kwargs['club'] = self.club
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
if not('club' in self.__dict__ and self.club):
|
if self.request.user.is_com_admin:
|
||||||
form.instance.is_moderated = True
|
form.instance.is_moderated = True
|
||||||
return super(PosterCreateBaseView, self).form_valid(form)
|
return super(PosterCreateBaseView, self).form_valid(form)
|
||||||
|
|
||||||
@ -568,19 +569,24 @@ class PosterEditBaseView(UpdateView):
|
|||||||
template_name = 'com/poster_edit.jinja'
|
template_name = 'com/poster_edit.jinja'
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
self.club = None
|
|
||||||
if 'club_id' in kwargs and kwargs['club_id']:
|
if 'club_id' in kwargs and kwargs['club_id']:
|
||||||
try:
|
try:
|
||||||
self.club = Club.objects.get(pk=kwargs['club_id'])
|
self.club = Club.objects.get(pk=kwargs['club_id'])
|
||||||
except Club.DoesNotExist:
|
except Club.DoesNotExist:
|
||||||
pass
|
raise PermissionDenied
|
||||||
return super(PosterEditBaseView, self).dispatch(request, *args, **kwargs)
|
return super(PosterEditBaseView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Poster.objects.all()
|
return Poster.objects.all()
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super(PosterEditBaseView, self).get_form_kwargs()
|
||||||
|
kwargs.update({'user': self.request.user})
|
||||||
|
return kwargs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(PosterEditBaseView, self).get_context_data(**kwargs)
|
kwargs = super(PosterEditBaseView, self).get_context_data(**kwargs)
|
||||||
|
if not self.request.user.is_com_admin:
|
||||||
kwargs['club'] = self.club
|
kwargs['club'] = self.club
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
@ -590,11 +596,24 @@ class PosterEditBaseView(UpdateView):
|
|||||||
return super(PosterEditBaseView, self).form_valid(form)
|
return super(PosterEditBaseView, self).form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class PosterListView(IsComAdminMixin, ComTabsMixin, PosterListBaseView):
|
class PosterDeleteBaseView(DeleteView):
|
||||||
"""List communication posters"""
|
"""Edit communication poster"""
|
||||||
|
pk_url_kwarg = "poster_id"
|
||||||
current_tab = "posters"
|
current_tab = "posters"
|
||||||
model = Poster
|
model = Poster
|
||||||
template_name = 'com/poster_list.jinja'
|
template_name = 'core/delete_confirm.jinja'
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
if 'club_id' in kwargs and kwargs['club_id']:
|
||||||
|
try:
|
||||||
|
self.club = Club.objects.get(pk=kwargs['club_id'])
|
||||||
|
except Club.DoesNotExist:
|
||||||
|
raise PermissionDenied
|
||||||
|
return super(PosterDeleteBaseView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class PosterListView(IsComAdminMixin, ComTabsMixin, PosterListBaseView):
|
||||||
|
"""List communication posters"""
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(PosterListView, self).get_context_data(**kwargs)
|
kwargs = super(PosterListView, self).get_context_data(**kwargs)
|
||||||
@ -622,12 +641,8 @@ class PosterEditView(IsComAdminMixin, ComTabsMixin, PosterEditBaseView):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class PosterDeleteView(IsComAdminMixin, ComTabsMixin, DeleteView):
|
class PosterDeleteView(IsComAdminMixin, ComTabsMixin, PosterDeleteBaseView):
|
||||||
"""Delete communication poster"""
|
"""Delete communication poster"""
|
||||||
pk_url_kwarg = "poster_id"
|
|
||||||
current_tab = "posters"
|
|
||||||
model = Poster
|
|
||||||
template_name = 'core/delete_confirm.jinja'
|
|
||||||
success_url = reverse_lazy('com:poster_list')
|
success_url = reverse_lazy('com:poster_list')
|
||||||
|
|
||||||
|
|
||||||
|
@ -518,9 +518,14 @@ class User(AbstractBaseUser):
|
|||||||
infos.save()
|
infos.save()
|
||||||
return infos
|
return infos
|
||||||
|
|
||||||
def get_clubs_with_rights(self):
|
@cached_property
|
||||||
|
def clubs_with_rights(self):
|
||||||
return [m.club.id for m in self.memberships.filter(models.Q(end_date__isnull=True) | models.Q(end_date__gte=timezone.now())).all() if m.club.has_rights_in_club(self)]
|
return [m.club.id for m in self.memberships.filter(models.Q(end_date__isnull=True) | models.Q(end_date__gte=timezone.now())).all() if m.club.has_rights_in_club(self)]
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def is_com_admin(self):
|
||||||
|
return self.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
|
||||||
|
|
||||||
|
|
||||||
class AnonymousUser(AuthAnonymousUser):
|
class AnonymousUser(AuthAnonymousUser):
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
|
@ -169,6 +169,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
|
{{ object }}
|
||||||
{% if list_of_tabs %}
|
{% if list_of_tabs %}
|
||||||
<div class="tool_bar">
|
<div class="tool_bar">
|
||||||
<div>{{ tabs_title }}</div>
|
<div>{{ tabs_title }}</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user