diff --git a/registrasion/admin.py b/registrasion/admin.py index 7155e177..67f50a8d 100644 --- a/registrasion/admin.py +++ b/registrasion/admin.py @@ -102,8 +102,8 @@ class VoucherDiscountInline(nested_admin.NestedStackedInline): ] -class VoucherEnablingConditionInline(nested_admin.NestedStackedInline): - model = rego.VoucherEnablingCondition +class VoucherFlagInline(nested_admin.NestedStackedInline): + model = rego.VoucherFlag verbose_name = _("Product and category enabled by voucher") verbose_name_plural = _("Products and categories enabled by voucher") @@ -125,7 +125,7 @@ class VoucherAdmin(nested_admin.NestedAdmin): discount_effects = None try: - enabling_effects = obj.voucherenablingcondition.effects() + enabling_effects = obj.voucherflag.effects() except ObjectDoesNotExist: enabling_effects = None @@ -140,20 +140,20 @@ class VoucherAdmin(nested_admin.NestedAdmin): list_display = ("recipient", "code", "effects") inlines = [ VoucherDiscountInline, - VoucherEnablingConditionInline, + VoucherFlagInline, ] # Enabling conditions -@admin.register(rego.ProductEnablingCondition) -class ProductEnablingConditionAdmin( +@admin.register(rego.ProductFlag) +class ProductFlagAdmin( nested_admin.NestedAdmin, EffectsDisplayMixin): def enablers(self, obj): return list(obj.enabling_products.all()) - model = rego.ProductEnablingCondition + model = rego.ProductFlag fields = ("description", "enabling_products", "mandatory", "products", "categories"), @@ -161,12 +161,12 @@ class ProductEnablingConditionAdmin( # Enabling conditions -@admin.register(rego.CategoryEnablingCondition) -class CategoryEnablingConditionAdmin( +@admin.register(rego.CategoryFlag) +class CategoryFlagAdmin( nested_admin.NestedAdmin, EffectsDisplayMixin): - model = rego.CategoryEnablingCondition + model = rego.CategoryFlag fields = ("description", "enabling_category", "mandatory", "products", "categories"), @@ -175,11 +175,11 @@ class CategoryEnablingConditionAdmin( # Enabling conditions -@admin.register(rego.TimeOrStockLimitEnablingCondition) -class TimeOrStockLimitEnablingConditionAdmin( +@admin.register(rego.TimeOrStockLimitFlag) +class TimeOrStockLimitFlagAdmin( nested_admin.NestedAdmin, EffectsDisplayMixin): - model = rego.TimeOrStockLimitEnablingCondition + model = rego.TimeOrStockLimitFlag list_display = ( "description", diff --git a/registrasion/controllers/conditions.py b/registrasion/controllers/conditions.py index 03b50118..787aed05 100644 --- a/registrasion/controllers/conditions.py +++ b/registrasion/controllers/conditions.py @@ -20,7 +20,7 @@ ConditionAndRemainder = namedtuple( class ConditionController(object): - ''' Base class for testing conditions that activate EnablingCondition + ''' Base class for testing conditions that activate Flag or Discount objects. ''' def __init__(self): @@ -29,15 +29,15 @@ class ConditionController(object): @staticmethod def for_condition(condition): CONTROLLERS = { - rego.CategoryEnablingCondition: CategoryConditionController, + rego.CategoryFlag: CategoryConditionController, rego.IncludedProductDiscount: ProductConditionController, - rego.ProductEnablingCondition: ProductConditionController, + rego.ProductFlag: ProductConditionController, rego.TimeOrStockLimitDiscount: TimeOrStockLimitDiscountController, - rego.TimeOrStockLimitEnablingCondition: - TimeOrStockLimitEnablingConditionController, + rego.TimeOrStockLimitFlag: + TimeOrStockLimitFlagController, rego.VoucherDiscount: VoucherConditionController, - rego.VoucherEnablingCondition: VoucherConditionController, + rego.VoucherFlag: VoucherConditionController, } try: @@ -211,7 +211,7 @@ class CategoryConditionController(ConditionController): class ProductConditionController(ConditionController): - ''' Condition tests for ProductEnablingCondition and + ''' Condition tests for ProductFlag and IncludedProductDiscount. ''' def __init__(self, condition): @@ -230,7 +230,7 @@ class ProductConditionController(ConditionController): class TimeOrStockLimitConditionController(ConditionController): - ''' Common condition tests for TimeOrStockLimit EnablingCondition and + ''' Common condition tests for TimeOrStockLimit Flag and Discount.''' def __init__(self, ceiling): @@ -280,7 +280,7 @@ class TimeOrStockLimitConditionController(ConditionController): return self.ceiling.limit - count -class TimeOrStockLimitEnablingConditionController( +class TimeOrStockLimitFlagController( TimeOrStockLimitConditionController): def _items(self): @@ -305,7 +305,7 @@ class TimeOrStockLimitDiscountController(TimeOrStockLimitConditionController): class VoucherConditionController(ConditionController): - ''' Condition test for VoucherEnablingCondition and VoucherDiscount.''' + ''' Condition test for VoucherFlag and VoucherDiscount.''' def __init__(self, condition): self.condition = condition diff --git a/registrasion/migrations/0021_auto_20160411_0748.py b/registrasion/migrations/0021_auto_20160411_0748.py new file mode 100644 index 00000000..345cd4ad --- /dev/null +++ b/registrasion/migrations/0021_auto_20160411_0748.py @@ -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', + ), + ] diff --git a/registrasion/models.py b/registrasion/models.py index 6e625887..a69f67dc 100644 --- a/registrasion/models.py +++ b/registrasion/models.py @@ -375,6 +375,9 @@ class EnablingConditionBase(models.Model): condition defined on a Product or Category, it will only be enabled if at least one condition is met. ''' + # TODO: rename to EnablingConditionBase once https://code.djangoproject.com/ticket/26488 + # is solved. + objects = InheritanceManager() def __str__(self): @@ -405,7 +408,7 @@ class EnablingConditionBase(models.Model): ) -class TimeOrStockLimitEnablingCondition(EnablingConditionBase): +class TimeOrStockLimitFlag(EnablingConditionBase): ''' Registration product ceilings ''' class Meta: @@ -432,7 +435,7 @@ class TimeOrStockLimitEnablingCondition(EnablingConditionBase): @python_2_unicode_compatible -class ProductEnablingCondition(EnablingConditionBase): +class ProductFlag(EnablingConditionBase): ''' The condition is met because a specific product is purchased. ''' def __str__(self): @@ -446,7 +449,7 @@ class ProductEnablingCondition(EnablingConditionBase): @python_2_unicode_compatible -class CategoryEnablingCondition(EnablingConditionBase): +class CategoryFlag(EnablingConditionBase): ''' The condition is met because a product in a particular product is purchased. ''' @@ -461,7 +464,7 @@ class CategoryEnablingCondition(EnablingConditionBase): @python_2_unicode_compatible -class VoucherEnablingCondition(EnablingConditionBase): +class VoucherFlag(EnablingConditionBase): ''' The condition is met because a Voucher is present. This is for e.g. enabling sponsor tickets. ''' @@ -472,10 +475,10 @@ class VoucherEnablingCondition(EnablingConditionBase): # @python_2_unicode_compatible -class RoleEnablingCondition(object): +class RoleFlag(object): ''' The condition is met because the active user has a particular Role. This is for e.g. enabling Team tickets. ''' - # TODO: implement RoleEnablingCondition + # TODO: implement RoleFlag pass diff --git a/registrasion/tests/test_cart.py b/registrasion/tests/test_cart.py index f8a82c21..eb7ff528 100644 --- a/registrasion/tests/test_cart.py +++ b/registrasion/tests/test_cart.py @@ -95,7 +95,7 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase): @classmethod 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, mandatory=True, limit=limit, @@ -109,7 +109,7 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase): @classmethod def make_category_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, mandatory=True, limit=limit, diff --git a/registrasion/tests/test_enabling_condition.py b/registrasion/tests/test_enabling_condition.py index d977cc5c..2782e464 100644 --- a/registrasion/tests/test_enabling_condition.py +++ b/registrasion/tests/test_enabling_condition.py @@ -12,13 +12,13 @@ from test_cart import RegistrationCartTestCase UTC = pytz.timezone('UTC') -class EnablingConditionTestCases(RegistrationCartTestCase): +class FlagTestCases(RegistrationCartTestCase): @classmethod def add_product_enabling_condition(cls, mandatory=False): ''' Adds a product enabling condition: adding PROD_1 to a cart is predicated on adding PROD_2 beforehand. ''' - enabling_condition = rego.ProductEnablingCondition.objects.create( + enabling_condition = rego.ProductFlag.objects.create( description="Product condition", mandatory=mandatory, ) @@ -31,7 +31,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase): def add_product_enabling_condition_on_category(cls, mandatory=False): ''' Adds a product enabling condition that operates on a category: 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", mandatory=mandatory, ) @@ -43,7 +43,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase): def add_category_enabling_condition(cls, mandatory=False): ''' Adds a category enabling condition: adding PROD_1 to a cart is predicated on adding an item from CAT_2 beforehand.''' - enabling_condition = rego.CategoryEnablingCondition.objects.create( + enabling_condition = rego.CategoryFlag.objects.create( description="Category condition", mandatory=mandatory, enabling_category=cls.CAT_2, diff --git a/registrasion/tests/test_voucher.py b/registrasion/tests/test_voucher.py index d4614efb..de3f93ee 100644 --- a/registrasion/tests/test_voucher.py +++ b/registrasion/tests/test_voucher.py @@ -58,7 +58,7 @@ class VoucherTestCases(RegistrationCartTestCase): def test_voucher_enables_item(self): voucher = self.new_voucher() - enabling_condition = rego.VoucherEnablingCondition.objects.create( + enabling_condition = rego.VoucherFlag.objects.create( description="Voucher condition", voucher=voucher, mandatory=False,