-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanufacturers_views.py
76 lines (59 loc) · 2.57 KB
/
manufacturers_views.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
# -*- coding: UTF-8 -*-
# Copyright (C) 2009 Sylvain Taverne <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import from standard library
from operator import itemgetter
# Import from itools
from itools.gettext import MSG
from itools.datatypes import Unicode, String
from itools.web import STLView
from itools.xapian import AndQuery, PhraseQuery
# Import from here
from utils import get_skin_template
class Manufacturers_View(STLView):
access = True
title = MSG(u'View')
def get_template(self, resource, context):
return get_skin_template(context, 'manufacturers_view.xml')
def get_namespace(self, resource, context):
from manufacturers import Manufacturer
namespace = {'manufacturers': [],
'title': resource.get_title()}
for resource in resource.search_resources(cls=Manufacturer):
namespace['manufacturers'].append(
{'name': resource.name,
'title': resource.get_title()})
namespace['manufacturers'].sort(key=itemgetter('title'))
return namespace
class Manufacturer_View(STLView):
access = True
title = MSG(u'View')
def get_template(self, resource, context):
return get_skin_template(context, 'manufacturer_view.xml')
def get_namespace(self, resource, context):
root = context.root
products = []
abspath = str(resource.get_abspath())
query = AndQuery(PhraseQuery('format', 'product'),
PhraseQuery('manufacturer', abspath),
PhraseQuery('workflow_state', 'public'))
results = root.search(query)
for result in results.get_documents():
product = root.get_resource(result.abspath)
products.append(product.viewbox.GET(product, context))
return {'title': resource.get_title(),
'data': resource.get_property('data'),
'photo': resource.get_property('photo'),
'products': products}