Added published status.

This commit is contained in:
2018-02-24 15:50:21 +01:00
parent 0f0dbbd34c
commit 37264f783a
6 changed files with 149 additions and 30 deletions

View File

@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import logging
import os
from django.apps import apps
@@ -121,19 +122,21 @@ class EventPermissionMixin(object):
if obj.accepted and (has_role(user, 'publish') or has_role(user, 'publish_incremental')):
return True
elif permission == 'accept':
if not obj.accepted:
if has_role(user, 'manage_all'):
return True
if has_role(user, 'manage_{}'.format(obj.sport.lower())):
return True
if has_role(user, 'manage_all'):
return True
if has_role(user, 'manage_{}'.format(obj.sport.lower())):
return True
elif permission == 'update':
if not obj.accepted:
if not obj.accepted and not obj.published:
if has_role(user, 'manage_all'):
return True
if has_role(user, 'manage_{}'.format(obj.sport.lower())):
return True
elif has_role(user, 'publish') or has_role(user, 'publish_incremental'):
return True
elif permission == 'publish':
if has_role(user, 'publish') or has_role(user, 'publish_incremental'):
return True
return False
@@ -156,6 +159,7 @@ class EventDetailView(EventPermissionMixin, generic.DetailView):
obj = context.get('event')
context['has_permission_accept'] = self.has_permission('accept', obj)
context['has_permission_update'] = self.has_permission('update', obj)
context['has_permission_publish'] = self.has_permission('publish', obj)
return context
@method_decorator(login_required)
@@ -173,6 +177,19 @@ class EventAcceptView(EventDetailView):
return HttpResponseRedirect(event.get_absolute_url())
class EventSetPublishedView(EventDetailView):
permission = 'publish'
def get(self, request, *args, **kwargs):
event = self.get_object()
if event.accepted:
event.set_published(request.user)
messages.success(request, _(u'Veröffentlichung registriert.'))
else:
messages.error(request, _(u'Veranstaltung ist noch nicht freigegeben.'))
return HttpResponseRedirect(event.get_absolute_url())
class EventUpdateView(EventPermissionMixin, generic.UpdateView):
permission = 'update'
model = models.Event
@@ -188,7 +205,8 @@ class EventUpdateView(EventPermissionMixin, generic.UpdateView):
context = super(EventUpdateView, self).get_context_data(**kwargs)
obj = context.get('event')
context['has_permission_accept'] = self.has_permission('accept', obj)
context['has_permission_update'] = True
context['has_permission_update'] = self.has_permission('update', obj)
context['has_permission_publish'] = self.has_permission('publish', obj)
return context
@method_decorator(login_required)