Verified Commit 4152b640 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Use events is_organiser

parent 22295bae
......@@ -5,9 +5,9 @@ from django.utils import timezone
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from pizzas import services
from .models import Order, PizzaEvent, Product
from events.models import Event
from events.services import is_organiser
@admin.register(Product)
......@@ -39,27 +39,27 @@ class OrderAdmin(admin.ModelAdmin):
list_display = ('pizza_event', 'member_name', 'product', 'paid')
def save_model(self, request, obj, form, change):
if not services.is_organiser(request.member, obj.pizza_event):
if not is_organiser(request.member, obj.pizza_event.event):
raise PermissionDenied
return super().save_model(request, obj, form, change)
def has_view_permission(self, request, order=None):
"""Only give view permission if the user is an organiser"""
if (order is not None and
not services.is_organiser(request.member, order.pizza_event)):
not is_organiser(request.member, order.pizza_event.event)):
return False
return super().has_view_permission(request, order)
def has_change_permission(self, request, order=None):
"""Only give change permission if the user is an organiser"""
if (order is not None and
not services.is_organiser(request.member, order.pizza_event)):
not is_organiser(request.member, order.pizza_event.event)):
return False
return super().has_change_permission(request, order)
def has_delete_permission(self, request, order=None):
"""Only give delete permission if the user is an organiser"""
if (order is not None and
not services.is_organiser(request.member, order.pizza_event)):
not is_organiser(request.member, order.pizza_event.event)):
return False
return super().has_delete_permission(request, order)
from events.services import is_organiser
from . models import Product, Order, PizzaEvent
......@@ -36,18 +37,6 @@ def gen_stats_current_pizza_orders():
return total
def is_organiser(member, pizza_event):
if member and member.is_authenticated:
if member.is_superuser or member.has_perm('events.override_organiser'):
return True
if pizza_event:
return member.get_member_groups().filter(
pk=pizza_event.event.organiser.pk).count() != 0
return False
def can_change_order(member, pizza_event):
return (member.has_perm('pizzas.change_order') and
is_organiser(member, pizza_event))
is_organiser(member, pizza_event.event))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment