Adds logic for required categories
This commit is contained in:
parent
dcad2d5f7c
commit
eff5686dcf
3 changed files with 41 additions and 2 deletions
20
registrasion/migrations/0006_category_required.py
Normal file
20
registrasion/migrations/0006_category_required.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('registrasion', '0005_auto_20160323_2141'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='category',
|
||||
name='required',
|
||||
field=models.BooleanField(default=False),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -132,6 +132,7 @@ class Category(models.Model):
|
|||
name = models.CharField(max_length=65, verbose_name=_("Name"))
|
||||
description = models.CharField(max_length=255,
|
||||
verbose_name=_("Description"))
|
||||
required = models.BooleanField(blank=True)
|
||||
order = models.PositiveIntegerField(verbose_name=("Display order"))
|
||||
render_type = models.IntegerField(choices=CATEGORY_RENDER_TYPES,
|
||||
verbose_name=_("Render type"))
|
||||
|
|
|
@ -114,12 +114,30 @@ def product_category(request, category_id):
|
|||
elif cat_form.is_valid():
|
||||
try:
|
||||
handle_valid_cat_form(cat_form, current_cart)
|
||||
except ValidationError as ve:
|
||||
pass
|
||||
|
||||
# If category is required, the user must have at least one
|
||||
# in an active+valid cart
|
||||
|
||||
if category.required:
|
||||
carts = rego.Cart.reserved_carts()
|
||||
carts = carts.filter(user=request.user)
|
||||
items = rego.ProductItem.objects.filter(
|
||||
product__category=category,
|
||||
cart=carts,
|
||||
)
|
||||
if len(items) == 0:
|
||||
cat_form.add_error(
|
||||
None,
|
||||
"You must have at least one item from this category",
|
||||
)
|
||||
|
||||
if not cat_form.errors:
|
||||
if category_id > attendee.highest_complete_category:
|
||||
attendee.highest_complete_category = category_id
|
||||
attendee.save()
|
||||
return redirect("dashboard")
|
||||
except ValidationError as ve:
|
||||
pass
|
||||
|
||||
else:
|
||||
# Create initial data for each of products in category
|
||||
|
|
Loading…
Reference in a new issue