Files
@ e9ebf5da03ea
Branch filter:
Location: symposion_app/registrasion/admin.py
e9ebf5da03ea
4.8 KiB
text/x-python
Writes inventory and overview documentation, and updates docstrings on a LOT of modules.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | from django.contrib import admin
from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import ugettext_lazy as _
import nested_admin
from registrasion.models import conditions
from registrasion.models import inventory
class EffectsDisplayMixin(object):
def effects(self, obj):
return list(obj.effects())
# Inventory admin
class ProductInline(admin.TabularInline):
model = inventory.Product
@admin.register(inventory.Category)
class CategoryAdmin(admin.ModelAdmin):
model = inventory.Category
fields = ("name", "description", "required", "render_type",
"limit_per_user", "order",)
list_display = ("name", "description")
inlines = [
ProductInline,
]
@admin.register(inventory.Product)
class ProductAdmin(admin.ModelAdmin):
model = inventory.Product
list_display = ("name", "category", "description")
list_filter = ("category", )
# Discounts
class DiscountForProductInline(admin.TabularInline):
model = conditions.DiscountForProduct
verbose_name = _("Product included in discount")
verbose_name_plural = _("Products included in discount")
class DiscountForCategoryInline(admin.TabularInline):
model = conditions.DiscountForCategory
verbose_name = _("Category included in discount")
verbose_name_plural = _("Categories included in discount")
@admin.register(conditions.TimeOrStockLimitDiscount)
class TimeOrStockLimitDiscountAdmin(admin.ModelAdmin, EffectsDisplayMixin):
list_display = (
"description",
"start_time",
"end_time",
"limit",
"effects",
)
ordering = ("start_time", "end_time", "limit")
inlines = [
DiscountForProductInline,
DiscountForCategoryInline,
]
@admin.register(conditions.IncludedProductDiscount)
class IncludedProductDiscountAdmin(admin.ModelAdmin):
def enablers(self, obj):
return list(obj.enabling_products.all())
def effects(self, obj):
return list(obj.effects())
list_display = ("description", "enablers", "effects")
inlines = [
DiscountForProductInline,
DiscountForCategoryInline,
]
# Vouchers
class VoucherDiscountInline(nested_admin.NestedStackedInline):
model = conditions.VoucherDiscount
verbose_name = _("Discount")
# TODO work out why we're allowed to add more than one?
max_num = 1
extra = 1
inlines = [
DiscountForProductInline,
DiscountForCategoryInline,
]
class VoucherFlagInline(nested_admin.NestedStackedInline):
model = conditions.VoucherFlag
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
@admin.register(inventory.Voucher)
class VoucherAdmin(nested_admin.NestedAdmin):
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:
enabling_effects = obj.voucherflag.effects()
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)
model = inventory.Voucher
list_display = ("recipient", "code", "effects")
inlines = [
VoucherDiscountInline,
VoucherFlagInline,
]
# Enabling conditions
@admin.register(conditions.ProductFlag)
class ProductFlagAdmin(
nested_admin.NestedAdmin,
EffectsDisplayMixin):
def enablers(self, obj):
return list(obj.enabling_products.all())
model = conditions.ProductFlag
fields = ("description", "enabling_products", "condition", "products",
"categories"),
list_display = ("description", "enablers", "effects")
# Enabling conditions
@admin.register(conditions.CategoryFlag)
class CategoryFlagAdmin(
nested_admin.NestedAdmin,
EffectsDisplayMixin):
model = conditions.CategoryFlag
fields = ("description", "enabling_category", "condition", "products",
"categories"),
list_display = ("description", "enabling_category", "effects")
ordering = ("enabling_category",)
# Enabling conditions
@admin.register(conditions.TimeOrStockLimitFlag)
class TimeOrStockLimitFlagAdmin(
nested_admin.NestedAdmin,
EffectsDisplayMixin):
model = conditions.TimeOrStockLimitFlag
list_display = (
"description",
"start_time",
"end_time",
"limit",
"effects",
)
ordering = ("start_time", "end_time", "limit")
|