-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebsite.py
162 lines (127 loc) · 5.3 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
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
# -*- 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 itools
from itools.core import merge_dicts
from itools.datatypes import Boolean
from itools.gettext import MSG
from itools.web import get_context
# Import from ikaaro
from ikaaro.registry import register_resource_class, register_document_type
from ikaaro.website import WebSite
from ikaaro.wiki import WikiFolder
# Import from itws
from itws.tracker import ITWSTracker
from itws.ws_neutral import NeutralWS
# Import from shop
from categories import Category
from datatypes import SkinsEnumerate
from manufacturers import Manufacturers
from search import ShopSearch
from shop import Shop
from shop_views import Shop_Register, Shop_Login
from shop_utils_views import Cart_Viewbox
from sidebar import CategorySidebar, ProductSidebar
from utils_views import RedirectPermanent
from website_views import ShopWebSite_View, ShopWS_SiteMap, ShopWS_RSS
from website_views import ShopWebSite_Edit
default_resources = {
'categories': (Category, {'title': {'en': u"Categories"}}),
'category-sidebar': (CategorySidebar, {'title': {'en': u'Category sidebar'}}),
'manufacturers': (Manufacturers, {'title': {'en': u"Manufacturers"}}),
'product-sidebar': (ProductSidebar, {'title': {'en': u'Product sidebar'}}),
'search': (ShopSearch, {'title': {'en': u'Search'}}),
'shop': (Shop, {'title': {'en': u'Shop'}, 'state':'public'}),
'tracker': (ITWSTracker, {}),
'wiki': (WikiFolder, {}),
}
class ShopWebSite(NeutralWS):
class_id = 'shop-website'
class_title = MSG(u'Shop website')
class_version = '20100712'
class_skin = '/ui/default_skin/'
__fixed_handlers__ = NeutralWS.__fixed_handlers__ + ['categories', 'shop']
# View
view = ShopWebSite_View()
edit = ShopWebSite_Edit()
sitemap = ShopWS_SiteMap()
product_search = RedirectPermanent(specific_document='search')
# Login views
register = Shop_Register()
login = Shop_Login()
unauthorized = Shop_Login()
# Compatibility
rss = last_news_rss = ShopWS_RSS()
# Shop configuration
shop_class = Shop
cart_preview_class = Cart_Viewbox
backoffice_rss_news_uri = None
backoffice_announce_uri = None
@staticmethod
def _make_resource(cls, folder, name, **kw):
root = get_context().resource
NeutralWS._make_resource(cls, folder, name, **kw)
website = root.get_resource(name)
# Languages (En and Fr)
metadata = website.metadata
metadata.set_property('website_languages', ('en', 'fr', ))
# Website is open
metadata.set_property('website_is_open', True)
# Default resources
for name2, (cls, kw) in default_resources.items():
cls._make_resource(cls, folder, '%s/%s' % (name, name2), **kw)
@classmethod
def get_metadata_schema(cls):
return merge_dicts(
NeutralWS.get_metadata_schema(),
hide_website_title_on_meta_title=Boolean,
class_skin=SkinsEnumerate,
class_skin_administrators=SkinsEnumerate)
def _get_catalog_values(self):
values = super(ShopWebSite, self)._get_catalog_values()
default_vhosts = ('shop', 'admin.shop',)
values['vhosts'] = self.get_property('vhosts') + default_vhosts
return values
def get_class_skin(self, context):
class_skin = self.get_property('class_skin')
if not class_skin:
return self.class_skin
ac = self.get_access_control()
if ac.is_admin(context.user, self):
return self.get_property('class_skin_administrators') or class_skin
return class_skin
def get_skin(self, context):
if context.get_query_value('is_admin_popup', type=Boolean) is True:
return self.get_resource('/ui/admin-popup/')
# Back-Office
hostname = context.uri.authority
if hostname[:6] == 'admin.' :
return self.get_resource('/ui/backoffice/')
# Front-Office
class_skin = self.get_class_skin(context)
skin = self.get_resource(class_skin, soft=True)
if skin is None:
skin = self.get_resource('/ui/default_skin/')
return skin
def is_allowed_to_view_for_authenticated(self, user, resource):
if (resource.has_property('must_be_authentificated') and
resource.get_property('must_be_authentificated')):
return self.is_authenticated(user, resource)
return self.is_allowed_to_view(user, resource)
register_resource_class(ShopWebSite)
register_document_type(ShopWebSite, WebSite.class_id)
# XXX Add a hack to change login page
from ikaaro.resource_ import DBResource
DBResource.login = Shop_Login()