Added primitive Update Event feature.
This commit is contained in:
@@ -61,7 +61,7 @@ class EventPermissionMixin(object):
|
||||
group_name = getattr(config, group_name_var, None)
|
||||
if group_name and user.groups.filter(name=group_name).count():
|
||||
return True
|
||||
elif permission in ('edit', 'accept'):
|
||||
elif permission in ('update', 'accept'):
|
||||
if user.groups.filter(name=config.MANAGE_ALL_GROUP).count():
|
||||
return True
|
||||
group_name_var = 'MANAGE_{}_GROUP'.format(obj.sport)
|
||||
@@ -74,7 +74,7 @@ class EventPermissionMixin(object):
|
||||
def enforce_permission(self, obj):
|
||||
permission = self.permission
|
||||
if not self.has_permission(permission, obj):
|
||||
raise PermissionDenied()
|
||||
raise PermissionDenied(permission)
|
||||
|
||||
|
||||
class EventDetailView(EventPermissionMixin, generic.DetailView):
|
||||
@@ -89,7 +89,7 @@ class EventDetailView(EventPermissionMixin, generic.DetailView):
|
||||
context = super(EventDetailView, self).get_context_data(**kwargs)
|
||||
obj = context.get('event')
|
||||
context['has_permission_accept'] = self.has_permission('accept', obj)
|
||||
context['has_permission_edit'] = self.has_permission('edit', obj)
|
||||
context['has_permission_update'] = self.has_permission('update', obj)
|
||||
return context
|
||||
|
||||
@method_decorator(login_required)
|
||||
@@ -110,6 +110,31 @@ class EventAcceptView(EventDetailView):
|
||||
return super(EventAcceptView, self).get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class EventUpdateView(EventPermissionMixin, generic.UpdateView):
|
||||
permission = 'update'
|
||||
model = models.Event
|
||||
form_class = forms.events.EventUpdateForm
|
||||
template_name_suffix = '_update_form'
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
obj = super(EventUpdateView, self).get_object(queryset=queryset)
|
||||
self.enforce_permission(obj)
|
||||
if obj.accepted:
|
||||
raise PermissionDenied('accepted')
|
||||
return obj
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
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
|
||||
return context
|
||||
|
||||
@method_decorator(login_required)
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super(EventUpdateView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
class EventCreateView(generic.FormView):
|
||||
form_class = forms.events.EventCreateForm
|
||||
template_dir = os.path.join('dav_events', 'event_create')
|
||||
|
||||
Reference in New Issue
Block a user