From 3180ec457d93058e7d423c33306aff6efe6f22dc Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Sun, 3 Jun 2018 18:33:51 +0200 Subject: [PATCH] switch backoffice to use the regular CampViewMixin --- src/backoffice/mixins.py | 29 ++++----------- src/backoffice/templates/badge_handout.html | 2 +- .../templates/{camp_index.html => index.html} | 10 +++--- .../templates/manage_eventproposal.html | 4 +-- .../templates/manage_proposals.html | 4 +-- .../templates/manage_speakerproposal.html | 4 +-- src/backoffice/templates/product_handout.html | 2 +- src/backoffice/templates/ticket_checkin.html | 2 +- src/backoffice/urls.py | 21 +++++------ src/backoffice/views.py | 35 ++++--------------- src/bornhack/urls.py | 9 +++-- src/templates/base.html | 3 +- src/templates/includes/menuitems.html | 3 ++ 13 files changed, 44 insertions(+), 84 deletions(-) rename src/backoffice/templates/{camp_index.html => index.html} (71%) diff --git a/src/backoffice/mixins.py b/src/backoffice/mixins.py index 1cef5314..6ad36dfd 100644 --- a/src/backoffice/mixins.py +++ b/src/backoffice/mixins.py @@ -1,25 +1,10 @@ -from django.http import HttpResponseForbidden -from django.shortcuts import get_object_or_404 -from django.contrib import messages -from camps.models import Camp +from camps.mixins import CampViewMixin +from utils.mixins import StaffMemberRequiredMixin -class BackofficeViewMixin(object): - def dispatch(self, request, *args, **kwargs): - # only permit staff users - if not request.user.is_staff: - messages.error(request, "No thanks") - return HttpResponseForbidden() - - # get camp from url kwarg - self.bocamp = get_object_or_404(Camp, slug=kwargs['bocamp_slug']) - - # continue with the request - return super().dispatch(request, *args, **kwargs) - - def get_context_data(self, **kwargs): - """ Add Camp to template context """ - context = super().get_context_data(**kwargs) - context['bocamp'] = self.bocamp - return context +class BackofficeViewMixin(CampViewMixin, StaffMemberRequiredMixin): + """ + Mixin used by all backoffice views. For now just uses CampViewMixin and StaffMemberRequiredMixin. + """ + pass diff --git a/src/backoffice/templates/badge_handout.html b/src/backoffice/templates/badge_handout.html index 3954bd47..27d6be4f 100644 --- a/src/backoffice/templates/badge_handout.html +++ b/src/backoffice/templates/badge_handout.html @@ -10,7 +10,7 @@

Hand Out Badges

- Use this view to hand out badges to participants. Use the search field to search for username, email, products, order ID, ticket UUID, etc. To check in participants go to the Ticket Checkin view instead. To hand out merchandise and other products go to the Hand Out Products view instead. + Use this view to hand out badges to participants. Use the search field to search for username, email, products, order ID, ticket UUID, etc. To check in participants go to the Ticket Checkin view instead. To hand out merchandise and other products go to the Hand Out Products view instead.
This table shows all (Shop|Discount|Sponsor)Tickets which are badge_handed_out=False. Tickets must be checked in before they are shown in this list. diff --git a/src/backoffice/templates/camp_index.html b/src/backoffice/templates/index.html similarity index 71% rename from src/backoffice/templates/camp_index.html rename to src/backoffice/templates/index.html index 2afc6ff7..bc9710cc 100644 --- a/src/backoffice/templates/camp_index.html +++ b/src/backoffice/templates/index.html @@ -14,23 +14,23 @@

- +

Hand Out Products

Use this view to mark products such as merchandise, cabins, fridges and so on as handed out.

- +

Check-In Tickets

Use this view to check-in tickets when participants arrive.

- +

Hand Out Badges

Use this view to mark badges as handed out.

- +

Approve Public Credit Names

Use this view to check and approve users Public Credit Names

- +

Manage Proposals

Use this view to manage SpeakerProposals and EventProposals

diff --git a/src/backoffice/templates/manage_eventproposal.html b/src/backoffice/templates/manage_eventproposal.html index 47690152..4fcb51b7 100644 --- a/src/backoffice/templates/manage_eventproposal.html +++ b/src/backoffice/templates/manage_eventproposal.html @@ -3,13 +3,13 @@ {% block content %}

Manage {{ form.instance.event_type.name }} Proposal

-{% include 'includes/eventproposal_detail.html' with camp=bocamp %} +{% include 'includes/eventproposal_detail.html' with camp=camp %}
{% csrf_token %} {% bootstrap_form form %} {% bootstrap_button " Approve" button_type="submit" button_class="btn-success" name="approve" %} {% bootstrap_button " Reject" button_type="submit" button_class="btn-danger" name="reject" %} - Cancel + Cancel
{% endblock content %} diff --git a/src/backoffice/templates/manage_proposals.html b/src/backoffice/templates/manage_proposals.html index fbb81470..4c28b64d 100644 --- a/src/backoffice/templates/manage_proposals.html +++ b/src/backoffice/templates/manage_proposals.html @@ -35,7 +35,7 @@ {{ proposal.needs_oneday_ticket|truefalseicon }} {{ proposal.event|truefalseicon }} {{ proposal.user }} - Manage + Manage {% endfor %} @@ -63,7 +63,7 @@ {% for speaker in proposal.speakers.all %} {% endfor %} {{ proposal.speaker|truefalseicon }} {{ proposal.user }} - Manage + Manage {% endfor %} diff --git a/src/backoffice/templates/manage_speakerproposal.html b/src/backoffice/templates/manage_speakerproposal.html index 89f9e0a8..ab545463 100644 --- a/src/backoffice/templates/manage_speakerproposal.html +++ b/src/backoffice/templates/manage_speakerproposal.html @@ -3,13 +3,13 @@ {% block content %}

Manage Speaker Proposal

-{% include 'includes/speakerproposal_detail.html' with camp=bocamp %} +{% include 'includes/speakerproposal_detail.html' with camp=camp %}
{% csrf_token %} {% bootstrap_form form %} {% bootstrap_button " Approve" button_type="submit" button_class="btn-success" name="approve" %} {% bootstrap_button " Reject" button_type="submit" button_class="btn-danger" name="reject" %} - Cancel + Cancel
{% endblock content %} diff --git a/src/backoffice/templates/product_handout.html b/src/backoffice/templates/product_handout.html index 875c5a80..8496a8a5 100644 --- a/src/backoffice/templates/product_handout.html +++ b/src/backoffice/templates/product_handout.html @@ -10,7 +10,7 @@

Hand Out Products

- Use this view to hand out products to participants. Use the search field to search for username, email, products, order ID etc. To check in participants go to the Ticket Checkin view instead. To hand out badges go to the Badge Handout view instead. + Use this view to hand out products to participants. Use the search field to search for username, email, products, order ID etc. To check in participants go to the Ticket Checkin view instead. To hand out badges go to the Badge Handout view instead.
This table shows all OrderProductRelations which are handed_out=False (not including unpaid, cancelled and refunded orders). The table is initally sorted by order ID but the sorting can be changed by clicking the column headlines (if javascript is enabled). diff --git a/src/backoffice/templates/ticket_checkin.html b/src/backoffice/templates/ticket_checkin.html index 5f6cfc37..177f7c1b 100644 --- a/src/backoffice/templates/ticket_checkin.html +++ b/src/backoffice/templates/ticket_checkin.html @@ -10,7 +10,7 @@

Ticket Check-In

- Use this view to check in participants. Use the search field to search for username, email, products, order ID, ticket UUID, etc. To hand out badges go to the Badge Handout view instead. To hand out other products go to the Hand Out Products view instead. + Use this view to check in participants. Use the search field to search for username, email, products, order ID, ticket UUID, etc. To hand out badges go to the Badge Handout view instead. To hand out other products go to the Hand Out Products view instead.
This table shows all (Shop|Discount|Sponsor)Tickets which are checked_in=False. diff --git a/src/backoffice/urls.py b/src/backoffice/urls.py index 2361a240..58da109d 100644 --- a/src/backoffice/urls.py +++ b/src/backoffice/urls.py @@ -5,18 +5,15 @@ from .views import * app_name = 'backoffice' urlpatterns = [ - path('', CampSelectView.as_view(), name='camp_select'), - path('/', include([ - path('', CampIndexView.as_view(), name='camp_index'), - path('product_handout/', ProductHandoutView.as_view(), name='product_handout'), - path('badge_handout/', BadgeHandoutView.as_view(), name='badge_handout'), - path('ticket_checkin/', TicketCheckinView.as_view(), name='ticket_checkin'), - path('public_credit_names/', ApproveNamesView.as_view(), name='public_credit_names'), - path('manage_proposals/', include([ - path('', ManageProposalsView.as_view(), name='manage_proposals'), - path('speakers//', SpeakerProposalManageView.as_view(), name='speakerproposal_manage'), - path('events//', EventProposalManageView.as_view(), name='eventproposal_manage'), - ])), + path('', BackofficeIndexView.as_view(), name='index'), + path('product_handout/', ProductHandoutView.as_view(), name='product_handout'), + path('badge_handout/', BadgeHandoutView.as_view(), name='badge_handout'), + path('ticket_checkin/', TicketCheckinView.as_view(), name='ticket_checkin'), + path('public_credit_names/', ApproveNamesView.as_view(), name='public_credit_names'), + path('manage_proposals/', include([ + path('', ManageProposalsView.as_view(), name='manage_proposals'), + path('speakers//', SpeakerProposalManageView.as_view(), name='speakerproposal_manage'), + path('events//', EventProposalManageView.as_view(), name='eventproposal_manage'), ])), ] diff --git a/src/backoffice/views.py b/src/backoffice/views.py index 2ac2efc3..7f057728 100644 --- a/src/backoffice/views.py +++ b/src/backoffice/views.py @@ -12,7 +12,7 @@ from shop.models import OrderProductRelation from tickets.models import ShopTicket, SponsorTicket, DiscountTicket from profiles.models import Profile from camps.models import Camp -from utils.mixins import StaffMemberRequiredMixin +from camps.mixins import CampViewMixin from program.models import SpeakerProposal, EventProposal from .mixins import BackofficeViewMixin @@ -20,31 +20,8 @@ from .mixins import BackofficeViewMixin logger = logging.getLogger("bornhack.%s" % __name__) -class CampSelectView(StaffMemberRequiredMixin, ListView): - model = Camp - template_name = "camp_select.html" - - def get_queryset(self): - """ - Filter away camps that are not writeable, since they are not interesting from a backoffice perspective - """ - return super().get_queryset().filter(read_only=False) - - def get(self, request, *args, **kwargs): - """ - If we only have one writable Camp redirect directly to it rather than show a 1 item list - """ - if self.get_queryset().count() == 1: - return redirect( - reverse('backoffice:camp_index', kwargs={ - 'bocamp_slug': self.get_queryset().first().slug - }) - ) - return super().get(request, *args, **kwargs) - - -class CampIndexView(BackofficeViewMixin, TemplateView): - template_name = "camp_index.html" +class BackofficeIndexView(BackofficeViewMixin, TemplateView): + template_name = "index.html" class ProductHandoutView(BackofficeViewMixin, ListView): @@ -96,14 +73,14 @@ class ManageProposalsView(BackofficeViewMixin, ListView): def get_queryset(self, **kwargs): return SpeakerProposal.objects.filter( - camp=self.bocamp, + camp=self.camp, proposal_status=SpeakerProposal.PROPOSAL_PENDING ) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['eventproposals'] = EventProposal.objects.filter( - track__camp=self.bocamp, + track__camp=self.camp, proposal_status=EventProposal.PROPOSAL_PENDING ) return context @@ -128,7 +105,7 @@ class ProposalManageView(BackofficeViewMixin, UpdateView): form.instance.mark_as_rejected(self.request) else: messages.error(self.request, "Unknown submit action") - return redirect(reverse('backoffice:manage_proposals', kwargs={'bocamp_slug': self.bocamp.slug})) + return redirect(reverse('backoffice:manage_proposals', kwargs={'camp_slug': self.camp.slug})) class SpeakerProposalManageView(ProposalManageView): diff --git a/src/bornhack/urls.py b/src/bornhack/urls.py index 3bbbe0fe..6c8f2ec9 100644 --- a/src/bornhack/urls.py +++ b/src/bornhack/urls.py @@ -113,11 +113,6 @@ urlpatterns = [ name='people', ), - path( - 'backoffice/', - include('backoffice.urls', namespace='backoffice') - ), - # camp specific urls below here path( @@ -187,6 +182,10 @@ urlpatterns = [ include('teams.urls', namespace='teams') ), + path( + 'backoffice/', + include('backoffice.urls', namespace='backoffice') + ), ]) ) diff --git a/src/templates/base.html b/src/templates/base.html index 1fb91fd5..4766b709 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -73,8 +73,7 @@
  • Contact
  • People
  • - {% if user.is_authenticated and user.is_staff %} -
  • Backoffice
  • + {% if request.user.is_staff %}
  • Django Admin
  • {% endif %} diff --git a/src/templates/includes/menuitems.html b/src/templates/includes/menuitems.html index 49dd27fd..9b021d07 100644 --- a/src/templates/includes/menuitems.html +++ b/src/templates/includes/menuitems.html @@ -5,4 +5,7 @@ Villages Sponsors Teams + {% if request.user.is_staff %} + Backoffice + {% endif %}