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):
|
||||
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",
|
||||
|
|
|
@ -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
|
||||
|
|
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
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue