-
Notifications
You must be signed in to change notification settings - Fork 8
/
admin.py
133 lines (121 loc) · 4.75 KB
/
admin.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
# coding : utf -8
# from flask.ext.htmlbuilder import html
# from flask.ext.admin.babel import lazy_gettext
from quokka import admin
from quokka.modules.posts.admin import PostAdmin
from quokka.core.admin.models import ModelAdmin
from quokka.utils.translation import _, _l
from quokka.core.widgets import TextEditor, PrepopulatedText
from .models import Cart, Processor
class ProductAdmin(PostAdmin):
column_list = ('title', 'slug', 'channel',
'unity_value', 'weight',
'published', 'created_at',
'available_at', 'view_on_site')
column_searchable_list = ['title', 'summary', 'description']
form_columns = [
'title', 'slug', 'channel', 'related_channels', 'summary',
'description', 'unity_value', 'weight', 'dimensions', 'extra_value',
'published', 'show_on_channel',
'available_at', 'available_until',
'tags', 'contents', 'values', 'template_type'
]
form_widget_args = {
'description': {
'rows': 20,
'cols': 20,
'class': 'text_editor',
'style': "margin: 0px; width: 725px; height: 360px;"
},
'summary': {
'style': 'width: 400px; height: 100px;'
},
'title': {'style': 'width: 400px'},
'slug': {'style': 'width: 400px'},
}
class CartAdmin(ModelAdmin):
roles_accepted = ('admin', 'editor')
column_filters = ('status', 'created_at', 'total', 'tax',
'reference_code', 'transaction_code')
column_searchable_list = ('transaction_code', 'checkout_code',
'reference_code', 'search_helper')
column_list = ("belongs_to", 'total', 'tax', 'status', 'created_at',
'processor',
"reference_code", 'items', 'published')
form_columns = ('created_at', 'belongs_to', 'processor', 'status',
'total', 'extra_costs', 'reference_code', 'checkout_code',
'sender_data', 'shipping_data', 'tax', 'shipping_cost',
'transaction_code',
# 'requires_login',
# 'continue_shopping_url', 'pipeline', 'config',
# 'items',
'payment', 'published')
form_subdocuments = {
'items': {
'form_subdocuments': {
None: {
'form_columns': ['uid', 'title', 'description',
'link', 'quantity', 'unity_value',
'total_value', 'weight', 'dimensions',
'extra_value']
}
}
}
}
column_formatters = {
'created_at': ModelAdmin.formatters.get('datetime'),
'available_at': ModelAdmin.formatters.get('datetime'),
'items': ModelAdmin.formatters.get('ul'),
'status': ModelAdmin.formatters.get('status'),
'reference_code': ModelAdmin.formatters.get('get_url')
}
column_formatters_args = {
'ul': {
'items': {
'placeholder': u"{item.title} - {item.total_value}",
'style': "min-width:200px;max-width:300px;"
}
},
'status': {
'status': {
'labels': {
'confirmed': 'success',
'checked_out': 'warning',
'cancelled': 'important',
'completed': 'success'
},
'style': 'min-height:18px;'
}
},
'get_url': {
'reference_code': {
'attribute': 'reference',
'method': 'get_admin_url'
}
}
}
def after_model_change(self, form, model, is_created):
if not is_created and model.reference:
model.reference.published = model.published
if model.tax:
model.set_reference_tax(float(model.tax))
model.reference.save()
class ProcessorAdmin(ModelAdmin):
roles_accepted = ('admin', 'developer')
column_list = ('identifier', 'title', 'module', 'published')
form_args = {
"description": {"widget": TextEditor()},
"identifier": {"widget": PrepopulatedText(master='title')}
}
form_columns = ('title', 'identifier', 'description', 'module',
'requires', 'image', 'link', 'config', 'pipeline',
'published')
form_ajax_refs = {
'image': {'fields': ['title', 'long_slug', 'summary']}
}
form_widget_args = {
'config': {'cols': 40, 'rows': 10, 'style': 'width:500px;'}
}
admin.register(Cart, CartAdmin, category=_("Cart"), name=_l("Cart"))
admin.register(Processor, ProcessorAdmin, category=_("Cart"),
name=_l("Processor"))