Commit fed362f3 authored by Luko van der Maas's avatar Luko van der Maas
Browse files

Merge branch 'remove-obsolete-pizza-views' into 'master'

Remove obsolete pizza views and fix redirects

See merge request !1253
parents ffaee25e 4dcefaa9
...@@ -5,8 +5,7 @@ from . import views ...@@ -5,8 +5,7 @@ from . import views
app_name = "pizzas" app_name = "pizzas"
urlpatterns = [ urlpatterns = [
url(r'^delete-order/$', views.delete_order, name='delete-order'), url(r'^order/cancel$', views.cancel_order, name='cancel-order'),
url(r'^cancel-order/$', views.cancel_order, name='cancel-order'),
url(r'^order/$', views.order, name='order'), url(r'^order/$', views.order, name='order'),
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
] ]
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required
from django.http import Http404, HttpResponseRedirect from django.http import Http404
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_http_methods from django.views.decorators.http import require_http_methods
...@@ -24,63 +23,6 @@ def index(request): ...@@ -24,63 +23,6 @@ def index(request):
return render(request, 'pizzas/index.html', context) return render(request, 'pizzas/index.html', context)
@permission_required('pizzas.change_order')
def orders(request, event_pk):
event = get_object_or_404(PizzaEvent, pk=event_pk)
context = {'event': event,
'orders': Order.objects.filter(pizza_event=event)
.prefetch_related('member', 'product')
.order_by('member__first_name')}
return render(request, 'pizzas/orders.html', context)
@permission_required('pizzas.change_order')
def overview(request, event_pk):
event = get_object_or_404(PizzaEvent, pk=event_pk)
product_list = {}
total_money = 0
total_products = 0
orders = Order.objects.filter(pizza_event=event)\
.prefetch_related('product')
for order in orders:
if order.product.id not in product_list:
product_list[order.product.id] = {
'name': order.product.name,
'price': order.product.price,
'amount': 0,
'total': 0
}
product_list[order.product.id]['amount'] += 1
product_list[order.product.id]['total'] += order.product.price
total_products += 1
total_money += order.product.price
product_list = sorted(product_list.values(), key=lambda x: x['name'])
context = {
'event': event,
'product_list': product_list,
'total_money': total_money,
'total_products': total_products
}
return render(request, 'pizzas/overview.html', context)
@require_http_methods(["POST"])
@permission_required('pizzas.change_order')
def delete_order(request):
if 'order' in request.POST:
try:
order = get_object_or_404(Order, pk=int(request.POST['order']))
order.delete()
except Http404:
messages.error(request, _("Your order could not be found."))
return HttpResponseRedirect(reverse('pizzas:index'))
@require_http_methods(["POST"]) @require_http_methods(["POST"])
def cancel_order(request): def cancel_order(request):
if 'order' in request.POST: if 'order' in request.POST:
...@@ -94,14 +36,14 @@ def cancel_order(request): ...@@ -94,14 +36,14 @@ def cancel_order(request):
messages.success(request, _("Your order has been cancelled.")) messages.success(request, _("Your order has been cancelled."))
except Http404: except Http404:
messages.error(request, _("Your order could not be found.")) messages.error(request, _("Your order could not be found."))
return HttpResponseRedirect(reverse('pizzas:index')) return redirect('pizzas:index')
@login_required @login_required
def order(request): def order(request):
event = PizzaEvent.current() event = PizzaEvent.current()
if not event: if not event:
return HttpResponseRedirect(reverse('pizzas:index')) return redirect('pizzas:index')
try: try:
order = Order.objects.get(pizza_event=event, order = Order.objects.get(pizza_event=event,
...@@ -123,4 +65,4 @@ def order(request): ...@@ -123,4 +65,4 @@ def order(request):
order = Order(pizza_event=event, member=request.member) order = Order(pizza_event=event, member=request.member)
order.product = product order.product = product
order.save() order.save()
return HttpResponseRedirect(reverse('pizzas:index')) return redirect('pizzas:index')
Markdown is supported
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