Bills initially working just as proof of concept
ng linted modifier categories list is better at displaying data sanely now
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
import uuid
|
||||
from functools import reduce
|
||||
|
||||
import transaction
|
||||
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import ModifierCategory, Product
|
||||
from barker.models import ModifierCategory, Product, MenuCategory
|
||||
from barker.models.validation_exception import ValidationError
|
||||
|
||||
|
||||
@ -73,12 +74,12 @@ def update(request):
|
||||
item.maximum = json.get("maximum", None)
|
||||
if item.maximum is not None:
|
||||
item.maximum = int(item.maximum)
|
||||
if item.maximum < 0:
|
||||
raise ValidationError(
|
||||
"Maximum must be an integer and cannot be less than zero"
|
||||
)
|
||||
elif item.maximum == 0:
|
||||
item.maximum = None
|
||||
if item.maximum < 0:
|
||||
raise ValidationError(
|
||||
"Maximum must be an integer and cannot be less than zero"
|
||||
)
|
||||
elif item.maximum == 0:
|
||||
item.maximum = None
|
||||
except ValueError:
|
||||
raise ValidationError("Maximum must be an integer and cannot be less than zero")
|
||||
item.is_active = json["isActive"]
|
||||
@ -139,18 +140,41 @@ def show_list(request):
|
||||
.order_by(ModifierCategory.name)
|
||||
.all()
|
||||
)
|
||||
menu_categories = (
|
||||
request.dbsession.query(MenuCategory)
|
||||
.join(MenuCategory.products)
|
||||
.filter(Product.is_active == True)
|
||||
.order_by(MenuCategory.sort_order, Product.sort_order, Product.name)
|
||||
.all()
|
||||
)
|
||||
modifier_categories = []
|
||||
for item in list_:
|
||||
modifier_categories.append(
|
||||
{
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"minimum": item.minimum,
|
||||
"maximum": item.maximum,
|
||||
"isActive": item.is_active,
|
||||
"products": [p.name for p in item.products],
|
||||
}
|
||||
)
|
||||
modifier_category = {
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"minimum": item.minimum,
|
||||
"maximum": item.maximum,
|
||||
"isActive": item.is_active,
|
||||
"menuCategories": [
|
||||
{
|
||||
"id": mc.id,
|
||||
"name": mc.name,
|
||||
"enabled": reduce(
|
||||
lambda x, y: x and (y in item.products), mc.products, True
|
||||
),
|
||||
"products": [
|
||||
{"id": p.id, "name": p.name}
|
||||
for p in mc.products
|
||||
if p in item.products
|
||||
],
|
||||
}
|
||||
for mc in menu_categories
|
||||
],
|
||||
}
|
||||
modifier_category["menuCategories"] = [
|
||||
i for i in modifier_category["menuCategories"] if len(i["products"]) > 0
|
||||
]
|
||||
modifier_categories.append(modifier_category)
|
||||
return modifier_categories
|
||||
|
||||
|
||||
@ -173,21 +197,17 @@ def show_for_pg(request):
|
||||
"maximum": item.maximum,
|
||||
"isActive": item.is_active,
|
||||
"modifiers": [
|
||||
{
|
||||
"id": m.id,
|
||||
"name": m.name,
|
||||
"prince": m.price
|
||||
}
|
||||
for m in item.modifiers if m.is_active == True
|
||||
{"id": m.id, "name": m.name, "prince": m.price}
|
||||
for m in item.modifiers
|
||||
if m.is_active == True
|
||||
],
|
||||
}
|
||||
for item in product.modifier_categories if item.is_active == True
|
||||
for item in product.modifier_categories
|
||||
if item.is_active == True
|
||||
]
|
||||
|
||||
|
||||
def modifier_category_info(item, dbsession):
|
||||
from barker.models import MenuCategory
|
||||
|
||||
menu_categories = (
|
||||
dbsession.query(MenuCategory)
|
||||
.join(MenuCategory.products)
|
||||
|
||||
Reference in New Issue
Block a user