Commit 1ebd5f8a authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch '549-ctrl-alt-delirium-can-order-inactive-pizza-s' into 'master'

Only order available products

Closes #549 and #548

See merge request !633
parents 1aa2e7b3 0c261fd1
......@@ -14,14 +14,18 @@ from pizzas.api import serializers
class PizzaViewset(GenericViewSet, ListModelMixin):
queryset = Product.objects.filter(available=True)
queryset = Product.available_products.all()
permission_classes = (permissions.IsAuthenticated,)
serializer_class = serializers.PizzaSerializer
def list(self, request, *args, **kwargs):
if (PizzaEvent.current() or
request.user.has_perm('pizzas.change_product')):
return super().list(request, *args, **kwargs)
queryset = self.get_queryset()
if not request.user.has_perm('pizzas.order_restricted_products'):
queryset = queryset.exclude(restricted=True)
serializer = serializers.PizzaSerializer(queryset, many=True)
return Response(serializer.data)
raise PermissionDenied
@list_route()
......
from django.forms import ModelForm
from .models import Order
from .models import Order, Product
class AddOrderForm(ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['product'].queryset = Product.available_products.all()
class Meta:
model = Order
fields = ['name', 'product']
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-15 22:31+0100\n"
"PO-Revision-Date: 2016-12-15 22:31+0100\n"
"POT-Creation-Date: 2018-01-02 16:34+0100\n"
"PO-Revision-Date: 2018-01-02 16:34+0100\n"
"Last-Translator: Joost Rijneveld <joost@joostrijneveld.nl>\n"
"Language-Team: \n"
"Language: nl\n"
......@@ -16,13 +16,18 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.11\n"
"X-Generator: Poedit 2.0.5\n"
#: pizzas/admin.py:18
#: pizzas/admin.py:21
#, python-brace-format
msgid "<strong><a href=\"{link}\">Orders</a></strong>"
msgstr "<strong><a href=\"{link}\">Bestellingen</a></strong>"
#: pizzas/api/serializers.py:38 pizzas/api/serializers.py:39
#: pizzas/models.py:108 pizzas/models.py:109
msgid "Either specify a member or a name"
msgstr "Specificeer een lid of vul een naam in"
#: pizzas/models.py:12
msgid "Order from"
msgstr "Bestel vanaf"
......@@ -31,50 +36,62 @@ msgstr "Bestel vanaf"
msgid "Order until"
msgstr "Bestel tot"
#: pizzas/models.py:42 pizzas/models.py:43
#: pizzas/models.py:46 pizzas/models.py:47
msgid "This event cannot overlap with "
msgstr "Dit evenement kan niet overlappen met "
#: pizzas/models.py:72
#: pizzas/models.py:71
msgid ""
"Only allow to be ordered by people with the 'order restricted products' "
"permission."
msgstr ""
"Laat alleen bestellen door mensen die de 'bestel beperkte producten' "
"permissie hebben."
#: pizzas/models.py:80
msgid "Order restricted products"
msgstr "Bestel beperkte producten"
#: pizzas/models.py:96
msgid "Use this for non-members"
msgstr "Vul dit in voor niet-leden"
#: pizzas/models.py:84 pizzas/models.py:85
msgid "Either specify a member or a name"
msgstr "Specificeer een lid of vul een naam in"
#: pizzas/templates/pizzas/add_order.html:4
#: pizzas/templates/pizzas/add_order.html:5
msgid "Add order"
msgstr "Nieuwe bestelling toevoegen"
#: pizzas/templates/pizzas/add_order.html:4
#: pizzas/templates/pizzas/index.html:4 pizzas/templates/pizzas/orders.html:5
#: pizzas/templates/pizzas/add_order.html:5
#: pizzas/templates/pizzas/index.html:4 pizzas/templates/pizzas/index.html:5
#: pizzas/templates/pizzas/orders.html:5 pizzas/templates/pizzas/orders.html:6
#: pizzas/templates/pizzas/overview.html:4
#: pizzas/templates/pizzas/overview.html:5
msgid "Pizzas"
msgstr "Pizza's"
#: pizzas/templates/pizzas/add_order.html:7
#: pizzas/templates/pizzas/add_order.html:8
#, python-format
msgid "Add order for %(title)s"
msgstr "Bestelling toevoegen voor %(title)s"
#: pizzas/templates/pizzas/add_order.html:12
#: pizzas/templates/pizzas/index.html:74 pizzas/templates/pizzas/index.html:107
#: pizzas/templates/pizzas/orders.html:22
#: pizzas/templates/pizzas/add_order.html:13
#: pizzas/templates/pizzas/index.html:82 pizzas/templates/pizzas/index.html:116
#: pizzas/templates/pizzas/orders.html:23
msgid "Name"
msgstr "Naam"
#: pizzas/templates/pizzas/add_order.html:21
#: pizzas/templates/pizzas/orders.html:23
#: pizzas/templates/pizzas/overview.html:20
#: pizzas/templates/pizzas/add_order.html:22
#: pizzas/templates/pizzas/orders.html:24
#: pizzas/templates/pizzas/overview.html:21
msgid "Product"
msgstr "Product"
#: pizzas/templates/pizzas/add_order.html:27
#: pizzas/templates/pizzas/add_order.html:28
msgid "Add"
msgstr "Toevoegen"
#: pizzas/templates/pizzas/add_order.html:33
#: pizzas/templates/pizzas/add_order.html:34
#, python-format
msgid ""
"A more generic version of this form is<br>also available in the <a href="
......@@ -83,162 +100,161 @@ msgstr ""
"Een meer generieke versie van dit formulier<br>is ook beschikbaar in de <a "
"href=\"%(url_pizzas_order_add)s\">back-end</a>."
#: pizzas/templates/pizzas/index.html:30
#: pizzas/templates/pizzas/index.html:8 pizzas/templates/pizzas/index.html:38
#, python-format
msgid "Order food for %(title)s"
msgstr "Bestel eten voor %(title)s"
#: pizzas/templates/pizzas/index.html:34
#: pizzas/templates/pizzas/index.html:10 pizzas/templates/pizzas/index.html:42
msgid "There is no current event for which you can order food"
msgstr "Er is nu geen evenement waar je eten voor kunt bestellen"
#: pizzas/templates/pizzas/index.html:39
#: pizzas/templates/pizzas/index.html:47
msgid "All products"
msgstr "Alle producten"
#: pizzas/templates/pizzas/index.html:42 pizzas/templates/pizzas/orders.html:14
#: pizzas/templates/pizzas/index.html:50 pizzas/templates/pizzas/orders.html:15
msgid "All events"
msgstr "Alle evenementen"
#: pizzas/templates/pizzas/index.html:45
#: pizzas/templates/pizzas/index.html:53
msgid "All orders"
msgstr "Alle bestellingen"
#: pizzas/templates/pizzas/index.html:52
#: pizzas/templates/pizzas/index.html:60
#, python-format
msgid "It will be possible to order from %(start)s."
msgstr "Je kan bestellen vanaf %(start)s."
#: pizzas/templates/pizzas/index.html:57
#: pizzas/templates/pizzas/index.html:65
#, python-format
msgid "It was possible to order until %(end)s."
msgstr "Je kon bestellen tot %(end)s."
#: pizzas/templates/pizzas/index.html:61
#: pizzas/templates/pizzas/index.html:69
#, python-format
msgid "It is possible to order until %(end)s."
msgstr "Je kan bestellen tot %(end)s."
#: pizzas/templates/pizzas/index.html:66
#: pizzas/templates/pizzas/index.html:74
msgid "The order has been paid for."
msgstr "De bestelling is betaald."
#: pizzas/templates/pizzas/index.html:68
#: pizzas/templates/pizzas/index.html:76
msgid "The order has not yet been paid for."
msgstr "De bestelling is nog niet betaald."
#: pizzas/templates/pizzas/index.html:70
#: pizzas/templates/pizzas/index.html:78
msgid "Current order"
msgstr "Huidige bestelling"
#: pizzas/templates/pizzas/index.html:75 pizzas/templates/pizzas/index.html:108
#: pizzas/templates/pizzas/index.html:83 pizzas/templates/pizzas/index.html:117
msgid "Description"
msgstr "Omschrijving"
#: pizzas/templates/pizzas/index.html:76 pizzas/templates/pizzas/index.html:109
#: pizzas/templates/pizzas/overview.html:21
#: pizzas/templates/pizzas/index.html:84 pizzas/templates/pizzas/index.html:118
#: pizzas/templates/pizzas/overview.html:22
msgid "Price"
msgstr "Prijs"
#: pizzas/templates/pizzas/index.html:77 pizzas/templates/pizzas/index.html:90
#: pizzas/templates/pizzas/index.html:85 pizzas/templates/pizzas/index.html:98
msgid "Cancel"
msgstr "Annuleren"
#: pizzas/templates/pizzas/index.html:85
#: pizzas/templates/pizzas/index.html:93 pizzas/views.py:95
msgid "You can no longer cancel."
msgstr "Je kunt niet meer annuleren."
#: pizzas/templates/pizzas/index.html:90
#: pizzas/templates/pizzas/index.html:98
msgid "Are you sure you want to cancel your order?"
msgstr "Weet je zeker dat je de bestelling wilt annuleren?"
#: pizzas/templates/pizzas/index.html:98
#: pizzas/templates/pizzas/index.html:106
msgid "Changing your order"
msgstr "Bestelling bewerken"
#: pizzas/templates/pizzas/index.html:101
#: pizzas/templates/pizzas/index.html:109
msgid "You did not place an order."
msgstr "Je hebt geen bestelling geplaatst."
#: pizzas/templates/pizzas/index.html:110
#: pizzas/templates/pizzas/index.html:121
#: pizzas/templates/pizzas/index.html:119
#: pizzas/templates/pizzas/index.html:130
msgid "Modify"
msgstr "Bewerken"
#: pizzas/templates/pizzas/index.html:110
#: pizzas/templates/pizzas/index.html:121
#: pizzas/templates/pizzas/index.html:119
#: pizzas/templates/pizzas/index.html:130
msgctxt "pizzas"
msgid "Order"
msgstr "Bestellen"
#: pizzas/templates/pizzas/index.html:121
#: pizzas/templates/pizzas/index.html:130
msgid "Are you sure you want to modify your order?"
msgstr "Weet je zeker dat je de bestelling aan wilt passen?"
#: pizzas/templates/pizzas/orders.html:9
#: pizzas/templates/pizzas/overview.html:9
#: pizzas/templates/pizzas/orders.html:10
#: pizzas/templates/pizzas/overview.html:10
#, python-format
msgid "Orders for %(title)s"
msgstr "Bestellingen voor %(title)s"
#: pizzas/templates/pizzas/orders.html:13
#: pizzas/templates/pizzas/orders.html:14
msgid "Add a new order"
msgstr "Nieuwe bestelling toevoegen"
#: pizzas/templates/pizzas/orders.html:15
#: pizzas/templates/pizzas/orders.html:16
msgid "Overview"
msgstr "Overzicht"
#: pizzas/templates/pizzas/orders.html:24
#: pizzas/templates/pizzas/orders.html:25
msgid "Paid"
msgstr "Betaald"
#: pizzas/templates/pizzas/orders.html:38
#: pizzas/templates/pizzas/orders.html:39
#: pizzas/templates/pizzas/overview.html:71
msgid "Yes"
msgstr "Ja"
#: pizzas/templates/pizzas/orders.html:38
#: pizzas/templates/pizzas/orders.html:39
#: pizzas/templates/pizzas/overview.html:71
msgid "No"
msgstr "Nee"
#: pizzas/templates/pizzas/orders.html:44
#: pizzas/templates/pizzas/orders.html:45
msgid "Are you sure you want to delete this order?"
msgstr "Weet je zeker dat je de bestelling wilt verwijderen?"
#: pizzas/templates/pizzas/orders.html:52
#: pizzas/templates/pizzas/overview.html:44
#: pizzas/templates/pizzas/orders.html:53
#: pizzas/templates/pizzas/overview.html:45
msgid "Nobody ordered yet"
msgstr "Nog geen bestellingen"
#: pizzas/templates/pizzas/overview.html:13
#: pizzas/templates/pizzas/overview.html:14
msgid "Back"
msgstr "Terug"
#: pizzas/templates/pizzas/overview.html:22
#: pizzas/templates/pizzas/overview.html:23
msgid "Amount"
msgstr "Aantal"
#: pizzas/templates/pizzas/overview.html:23
#: pizzas/templates/pizzas/overview.html:24
msgid "Total"
msgstr "Totaal"
#: pizzas/views.py:72
msgid "You must supply an order pk."
msgstr "Je moet een bestelling pk meegeven."
#: pizzas/views.py:76 pizzas/views.py:90 pizzas/views.py:106
#: pizzas/views.py:81 pizzas/views.py:100
msgid "Your order could not be found."
msgstr "Je bestelling kont niet worden gevonden."
#: pizzas/views.py:104
#: pizzas/views.py:98
msgid "Your order has been cancelled."
msgstr "Je bestelling is geannuleerd."
#: pizzas/views.py:118
#: pizzas/views.py:112
msgid "Your order was successful."
msgstr "Je bestelling is succesvol."
#~ msgid "You must supply an order pk."
#~ msgstr "Je moet een bestelling pk meegeven."
#~ msgid "Order not found!"
#~ msgstr "Bestelling niet gevonden!"
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2017-12-13 18:54
from __future__ import unicode_literals
from django.db import migrations
import django.db.models.manager
class Migration(migrations.Migration):
dependencies = [
('pizzas', '0004_auto_20171013_1408'),
]
operations = [
migrations.AlterModelManagers(
name='product',
managers=[
('available_products', django.db.models.manager.Manager()),
],
),
]
# -*- 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 2018-01-08 12:18
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
replaces = [('pizzas', '0006_product_restricted'), ('pizzas', '0007_auto_20171213_2017'), ('pizzas', '0008_auto_20180102_1635')]
dependencies = [
('pizzas', '0005_auto_20171213_1954'),
]
operations = [
migrations.AddField(
model_name='product',
name='restricted',
field=models.BooleanField(default=False),
),
migrations.AlterModelOptions(
name='product',
options={'ordering': ('name',), 'permissions': (('order_restricted_products', 'Order restricted products'),)},
),
migrations.AlterModelManagers(
name='product',
managers=[
],
),
migrations.AlterField(
model_name='product',
name='restricted',
field=models.BooleanField(default=False, help_text="Only allow to be ordered by people with the 'order restricted products' permission."),
),
]
# -*- 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=[
],
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-01-02 15:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pizzas', '0007_auto_20171213_2017'),
]
operations = [
migrations.AlterField(
model_name='product',
name='restricted',
field=models.BooleanField(default=False, help_text="Only allow to be ordered by people with the 'order restricted products' permission."),
),
]
......@@ -51,17 +51,34 @@ class PizzaEvent(models.Model):
return 'Pizzas for ' + str(self.event)
class AvailableProductManager(models.Manager):
"""Only shows available products"""
def get_queryset(self):
return super().get_queryset().filter(available=True)
class Product(models.Model, metaclass=ModelTranslateMeta):
objects = models.Manager()
available_products = AvailableProductManager()
name = models.CharField(max_length=50)
description = MultilingualField(models.TextField)
price = models.DecimalField(max_digits=5, decimal_places=2)
available = models.BooleanField(default=True)
restricted = models.BooleanField(
default=False,
help_text=_("Only allow to be ordered by people with the "
"'order restricted products' permission."))
def __str__(self):
return self.name
class Meta:
ordering = ('name', )
permissions = (
('order_restricted_products', _('Order restricted products')),
)
class Order(models.Model):
......
......@@ -12,7 +12,9 @@ from .models import Order, PizzaEvent, Product
@login_required
def index(request):
products = Product.objects.filter(available=True).order_by('name')
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,
......@@ -123,20 +125,23 @@ def order(request):
return HttpResponseRedirect(reverse('pizzas:index'))
try:
order_placed = Order.objects.get(pizza_event=event,
member=request.member)
current_order_locked = not order_placed.can_be_changed
order = Order.objects.get(pizza_event=event,
member=request.member)
current_order_locked = not order.can_be_changed
except Order.DoesNotExist:
order = None
current_order_locked = False
if 'product' in request.POST and not current_order_locked:
product = Product.objects.get(pk=int(request.POST['product']))
if product:
try:
order = Order.objects.get(pizza_event=event,
member=request.member)
except Order.DoesNotExist:
order = Order(pizza_event=event, member=request.member)
order.product = product
order.save()
productset = Product.available_products.all()
if not request.user.has_perm('pizzas.order_restricted_products'):
productset = productset.exclude(restricted=True)
try:
product = productset.get(pk=int(request.POST['product']))
except Product.DoesNotExist:
raise Http404('Pizza does not exist')
if not order:
order = Order(pizza_event=event, member=request.member)
order.product = product
order.save()
return HttpResponseRedirect(reverse('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