2016-01-22 05:01:30 +00:00
|
|
|
from django.contrib import admin
|
2016-03-31 01:04:30 +00:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
2016-01-22 05:01:30 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
import nested_admin
|
|
|
|
|
2016-04-22 05:06:24 +00:00
|
|
|
from registrasion.models import conditions
|
|
|
|
from registrasion.models import inventory
|
2016-01-22 05:01:30 +00:00
|
|
|
|
|
|
|
|
2016-03-31 01:04:30 +00:00
|
|
|
class EffectsDisplayMixin(object):
|
|
|
|
def effects(self, obj):
|
|
|
|
return list(obj.effects())
|
|
|
|
|
2016-09-04 04:21:30 +00:00
|
|
|
|
2016-01-22 05:01:30 +00:00
|
|
|
# Inventory admin
|
|
|
|
|
2016-03-31 01:04:30 +00:00
|
|
|
|
2016-01-22 05:01:30 +00:00
|
|
|
class ProductInline(admin.TabularInline):
|
2016-04-22 05:06:24 +00:00
|
|
|
model = inventory.Product
|
2016-01-22 05:01:30 +00:00
|
|
|
|
|
|
|
|
2016-04-22 05:06:24 +00:00
|
|
|
@admin.register(inventory.Category)
|
2016-01-22 05:01:30 +00:00
|
|
|
class CategoryAdmin(admin.ModelAdmin):
|
2016-04-22 05:06:24 +00:00
|
|
|
model = inventory.Category
|
2016-03-31 01:04:30 +00:00
|
|
|
fields = ("name", "description", "required", "render_type",
|
|
|
|
"limit_per_user", "order",)
|
|
|
|
list_display = ("name", "description")
|
2016-01-22 05:01:30 +00:00
|
|
|
inlines = [
|
|
|
|
ProductInline,
|
|
|
|
]
|
|
|
|
|
2016-03-31 01:04:30 +00:00
|
|
|
|
2016-04-22 05:06:24 +00:00
|
|
|
@admin.register(inventory.Product)
|
2016-03-31 01:04:30 +00:00
|
|
|
class ProductAdmin(admin.ModelAdmin):
|
2016-04-22 05:06:24 +00:00
|
|
|
model = inventory.Product
|
2016-03-31 01:04:30 +00:00
|
|
|
list_display = ("name", "category", "description")
|
|
|
|
list_filter = ("category", )
|
2016-01-22 05:01:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Discounts
|
|
|
|
|
|
|
|
class DiscountForProductInline(admin.TabularInline):
|
2016-04-22 05:06:24 +00:00
|
|
|
model = conditions.DiscountForProduct
|
2016-01-22 05:01:30 +00:00
|
|
|
verbose_name = _("Product included in discount")
|
|
|
|
verbose_name_plural = _("Products included in discount")
|
|
|
|
|
|
|
|
|
|
|
|
class DiscountForCategoryInline(admin.TabularInline):
|
2016-04-22 05:06:24 +00:00
|
|
|
model = conditions.DiscountForCategory
|
2016-01-22 05:01:30 +00:00
|
|
|
verbose_name = _("Category included in discount")
|
|
|
|
verbose_name_plural = _("Categories included in discount")
|
|
|
|
|
|
|
|
|
2016-04-22 05:06:24 +00:00
|
|
|
@admin.register(conditions.TimeOrStockLimitDiscount)
|
2016-03-31 01:04:30 +00:00
|
|
|
class TimeOrStockLimitDiscountAdmin(admin.ModelAdmin, EffectsDisplayMixin):
|
|
|
|
list_display = (
|
|
|
|
"description",
|
|
|
|
"start_time",
|
|
|
|
"end_time",
|
|
|
|
"limit",
|
|
|
|
"effects",
|
|
|
|
)
|
|
|
|
ordering = ("start_time", "end_time", "limit")
|
|
|
|
|
|
|
|
inlines = [
|
|
|
|
DiscountForProductInline,
|
|
|
|
DiscountForCategoryInline,
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-04-22 05:06:24 +00:00
|
|
|
@admin.register(conditions.IncludedProductDiscount)
|
2016-09-04 04:21:30 +00:00
|
|
|
class IncludedProductDiscountAdmin(admin.ModelAdmin, EffectsDisplayMixin):
|
2016-03-31 01:04:30 +00:00
|
|
|
|
|
|
|
def enablers(self, obj):
|
|
|
|
return list(obj.enabling_products.all())
|
|
|
|
|
|
|
|
list_display = ("description", "enablers", "effects")
|
|
|
|
|
2016-01-22 05:01:30 +00:00
|
|
|
inlines = [
|
|
|
|
DiscountForProductInline,
|
|
|
|
DiscountForCategoryInline,
|
|
|
|
]
|
|
|
|
|
2016-09-04 04:21:30 +00:00
|
|
|
@admin.register(conditions.SpeakerDiscount)
|
|
|
|
class SpeakerDiscountAdmin(admin.ModelAdmin, EffectsDisplayMixin):
|
|
|
|
|
|
|
|
fields = ("description", "is_presenter", "is_copresenter", "proposal_kind")
|
|
|
|
|
|
|
|
list_display = ("description", "is_presenter", "is_copresenter", "effects")
|
|
|
|
|
|
|
|
ordering = ("-is_presenter", "-is_copresenter")
|
|
|
|
|
|
|
|
inlines = [
|
|
|
|
DiscountForProductInline,
|
|
|
|
DiscountForCategoryInline,
|
|
|
|
]
|
|
|
|
|
2016-01-22 05:01:30 +00:00
|
|
|
|
2016-09-05 00:48:38 +00:00
|
|
|
@admin.register(conditions.GroupMemberDiscount)
|
|
|
|
class GroupMemberDiscountAdmin(admin.ModelAdmin, EffectsDisplayMixin):
|
|
|
|
|
|
|
|
fields = ("description", "group")
|
|
|
|
|
|
|
|
list_display = ("description", "effects")
|
|
|
|
|
|
|
|
inlines = [
|
|
|
|
DiscountForProductInline,
|
|
|
|
DiscountForCategoryInline,
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-01-22 05:01:30 +00:00
|
|
|
# Vouchers
|
|
|
|
|
|
|
|
class VoucherDiscountInline(nested_admin.NestedStackedInline):
|
2016-04-22 05:06:24 +00:00
|
|
|
model = conditions.VoucherDiscount
|
2016-01-22 05:01:30 +00:00
|
|
|
verbose_name = _("Discount")
|
|
|
|
|
|
|
|
# TODO work out why we're allowed to add more than one?
|
|
|
|
max_num = 1
|
|
|
|
extra = 1
|
|
|
|
inlines = [
|
|
|
|
DiscountForProductInline,
|
|
|
|
DiscountForCategoryInline,
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-04-11 07:55:00 +00:00
|
|
|
class VoucherFlagInline(nested_admin.NestedStackedInline):
|
2016-04-22 05:06:24 +00:00
|
|
|
model = conditions.VoucherFlag
|
2016-01-22 05:01:30 +00:00
|
|
|
verbose_name = _("Product and category enabled by voucher")
|
|
|
|
verbose_name_plural = _("Products and categories enabled by voucher")
|
|
|
|
|
|
|
|
# TODO work out why we're allowed to add more than one?
|
|
|
|
max_num = 1
|
|
|
|
extra = 1
|
|
|
|
|
|
|
|
|
2016-04-22 05:06:24 +00:00
|
|
|
@admin.register(inventory.Voucher)
|
2016-01-22 05:01:30 +00:00
|
|
|
class VoucherAdmin(nested_admin.NestedAdmin):
|
2016-03-31 01:04:30 +00:00
|
|
|
|
|
|
|
def effects(self, obj):
|
|
|
|
''' List the effects of the voucher in the admin. '''
|
|
|
|
out = []
|
|
|
|
|
|
|
|
try:
|
|
|
|
discount_effects = obj.voucherdiscount.effects()
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
discount_effects = None
|
|
|
|
|
|
|
|
try:
|
2016-04-11 07:55:00 +00:00
|
|
|
enabling_effects = obj.voucherflag.effects()
|
2016-03-31 01:04:30 +00:00
|
|
|
except ObjectDoesNotExist:
|
|
|
|
enabling_effects = None
|
|
|
|
|
|
|
|
if discount_effects:
|
|
|
|
out.append("Discounts: " + str(list(discount_effects)))
|
|
|
|
if enabling_effects:
|
|
|
|
out.append("Enables: " + str(list(enabling_effects)))
|
|
|
|
|
|
|
|
return "\n".join(out)
|
|
|
|
|
2016-04-22 05:06:24 +00:00
|
|
|
model = inventory.Voucher
|
2016-03-31 01:04:30 +00:00
|
|
|
list_display = ("recipient", "code", "effects")
|
2016-01-22 05:01:30 +00:00
|
|
|
inlines = [
|
|
|
|
VoucherDiscountInline,
|
2016-04-11 07:55:00 +00:00
|
|
|
VoucherFlagInline,
|
2016-01-22 05:01:30 +00:00
|
|
|
]
|
2016-03-04 22:28:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Enabling conditions
|
2016-04-22 05:06:24 +00:00
|
|
|
@admin.register(conditions.ProductFlag)
|
2016-04-11 07:55:00 +00:00
|
|
|
class ProductFlagAdmin(
|
2016-03-31 01:04:30 +00:00
|
|
|
nested_admin.NestedAdmin,
|
|
|
|
EffectsDisplayMixin):
|
|
|
|
|
|
|
|
def enablers(self, obj):
|
|
|
|
return list(obj.enabling_products.all())
|
|
|
|
|
2016-04-22 05:06:24 +00:00
|
|
|
model = conditions.ProductFlag
|
2016-04-12 01:43:38 +00:00
|
|
|
fields = ("description", "enabling_products", "condition", "products",
|
2016-03-31 01:04:30 +00:00
|
|
|
"categories"),
|
|
|
|
|
|
|
|
list_display = ("description", "enablers", "effects")
|
2016-03-04 22:28:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Enabling conditions
|
2016-04-22 05:06:24 +00:00
|
|
|
@admin.register(conditions.CategoryFlag)
|
2016-04-11 07:55:00 +00:00
|
|
|
class CategoryFlagAdmin(
|
2016-03-31 01:04:30 +00:00
|
|
|
nested_admin.NestedAdmin,
|
|
|
|
EffectsDisplayMixin):
|
|
|
|
|
2016-04-22 05:06:24 +00:00
|
|
|
model = conditions.CategoryFlag
|
2016-04-12 01:43:38 +00:00
|
|
|
fields = ("description", "enabling_category", "condition", "products",
|
2016-03-31 01:04:30 +00:00
|
|
|
"categories"),
|
|
|
|
|
|
|
|
list_display = ("description", "enabling_category", "effects")
|
|
|
|
ordering = ("enabling_category",)
|
|
|
|
|
|
|
|
|
2016-09-04 04:21:30 +00:00
|
|
|
@admin.register(conditions.SpeakerFlag)
|
|
|
|
class SpeakerFlagAdmin(nested_admin.NestedAdmin, EffectsDisplayMixin):
|
2016-03-31 01:04:30 +00:00
|
|
|
|
2016-09-04 04:21:30 +00:00
|
|
|
model = conditions.SpeakerFlag
|
|
|
|
fields = ("description", "is_presenter", "is_copresenter", "proposal_kind",
|
|
|
|
"products", "categories")
|
|
|
|
|
|
|
|
list_display = ("description", "is_presenter", "is_copresenter", "effects")
|
|
|
|
|
|
|
|
ordering = ("-is_presenter", "-is_copresenter")
|
2016-09-05 00:48:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(conditions.GroupMemberFlag)
|
|
|
|
class GroupMemberFlagAdmin(admin.ModelAdmin, EffectsDisplayMixin):
|
|
|
|
|
|
|
|
fields = ("description", "group")
|
|
|
|
|
|
|
|
list_display = ("description", "effects")
|