# -*- coding: utf-8 -*- from django.contrib import messages from django.contrib.auth.decorators import login_required from django.core.exceptions import PermissionDenied from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404 from django.urls import reverse from django.utils.decorators import method_decorator from django.views import generic from dav_events.models import Participant from dav_events.views.events import EventListView as _EventListView, EventRegistrationsView as _EventRegistrationsView from dav_events.workflow import DefaultWorkflow class HomeView(generic.TemplateView): template_name = 'dav_event_office/home.html' class EventListView(_EventListView): template_name = 'dav_event_office/event_list.html' @method_decorator(login_required) def dispatch(self, request, *args, **kwargs): if not DefaultWorkflow.has_global_permission(request.user, 'payment'): raise PermissionDenied('payment') return super().dispatch(request, *args, **kwargs) class EventDetailView(_EventRegistrationsView): template_name = 'dav_event_office/event_detail.html' @method_decorator(login_required) def dispatch(self, request, *args, **kwargs): if not DefaultWorkflow.has_global_permission(request.user, 'payment'): raise PermissionDenied('payment') return super().dispatch(request, *args, **kwargs) class ParticipantListView(generic.ListView): model = Participant template_name = 'dav_event_office/participant_list.html' def post(self, request, *args, **kwargs): action = request.POST.get('action') if action == 'confirm_payment': participant_id = request.POST.get('id') participant = get_object_or_404(Participant, pk=participant_id) participant.paid = True participant.save() elif action == 'revoke_payment': participant_id = request.POST.get('id') participant = get_object_or_404(Participant, pk=participant_id) participant.paid = False participant.save() elif action == 'toggle_reduced_fee': participant_id = request.POST.get('id') participant = get_object_or_404(Participant, pk=participant_id) participant.apply_reduced_fee = not participant.apply_reduced_fee participant.save() else: messages.error(request, 'unsupported action: {}'.format(action)) return HttpResponseRedirect(reverse('dav_event_office:participant-list')) @method_decorator(login_required) def dispatch(self, request, *args, **kwargs): if not DefaultWorkflow.has_global_permission(request.user, 'payment'): raise PermissionDenied('payment') return super().dispatch(request, *args, **kwargs)