Renames EnablingCondition to Flag where possible
This commit is contained in:
parent
eefdb41cfc
commit
4fedc73304
7 changed files with 70 additions and 36 deletions
|
@ -102,8 +102,8 @@ class VoucherDiscountInline(nested_admin.NestedStackedInline):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class VoucherEnablingConditionInline(nested_admin.NestedStackedInline):
|
class VoucherFlagInline(nested_admin.NestedStackedInline):
|
||||||
model = rego.VoucherEnablingCondition
|
model = rego.VoucherFlag
|
||||||
verbose_name = _("Product and category enabled by voucher")
|
verbose_name = _("Product and category enabled by voucher")
|
||||||
verbose_name_plural = _("Products and categories enabled by voucher")
|
verbose_name_plural = _("Products and categories enabled by voucher")
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ class VoucherAdmin(nested_admin.NestedAdmin):
|
||||||
discount_effects = None
|
discount_effects = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
enabling_effects = obj.voucherenablingcondition.effects()
|
enabling_effects = obj.voucherflag.effects()
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
enabling_effects = None
|
enabling_effects = None
|
||||||
|
|
||||||
|
@ -140,20 +140,20 @@ class VoucherAdmin(nested_admin.NestedAdmin):
|
||||||
list_display = ("recipient", "code", "effects")
|
list_display = ("recipient", "code", "effects")
|
||||||
inlines = [
|
inlines = [
|
||||||
VoucherDiscountInline,
|
VoucherDiscountInline,
|
||||||
VoucherEnablingConditionInline,
|
VoucherFlagInline,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Enabling conditions
|
# Enabling conditions
|
||||||
@admin.register(rego.ProductEnablingCondition)
|
@admin.register(rego.ProductFlag)
|
||||||
class ProductEnablingConditionAdmin(
|
class ProductFlagAdmin(
|
||||||
nested_admin.NestedAdmin,
|
nested_admin.NestedAdmin,
|
||||||
EffectsDisplayMixin):
|
EffectsDisplayMixin):
|
||||||
|
|
||||||
def enablers(self, obj):
|
def enablers(self, obj):
|
||||||
return list(obj.enabling_products.all())
|
return list(obj.enabling_products.all())
|
||||||
|
|
||||||
model = rego.ProductEnablingCondition
|
model = rego.ProductFlag
|
||||||
fields = ("description", "enabling_products", "mandatory", "products",
|
fields = ("description", "enabling_products", "mandatory", "products",
|
||||||
"categories"),
|
"categories"),
|
||||||
|
|
||||||
|
@ -161,12 +161,12 @@ class ProductEnablingConditionAdmin(
|
||||||
|
|
||||||
|
|
||||||
# Enabling conditions
|
# Enabling conditions
|
||||||
@admin.register(rego.CategoryEnablingCondition)
|
@admin.register(rego.CategoryFlag)
|
||||||
class CategoryEnablingConditionAdmin(
|
class CategoryFlagAdmin(
|
||||||
nested_admin.NestedAdmin,
|
nested_admin.NestedAdmin,
|
||||||
EffectsDisplayMixin):
|
EffectsDisplayMixin):
|
||||||
|
|
||||||
model = rego.CategoryEnablingCondition
|
model = rego.CategoryFlag
|
||||||
fields = ("description", "enabling_category", "mandatory", "products",
|
fields = ("description", "enabling_category", "mandatory", "products",
|
||||||
"categories"),
|
"categories"),
|
||||||
|
|
||||||
|
@ -175,11 +175,11 @@ class CategoryEnablingConditionAdmin(
|
||||||
|
|
||||||
|
|
||||||
# Enabling conditions
|
# Enabling conditions
|
||||||
@admin.register(rego.TimeOrStockLimitEnablingCondition)
|
@admin.register(rego.TimeOrStockLimitFlag)
|
||||||
class TimeOrStockLimitEnablingConditionAdmin(
|
class TimeOrStockLimitFlagAdmin(
|
||||||
nested_admin.NestedAdmin,
|
nested_admin.NestedAdmin,
|
||||||
EffectsDisplayMixin):
|
EffectsDisplayMixin):
|
||||||
model = rego.TimeOrStockLimitEnablingCondition
|
model = rego.TimeOrStockLimitFlag
|
||||||
|
|
||||||
list_display = (
|
list_display = (
|
||||||
"description",
|
"description",
|
||||||
|
|
|
@ -20,7 +20,7 @@ ConditionAndRemainder = namedtuple(
|
||||||
|
|
||||||
|
|
||||||
class ConditionController(object):
|
class ConditionController(object):
|
||||||
''' Base class for testing conditions that activate EnablingCondition
|
''' Base class for testing conditions that activate Flag
|
||||||
or Discount objects. '''
|
or Discount objects. '''
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -29,15 +29,15 @@ class ConditionController(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def for_condition(condition):
|
def for_condition(condition):
|
||||||
CONTROLLERS = {
|
CONTROLLERS = {
|
||||||
rego.CategoryEnablingCondition: CategoryConditionController,
|
rego.CategoryFlag: CategoryConditionController,
|
||||||
rego.IncludedProductDiscount: ProductConditionController,
|
rego.IncludedProductDiscount: ProductConditionController,
|
||||||
rego.ProductEnablingCondition: ProductConditionController,
|
rego.ProductFlag: ProductConditionController,
|
||||||
rego.TimeOrStockLimitDiscount:
|
rego.TimeOrStockLimitDiscount:
|
||||||
TimeOrStockLimitDiscountController,
|
TimeOrStockLimitDiscountController,
|
||||||
rego.TimeOrStockLimitEnablingCondition:
|
rego.TimeOrStockLimitFlag:
|
||||||
TimeOrStockLimitEnablingConditionController,
|
TimeOrStockLimitFlagController,
|
||||||
rego.VoucherDiscount: VoucherConditionController,
|
rego.VoucherDiscount: VoucherConditionController,
|
||||||
rego.VoucherEnablingCondition: VoucherConditionController,
|
rego.VoucherFlag: VoucherConditionController,
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -211,7 +211,7 @@ class CategoryConditionController(ConditionController):
|
||||||
|
|
||||||
|
|
||||||
class ProductConditionController(ConditionController):
|
class ProductConditionController(ConditionController):
|
||||||
''' Condition tests for ProductEnablingCondition and
|
''' Condition tests for ProductFlag and
|
||||||
IncludedProductDiscount. '''
|
IncludedProductDiscount. '''
|
||||||
|
|
||||||
def __init__(self, condition):
|
def __init__(self, condition):
|
||||||
|
@ -230,7 +230,7 @@ class ProductConditionController(ConditionController):
|
||||||
|
|
||||||
|
|
||||||
class TimeOrStockLimitConditionController(ConditionController):
|
class TimeOrStockLimitConditionController(ConditionController):
|
||||||
''' Common condition tests for TimeOrStockLimit EnablingCondition and
|
''' Common condition tests for TimeOrStockLimit Flag and
|
||||||
Discount.'''
|
Discount.'''
|
||||||
|
|
||||||
def __init__(self, ceiling):
|
def __init__(self, ceiling):
|
||||||
|
@ -280,7 +280,7 @@ class TimeOrStockLimitConditionController(ConditionController):
|
||||||
return self.ceiling.limit - count
|
return self.ceiling.limit - count
|
||||||
|
|
||||||
|
|
||||||
class TimeOrStockLimitEnablingConditionController(
|
class TimeOrStockLimitFlagController(
|
||||||
TimeOrStockLimitConditionController):
|
TimeOrStockLimitConditionController):
|
||||||
|
|
||||||
def _items(self):
|
def _items(self):
|
||||||
|
@ -305,7 +305,7 @@ class TimeOrStockLimitDiscountController(TimeOrStockLimitConditionController):
|
||||||
|
|
||||||
|
|
||||||
class VoucherConditionController(ConditionController):
|
class VoucherConditionController(ConditionController):
|
||||||
''' Condition test for VoucherEnablingCondition and VoucherDiscount.'''
|
''' Condition test for VoucherFlag and VoucherDiscount.'''
|
||||||
|
|
||||||
def __init__(self, condition):
|
def __init__(self, condition):
|
||||||
self.condition = condition
|
self.condition = condition
|
||||||
|
|
31
registrasion/migrations/0021_auto_20160411_0748.py
Normal file
31
registrasion/migrations/0021_auto_20160411_0748.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9.2 on 2016-04-11 07:48
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('registrasion', '0020_auto_20160411_0258'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameModel(
|
||||||
|
old_name='CategoryEnablingCondition',
|
||||||
|
new_name='CategoryFlag',
|
||||||
|
),
|
||||||
|
migrations.RenameModel(
|
||||||
|
old_name='ProductEnablingCondition',
|
||||||
|
new_name='ProductFlag',
|
||||||
|
),
|
||||||
|
migrations.RenameModel(
|
||||||
|
old_name='TimeOrStockLimitEnablingCondition',
|
||||||
|
new_name='TimeOrStockLimitFlag',
|
||||||
|
),
|
||||||
|
migrations.RenameModel(
|
||||||
|
old_name='VoucherEnablingCondition',
|
||||||
|
new_name='VoucherFlag',
|
||||||
|
),
|
||||||
|
]
|
|
@ -375,6 +375,9 @@ class EnablingConditionBase(models.Model):
|
||||||
condition defined on a Product or Category, it will only be enabled if at
|
condition defined on a Product or Category, it will only be enabled if at
|
||||||
least one condition is met. '''
|
least one condition is met. '''
|
||||||
|
|
||||||
|
# TODO: rename to EnablingConditionBase once https://code.djangoproject.com/ticket/26488
|
||||||
|
# is solved.
|
||||||
|
|
||||||
objects = InheritanceManager()
|
objects = InheritanceManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -405,7 +408,7 @@ class EnablingConditionBase(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TimeOrStockLimitEnablingCondition(EnablingConditionBase):
|
class TimeOrStockLimitFlag(EnablingConditionBase):
|
||||||
''' Registration product ceilings '''
|
''' Registration product ceilings '''
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -432,7 +435,7 @@ class TimeOrStockLimitEnablingCondition(EnablingConditionBase):
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class ProductEnablingCondition(EnablingConditionBase):
|
class ProductFlag(EnablingConditionBase):
|
||||||
''' The condition is met because a specific product is purchased. '''
|
''' The condition is met because a specific product is purchased. '''
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -446,7 +449,7 @@ class ProductEnablingCondition(EnablingConditionBase):
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class CategoryEnablingCondition(EnablingConditionBase):
|
class CategoryFlag(EnablingConditionBase):
|
||||||
''' The condition is met because a product in a particular product is
|
''' The condition is met because a product in a particular product is
|
||||||
purchased. '''
|
purchased. '''
|
||||||
|
|
||||||
|
@ -461,7 +464,7 @@ class CategoryEnablingCondition(EnablingConditionBase):
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class VoucherEnablingCondition(EnablingConditionBase):
|
class VoucherFlag(EnablingConditionBase):
|
||||||
''' The condition is met because a Voucher is present. This is for e.g.
|
''' The condition is met because a Voucher is present. This is for e.g.
|
||||||
enabling sponsor tickets. '''
|
enabling sponsor tickets. '''
|
||||||
|
|
||||||
|
@ -472,10 +475,10 @@ class VoucherEnablingCondition(EnablingConditionBase):
|
||||||
|
|
||||||
|
|
||||||
# @python_2_unicode_compatible
|
# @python_2_unicode_compatible
|
||||||
class RoleEnablingCondition(object):
|
class RoleFlag(object):
|
||||||
''' The condition is met because the active user has a particular Role.
|
''' The condition is met because the active user has a particular Role.
|
||||||
This is for e.g. enabling Team tickets. '''
|
This is for e.g. enabling Team tickets. '''
|
||||||
# TODO: implement RoleEnablingCondition
|
# TODO: implement RoleFlag
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def make_ceiling(cls, name, limit=None, start_time=None, end_time=None):
|
def make_ceiling(cls, name, limit=None, start_time=None, end_time=None):
|
||||||
limit_ceiling = rego.TimeOrStockLimitEnablingCondition.objects.create(
|
limit_ceiling = rego.TimeOrStockLimitFlag.objects.create(
|
||||||
description=name,
|
description=name,
|
||||||
mandatory=True,
|
mandatory=True,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
|
@ -109,7 +109,7 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def make_category_ceiling(
|
def make_category_ceiling(
|
||||||
cls, name, limit=None, start_time=None, end_time=None):
|
cls, name, limit=None, start_time=None, end_time=None):
|
||||||
limit_ceiling = rego.TimeOrStockLimitEnablingCondition.objects.create(
|
limit_ceiling = rego.TimeOrStockLimitFlag.objects.create(
|
||||||
description=name,
|
description=name,
|
||||||
mandatory=True,
|
mandatory=True,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
|
|
|
@ -12,13 +12,13 @@ from test_cart import RegistrationCartTestCase
|
||||||
UTC = pytz.timezone('UTC')
|
UTC = pytz.timezone('UTC')
|
||||||
|
|
||||||
|
|
||||||
class EnablingConditionTestCases(RegistrationCartTestCase):
|
class FlagTestCases(RegistrationCartTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_product_enabling_condition(cls, mandatory=False):
|
def add_product_enabling_condition(cls, mandatory=False):
|
||||||
''' Adds a product enabling condition: adding PROD_1 to a cart is
|
''' Adds a product enabling condition: adding PROD_1 to a cart is
|
||||||
predicated on adding PROD_2 beforehand. '''
|
predicated on adding PROD_2 beforehand. '''
|
||||||
enabling_condition = rego.ProductEnablingCondition.objects.create(
|
enabling_condition = rego.ProductFlag.objects.create(
|
||||||
description="Product condition",
|
description="Product condition",
|
||||||
mandatory=mandatory,
|
mandatory=mandatory,
|
||||||
)
|
)
|
||||||
|
@ -31,7 +31,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
def add_product_enabling_condition_on_category(cls, mandatory=False):
|
def add_product_enabling_condition_on_category(cls, mandatory=False):
|
||||||
''' Adds a product enabling condition that operates on a category:
|
''' Adds a product enabling condition that operates on a category:
|
||||||
adding an item from CAT_1 is predicated on adding PROD_3 beforehand '''
|
adding an item from CAT_1 is predicated on adding PROD_3 beforehand '''
|
||||||
enabling_condition = rego.ProductEnablingCondition.objects.create(
|
enabling_condition = rego.ProductFlag.objects.create(
|
||||||
description="Product condition",
|
description="Product condition",
|
||||||
mandatory=mandatory,
|
mandatory=mandatory,
|
||||||
)
|
)
|
||||||
|
@ -43,7 +43,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
def add_category_enabling_condition(cls, mandatory=False):
|
def add_category_enabling_condition(cls, mandatory=False):
|
||||||
''' Adds a category enabling condition: adding PROD_1 to a cart is
|
''' Adds a category enabling condition: adding PROD_1 to a cart is
|
||||||
predicated on adding an item from CAT_2 beforehand.'''
|
predicated on adding an item from CAT_2 beforehand.'''
|
||||||
enabling_condition = rego.CategoryEnablingCondition.objects.create(
|
enabling_condition = rego.CategoryFlag.objects.create(
|
||||||
description="Category condition",
|
description="Category condition",
|
||||||
mandatory=mandatory,
|
mandatory=mandatory,
|
||||||
enabling_category=cls.CAT_2,
|
enabling_category=cls.CAT_2,
|
||||||
|
|
|
@ -58,7 +58,7 @@ class VoucherTestCases(RegistrationCartTestCase):
|
||||||
def test_voucher_enables_item(self):
|
def test_voucher_enables_item(self):
|
||||||
voucher = self.new_voucher()
|
voucher = self.new_voucher()
|
||||||
|
|
||||||
enabling_condition = rego.VoucherEnablingCondition.objects.create(
|
enabling_condition = rego.VoucherFlag.objects.create(
|
||||||
description="Voucher condition",
|
description="Voucher condition",
|
||||||
voucher=voucher,
|
voucher=voucher,
|
||||||
mandatory=False,
|
mandatory=False,
|
||||||
|
|
Loading…
Reference in a new issue