-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.py
136 lines (105 loc) · 5.56 KB
/
models.py
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
import os
from os.path import join, getsize
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import slugify
from cms.models.pluginmodel import CMSPlugin
from appconf import AppConf
from .lib.choices import (
DynamicTemplateChoices,
DynamicChoice, )
STATIC_URL = getattr(settings, "STATIC_URL", '/static')
STATIC_ROOT = getattr(settings, "STATIC_ROOT", None)
MEDIA_URL = getattr(settings, "MEDIA_URL", '/media')
MEDIA_ROOT = getattr(settings, "MEDIA_ROOT", None)
class ApplicationSettings(AppConf):
TEMPLATE_BASE_PATH = __package__
PRODUCT_TYPE_CONTAINER_TEMPLATES = os.path.join(TEMPLATE_BASE_PATH, "product-types", 'containers')
PRODUCT_TYPE_ITEM_TEMPLATES = os.path.join(TEMPLATE_BASE_PATH, "product-types", 'items')
PRODUCT_CONTAINER_TEMPLATES = os.path.join(TEMPLATE_BASE_PATH, "product-list", 'containers')
PRODUCT_ITEM_TEMPLATES = os.path.join(TEMPLATE_BASE_PATH, "product-list", 'items')
DEFAULT_CATEGORY_IMAGE_URL = os.path.join(STATIC_URL, 'defaults', 'img',
'product-category', 'missing-icon-{0}.png')
CATEGORY_IMAGE_URL = '{0}/product-category'.format(MEDIA_URL)
CATEGORY_IMAGE_ROOT = '{0}/product-category'.format(MEDIA_ROOT)
class ProductTypeIcon(models.Model):
upload_path = lambda instance, filename: "files/product-category/{0}".format(
"{0}-{1}".format(slugify(instance.product_type), filename) )
# fields
name = models.CharField(max_length=128, default="small")
image = models.ImageField(upload_to=upload_path, blank=True, null=True)
product_type = models.ForeignKey('configurableproduct.ProductType',
related_name='icons', help_text="""The product type you want this icon
related to...""")
class Meta:
unique_together = ('product_type', 'name',)
class CProductTypesPlugin(CMSPlugin):
""" Stores options for cmsplugin that shows lists of ProductTypes
"""
DEFAULT_CONTAINER_TEMPLATE = os.path.join(ApplicationSettings.PRODUCT_TYPE_CONTAINER_TEMPLATES, "default.html")
DEFAULT_ITEM_TEMPLATE = os.path.join(ApplicationSettings.PRODUCT_TYPE_ITEM_TEMPLATES, "default.html")
title = models.CharField(max_length=128, default="Categories", null=True, blank=True)
categories = models.ManyToManyField('configurableproduct.ProductType',
blank=True, null=True,
help_text="""Restrict the output list to these selected categories.
if none are selected then all will be shown.""")
hide_empty_categories = models.BooleanField(default=True,
help_text="Hide product types that have no products?")
container_template = models.CharField(
default = ("Default", DEFAULT_CONTAINER_TEMPLATE) ,
max_length=256, blank=True, null=True,
choices=DynamicTemplateChoices(
path=ApplicationSettings.PRODUCT_TYPE_CONTAINER_TEMPLATES,
include='.html'),
help_text="""Select a template to render this
list. Templates are stored in : {0}""".format(ApplicationSettings.PRODUCT_TYPE_CONTAINER_TEMPLATES))
item_template = models.CharField(
default = ("Default", DEFAULT_ITEM_TEMPLATE) ,
max_length=256, blank=True, null=True,
choices=DynamicTemplateChoices(
path=ApplicationSettings.PRODUCT_TYPE_ITEM_TEMPLATES,
include='.html'),
help_text="""Select a template to render this
list. Templates are stored in : {0}""".format(ApplicationSettings.PRODUCT_TYPE_ITEM_TEMPLATES))
def __unicode__(self):
return U"Types: {0}".format(self.categories.all())
class CProductsPlugin(CMSPlugin):
""" Stores Options to display list of products from certain ProductTypes
"""
DEFAULT_CONTAINER_TEMPLATE = os.path.join(ApplicationSettings.PRODUCT_CONTAINER_TEMPLATES, "default.html")
DEFAULT_ITEM_TEMPLATE = os.path.join(ApplicationSettings.PRODUCT_ITEM_TEMPLATES, "default.html")
FILTER_ACTIONS = (
("show", "Filter"),
("hide", "Exclude")
)
categories = models.ManyToManyField('configurableproduct.ProductType',
help_text="""Restrict the output list to these selected categories.
if none are selected then all will be shown.""")
hide_empty_categories = models.BooleanField(default=True)
filter_product_attributes = models.CharField(max_length=256,
blank=True, null=True,
help_text="""Comma separated list of product
field names and values to check for. ie :
on_sale, is_preorder, holds_litres""")
filter_action = models.CharField(max_length=32,
blank=True, null=True, choices = FILTER_ACTIONS,
help_text="How to treat the filter verbs?")
container_template = models.CharField(
default = ("Default", DEFAULT_CONTAINER_TEMPLATE) ,
max_length=256, blank=True, null=True,
choices=DynamicTemplateChoices(
path=ApplicationSettings.PRODUCT_TYPE_CONTAINER_TEMPLATES,
include='.html'),
help_text="""Select a template to render this
list. Templates are stored in : {0}""".format(ApplicationSettings.PRODUCT_CONTAINER_TEMPLATES))
item_template = models.CharField(
default = ("Default", DEFAULT_ITEM_TEMPLATE) ,
max_length=256, blank=True, null=True,
choices=DynamicTemplateChoices(
path=ApplicationSettings.PRODUCT_ITEM_TEMPLATES,
include='.html'),
help_text="""Select a template to render this
list. Templates are stored in : {0}""".format(ApplicationSettings.PRODUCT_ITEM_TEMPLATES))
def __unicode__(self):
return U"Types: {0}".format(",".join([ ctype.name for ctype in self.categories.all()]))