Unverified Commit 653943eb authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Implement restricting pizzas to special people

Implements #548
parent 617caaa5
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2017-12-13 19:01
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pizzas', '0005_auto_20171213_1954'),
]
operations = [
migrations.AddField(
model_name='product',
name='restricted',
field=models.BooleanField(default=False),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2017-12-13 19:17
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('pizzas', '0006_product_restricted'),
]
operations = [
migrations.AlterModelOptions(
name='product',
options={'ordering': ('name',), 'permissions': (('order_restricted_products', 'Order restricted products'),)},
),
migrations.AlterModelManagers(
name='product',
managers=[
],
),
]
......@@ -66,12 +66,16 @@ class Product(models.Model, metaclass=ModelTranslateMeta):
description = MultilingualField(models.TextField)
price = models.DecimalField(max_digits=5, decimal_places=2)
available = models.BooleanField(default=True)
restricted = models.BooleanField(default=False)
def __str__(self):
return self.name
class Meta:
ordering = ('name', )
permissions = (
('order_restricted_products', _('Order restricted products')),
)
class Order(models.Model):
......
......@@ -13,6 +13,8 @@ from .models import Order, PizzaEvent, Product
@login_required
def index(request):
products = Product.available_products.order_by('name')
if not request.user.has_perm('pizzas.order_restricted_products'):
products = products.exclude(restricted=True)
event = PizzaEvent.current()
try:
order = Order.objects.get(pizza_event=event,
......@@ -131,9 +133,11 @@ def order(request):
current_order_locked = False
if 'product' in request.POST and not current_order_locked:
productset = Product.available_products.all()
if not request.user.has_perm('pizzas.order_restricted_products'):
productset = productset.exclude(restricted=True)
try:
product = Product.available_products.get(
pk=int(request.POST['product']))
product = productset.get(pk=int(request.POST['product']))
except Product.DoesNotExist:
raise Http404('Pizza does not exist')
if not order:
......
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