Verified Commit 4dcefaa9 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Remove obselete pizza views and fix redirects

parent 54be22a3
......@@ -5,8 +5,7 @@ from . import views
app_name = "pizzas"
urlpatterns = [
url(r'^delete-order/$', views.delete_order, name='delete-order'),
url(r'^cancel-order/$', views.cancel_order, name='cancel-order'),
url(r'^order/cancel$', views.cancel_order, name='cancel-order'),
url(r'^order/$', views.order, name='order'),
url(r'^$', views.index, name='index'),
]
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.contrib.auth.decorators import login_required
from django.http import Http404
from django.shortcuts import get_object_or_404, render, redirect
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_http_methods
......@@ -24,63 +23,6 @@ def index(request):
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"])
def cancel_order(request):
if 'order' in request.POST:
......@@ -94,14 +36,14 @@ def cancel_order(request):
messages.success(request, _("Your order has been cancelled."))
except Http404:
messages.error(request, _("Your order could not be found."))
return HttpResponseRedirect(reverse('pizzas:index'))
return redirect('pizzas:index')
@login_required
def order(request):
event = PizzaEvent.current()
if not event:
return HttpResponseRedirect(reverse('pizzas:index'))
return redirect('pizzas:index')
try:
order = Order.objects.get(pizza_event=event,
......@@ -123,4 +65,4 @@ def order(request):
order = Order(pizza_event=event, member=request.member)
order.product = product
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