forked from trytonus/nereid-webshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
website.py
111 lines (94 loc) · 3.12 KB
/
website.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
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from nereid import current_app, jsonify, render_template, request, route
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, Not
class Website(metaclass=PoolMeta):
__name__ = 'nereid.website'
cms_root_menu = fields.Many2One(
'nereid.cms.menuitem', "CMS root menu", ondelete='RESTRICT',
select=True,
)
show_site_message = fields.Boolean('Show Site Message')
site_message = fields.Char(
'Site Message',
states={
'readonly': Not(Eval('show_site_message', False)),
'required': Eval('show_site_message', False)
},
depends=['show_site_message']
)
copyright_year_range = fields.Char('Copyright Year Range')
cms_root_footer = fields.Many2One(
'nereid.cms.menuitem', "CMS root Footer", ondelete='RESTRICT',
select=True,
)
homepage_menu = fields.Many2One(
'nereid.cms.menuitem', "Homepage Menu", ondelete='RESTRICT',
select=True,
)
default_product_image = fields.Many2One("nereid.static.file",
'Default product image',
help='This image will be shown as a placeholder if no other '
'product image is found')
accept_gift_card = fields.Boolean('Accept Gift Card')
@classmethod
@route('/sitemap', methods=["GET"])
def render_sitemap(cls):
"""
Return the sitemap.
"""
Node = Pool().get('product.tree_node')
# Search for nodes, sort by sequence.
nodes = Node.search([
('parent', '=', None),
], order=[
('sequence', 'ASC'),
])
return render_template('sitemap.jinja', nodes=nodes)
@classmethod
def auto_complete(cls, phrase):
"""
Customizable method which returns a list of dictionaries
according to the search query. The search service used can
be modified in downstream modules.
The front-end expects a jsonified list of dictionaries. For example,
a downstream implementation of this method could return -:
[
...
{
"value": "<suggestion string>"
}, {
"value": "Nexus 6"
}
...
]
"""
return []
@classmethod
@route('/search-auto-complete')
def search_auto_complete(cls):
"""
Handler for auto-completing search.
"""
return jsonify(results=cls.auto_complete(
request.args.get('q', '')
))
@classmethod
@route('/search')
def quick_search(cls):
"""
Downstream implementation of quick_search().
TODO:
* Add article search.
"""
return super(Website, cls).quick_search()
@staticmethod
def default_cms_root_footer():
"""
Get default record from xml
"""
ModelData = Pool().get('ir.model.data')
menu_item_id = ModelData.get_id("nereid_webshop", "cms_root_footer")
return menu_item_id