author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 21 Apr 2010 16:53:25 +0200 | |
branch | stable |
changeset 5367 | 4176a50c81c9 |
parent 5326 | 0d9054eb3bd1 |
child 5328 | c51e8f62652a |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
1 |
"""common web configuration for twisted/modpython instances |
0 | 2 |
|
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3642
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
2087 | 9 |
_ = unicode |
0 | 10 |
|
11 |
import os |
|
1132 | 12 |
from os.path import join, exists, split |
0 | 13 |
|
3642 | 14 |
from logilab.common.decorators import cached |
0 | 15 |
|
16 |
from cubicweb.toolsutils import read_config |
|
17 |
from cubicweb.cwconfig import CubicWebConfiguration, register_persistent_options, merge_options |
|
18 |
||
19 |
||
20 |
register_persistent_options( ( |
|
21 |
# site-wide only web ui configuration |
|
22 |
('site-title', |
|
23 |
{'type' : 'string', 'default': 'unset title', |
|
24 |
'help': _('site title'), |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
25 |
'sitewide': True, 'group': 'ui', |
0 | 26 |
}), |
27 |
('main-template', |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
447
diff
changeset
|
28 |
{'type' : 'string', 'default': 'main-template', |
0 | 29 |
'help': _('id of main template used to render pages'), |
30 |
'sitewide': True, 'group': 'ui', |
|
31 |
}), |
|
32 |
# user web ui configuration |
|
33 |
('fckeditor', |
|
34 |
{'type' : 'yn', 'default': True, |
|
35 |
'help': _('should html fields being edited using fckeditor (a HTML ' |
|
36 |
'WYSIWYG editor). You should also select text/html as default ' |
|
37 |
'text format to actually get fckeditor.'), |
|
38 |
'group': 'ui', |
|
39 |
}), |
|
40 |
# navigation configuration |
|
41 |
('page-size', |
|
42 |
{'type' : 'int', 'default': 40, |
|
43 |
'help': _('maximum number of objects displayed by page of results'), |
|
44 |
'group': 'navigation', |
|
45 |
}), |
|
46 |
('related-limit', |
|
47 |
{'type' : 'int', 'default': 8, |
|
48 |
'help': _('maximum number of related entities to display in the primary ' |
|
49 |
'view'), |
|
50 |
'group': 'navigation', |
|
51 |
}), |
|
52 |
('combobox-limit', |
|
53 |
{'type' : 'int', 'default': 20, |
|
54 |
'help': _('maximum number of entities to display in related combo box'), |
|
55 |
'group': 'navigation', |
|
56 |
}), |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
57 |
|
0 | 58 |
)) |
59 |
||
60 |
||
61 |
class WebConfiguration(CubicWebConfiguration): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
62 |
"""the WebConfiguration is a singleton object handling instance's |
0 | 63 |
configuration and preferences |
64 |
""" |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2552
diff
changeset
|
65 |
cubicweb_appobject_path = CubicWebConfiguration.cubicweb_appobject_path | set(['web/views']) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2552
diff
changeset
|
66 |
cube_appobject_path = CubicWebConfiguration.cube_appobject_path | set(['views']) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
67 |
|
0 | 68 |
options = merge_options(CubicWebConfiguration.options + ( |
69 |
('anonymous-user', |
|
70 |
{'type' : 'string', |
|
71 |
'default': None, |
|
72 |
'help': 'login of the CubicWeb user account to use for anonymous user (if you want to allow anonymous)', |
|
73 |
'group': 'main', 'inputlevel': 1, |
|
74 |
}), |
|
75 |
('anonymous-password', |
|
76 |
{'type' : 'string', |
|
77 |
'default': None, |
|
78 |
'help': 'password of the CubicWeb user account to use for anonymous user, ' |
|
79 |
'if anonymous-user is set', |
|
80 |
'group': 'main', 'inputlevel': 1, |
|
81 |
}), |
|
82 |
('query-log-file', |
|
83 |
{'type' : 'string', |
|
84 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
85 |
'help': 'web instance query log file', |
0 | 86 |
'group': 'main', 'inputlevel': 2, |
87 |
}), |
|
88 |
# web configuration |
|
89 |
('https-url', |
|
90 |
{'type' : 'string', |
|
91 |
'default': None, |
|
92 |
'help': 'web server root url on https. By specifying this option your '\ |
|
93 |
'site can be available as an http and https site. Authenticated users '\ |
|
94 |
'will in this case be authenticated and once done navigate through the '\ |
|
95 |
'https site. IMPORTANTE NOTE: to do this work, you should have your '\ |
|
96 |
'apache redirection include "https" as base url path so cubicweb can '\ |
|
97 |
'differentiate between http vs https access. For instance: \n'\ |
|
98 |
'RewriteRule ^/demo/(.*) http://127.0.0.1:8080/https/$1 [L,P]\n'\ |
|
99 |
'where the cubicweb web server is listening on port 8080.', |
|
100 |
'group': 'main', 'inputlevel': 2, |
|
101 |
}), |
|
102 |
('auth-mode', |
|
103 |
{'type' : 'choice', |
|
104 |
'choices' : ('cookie', 'http'), |
|
105 |
'default': 'cookie', |
|
106 |
'help': 'authentication mode (cookie / http)', |
|
107 |
'group': 'web', 'inputlevel': 1, |
|
108 |
}), |
|
109 |
('realm', |
|
110 |
{'type' : 'string', |
|
111 |
'default': 'cubicweb', |
|
112 |
'help': 'realm to use on HTTP authentication mode', |
|
113 |
'group': 'web', 'inputlevel': 2, |
|
114 |
}), |
|
115 |
('http-session-time', |
|
5326
0d9054eb3bd1
[config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5283
diff
changeset
|
116 |
{'type' : 'time', |
0 | 117 |
'default': 0, |
5326
0d9054eb3bd1
[config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5283
diff
changeset
|
118 |
'help': "duration of the cookie used to store session identifier. " |
0d9054eb3bd1
[config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5283
diff
changeset
|
119 |
"If 0, the cookie will expire when the user exist its browser. " |
0d9054eb3bd1
[config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5283
diff
changeset
|
120 |
"Should be 0 or greater than repository\'s session-time.", |
0 | 121 |
'group': 'web', 'inputlevel': 2, |
122 |
}), |
|
123 |
('cleanup-session-time', |
|
5326
0d9054eb3bd1
[config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5283
diff
changeset
|
124 |
{'type' : 'time', |
0d9054eb3bd1
[config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5283
diff
changeset
|
125 |
'default': '24h', |
0d9054eb3bd1
[config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5283
diff
changeset
|
126 |
'help': 'duration of inactivity after which a connection ' |
5283
9ad0eaa09d34
[config] better *-session-time documentation and usage in session handler
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5005
diff
changeset
|
127 |
'will be closed, to limit memory consumption (avoid sessions that ' |
9ad0eaa09d34
[config] better *-session-time documentation and usage in session handler
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5005
diff
changeset
|
128 |
'never expire and cause memory leak when http-session-time is 0). ' |
9ad0eaa09d34
[config] better *-session-time documentation and usage in session handler
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5005
diff
changeset
|
129 |
'So even if http-session-time is 0 and the user don\'t close his ' |
9ad0eaa09d34
[config] better *-session-time documentation and usage in session handler
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5005
diff
changeset
|
130 |
'browser, he will have to reauthenticate after this time of ' |
9ad0eaa09d34
[config] better *-session-time documentation and usage in session handler
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5005
diff
changeset
|
131 |
'inactivity. Default to 24h.', |
0 | 132 |
'group': 'web', 'inputlevel': 2, |
133 |
}), |
|
134 |
('cleanup-anonymous-session-time', |
|
5326
0d9054eb3bd1
[config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5283
diff
changeset
|
135 |
{'type' : 'time', |
0d9054eb3bd1
[config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5283
diff
changeset
|
136 |
'default': '5min', |
5283
9ad0eaa09d34
[config] better *-session-time documentation and usage in session handler
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5005
diff
changeset
|
137 |
'help': 'Same as cleanup-session-time but specific to anonymous ' |
9ad0eaa09d34
[config] better *-session-time documentation and usage in session handler
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5005
diff
changeset
|
138 |
'sessions. You can have a much smaller timeout here since it will be ' |
9ad0eaa09d34
[config] better *-session-time documentation and usage in session handler
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5005
diff
changeset
|
139 |
'transparent to the user. Default to 5min.', |
0 | 140 |
'group': 'web', 'inputlevel': 2, |
141 |
}), |
|
2552
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
142 |
('force-html-content-type', |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
143 |
{'type' : 'yn', |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
144 |
'default': False, |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
145 |
'help': 'force text/html content type for your html pages instead of cubicweb user-agent based'\ |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
146 |
'deduction of an appropriate content type', |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
147 |
'group': 'web', 'inputlevel': 2, |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
148 |
}), |
0 | 149 |
('embed-allowed', |
150 |
{'type' : 'regexp', |
|
151 |
'default': None, |
|
152 |
'help': 'regular expression matching URLs that may be embeded. \ |
|
153 |
leave it blank if you don\'t want the embedding feature, or set it to ".*" \ |
|
154 |
if you want to allow everything', |
|
155 |
'group': 'web', 'inputlevel': 1, |
|
156 |
}), |
|
157 |
('submit-mail', |
|
158 |
{'type' : 'string', |
|
159 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
160 |
'help': ('Mail used as recipient to report bug in this instance, ' |
0 | 161 |
'if you want this feature on'), |
162 |
'group': 'web', 'inputlevel': 2, |
|
163 |
}), |
|
164 |
||
165 |
('language-negociation', |
|
166 |
{'type' : 'yn', |
|
167 |
'default': True, |
|
168 |
'help': 'use Accept-Language http header to try to set user '\ |
|
169 |
'interface\'s language according to browser defined preferences', |
|
170 |
'group': 'web', 'inputlevel': 2, |
|
171 |
}), |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
172 |
|
0 | 173 |
('print-traceback', |
174 |
{'type' : 'yn', |
|
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
175 |
'default': CubicWebConfiguration.mode != 'system', |
0 | 176 |
'help': 'print the traceback on the error page when an error occured', |
177 |
'group': 'web', 'inputlevel': 2, |
|
178 |
}), |
|
4595
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
179 |
|
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
180 |
('captcha-font-file', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
181 |
{'type' : 'string', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
182 |
'default': join(CubicWebConfiguration.shared_dir(), 'data', 'porkys.ttf'), |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
183 |
'help': 'True type font to use for captcha image generation (you \ |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
184 |
must have the python imaging library installed to use captcha)', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
185 |
'group': 'web', 'inputlevel': 2, |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
186 |
}), |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
187 |
('captcha-font-size', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
188 |
{'type' : 'int', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
189 |
'default': 25, |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
190 |
'help': 'Font size to use for captcha image generation (you must \ |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
191 |
have the python imaging library installed to use captcha)', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
192 |
'group': 'web', 'inputlevel': 2, |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
193 |
}), |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
194 |
|
0 | 195 |
)) |
196 |
||
890
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
197 |
def fckeditor_installed(self): |
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
198 |
return exists(self.ext_resources['FCKEDITOR_PATH']) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
199 |
|
890
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
200 |
def eproperty_definitions(self): |
893 | 201 |
for key, pdef in super(WebConfiguration, self).eproperty_definitions(): |
890
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
202 |
if key == 'ui.fckeditor' and not self.fckeditor_installed(): |
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
203 |
continue |
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
204 |
yield key, pdef |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
205 |
|
0 | 206 |
# method used to connect to the repository: 'inmemory' / 'pyro' |
207 |
# Pyro repository by default |
|
208 |
repo_method = 'pyro' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
209 |
|
0 | 210 |
# don't use @cached: we want to be able to disable it while this must still |
211 |
# be cached |
|
212 |
def repository(self, vreg=None): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
213 |
"""return the instance's repository object""" |
0 | 214 |
try: |
215 |
return self.__repo |
|
216 |
except AttributeError: |
|
217 |
from cubicweb.dbapi import get_repository |
|
218 |
if self.repo_method == 'inmemory': |
|
219 |
repo = get_repository('inmemory', vreg=vreg, config=self) |
|
220 |
else: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
221 |
repo = get_repository('pyro', self['pyro-instance-id'], |
0 | 222 |
config=self) |
223 |
self.__repo = repo |
|
224 |
return repo |
|
225 |
||
226 |
def vc_config(self): |
|
227 |
return self.repository().get_versions() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
228 |
|
0 | 229 |
# mapping to external resources (id -> path) (`external_resources` file) ## |
230 |
ext_resources = { |
|
231 |
'FAVICON': 'DATADIR/favicon.ico', |
|
232 |
'LOGO': 'DATADIR/logo.png', |
|
233 |
'RSS_LOGO': 'DATADIR/rss.png', |
|
234 |
'HELP': 'DATADIR/help.png', |
|
235 |
'CALENDAR_ICON': 'DATADIR/calendar.gif', |
|
236 |
'SEARCH_GO':'DATADIR/go.png', |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
237 |
|
0 | 238 |
'FCKEDITOR_PATH': '/usr/share/fckeditor/', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
239 |
|
0 | 240 |
'IE_STYLESHEETS': ['DATADIR/cubicweb.ie.css'], |
241 |
'STYLESHEETS': ['DATADIR/cubicweb.css'], |
|
242 |
'STYLESHEETS_PRINT': ['DATADIR/cubicweb.print.css'], |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
243 |
|
0 | 244 |
'JAVASCRIPTS': ['DATADIR/jquery.js', |
30
25ef1dddaab8
round corners are back
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
245 |
'DATADIR/jquery.corner.js', |
25ef1dddaab8
round corners are back
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
246 |
'DATADIR/jquery.json.js', |
0 | 247 |
'DATADIR/cubicweb.compat.js', |
248 |
'DATADIR/cubicweb.python.js', |
|
249 |
'DATADIR/cubicweb.htmlhelpers.js'], |
|
250 |
} |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
251 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
252 |
|
0 | 253 |
def anonymous_user(self): |
254 |
"""return a login and password to use for anonymous users. None |
|
255 |
may be returned for both if anonymous connections are not allowed |
|
256 |
""" |
|
257 |
try: |
|
258 |
user = self['anonymous-user'] |
|
259 |
passwd = self['anonymous-password'] |
|
260 |
except KeyError: |
|
261 |
user, passwd = None, None |
|
262 |
if user is not None: |
|
263 |
user = unicode(user) |
|
264 |
return user, passwd |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
265 |
|
0 | 266 |
def has_resource(self, rid): |
267 |
"""return true if an external resource is defined""" |
|
268 |
return bool(self.ext_resources.get(rid)) |
|
269 |
||
270 |
@cached |
|
271 |
def locate_resource(self, rid): |
|
272 |
"""return the directory where the given resource may be found""" |
|
273 |
return self._fs_locate(rid, 'data') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
274 |
|
0 | 275 |
@cached |
276 |
def locate_doc_file(self, fname): |
|
277 |
"""return the directory where the given resource may be found""" |
|
278 |
return self._fs_locate(fname, 'wdoc') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
279 |
|
0 | 280 |
def _fs_locate(self, rid, rdirectory): |
281 |
"""return the directory where the given resource may be found""" |
|
282 |
path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
|
283 |
for directory in path: |
|
284 |
if exists(join(directory, rdirectory, rid)): |
|
285 |
return join(directory, rdirectory) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
286 |
|
0 | 287 |
def locate_all_files(self, rid, rdirectory='wdoc'): |
288 |
"""return all files corresponding to the given resource""" |
|
289 |
path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
|
290 |
for directory in path: |
|
291 |
fpath = join(directory, rdirectory, rid) |
|
292 |
if exists(fpath): |
|
293 |
yield join(fpath) |
|
294 |
||
295 |
def load_configuration(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
296 |
"""load instance's configuration files""" |
0 | 297 |
super(WebConfiguration, self).load_configuration() |
298 |
# load external resources definition |
|
299 |
self._build_ext_resources() |
|
300 |
self._init_base_url() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
301 |
|
0 | 302 |
def _init_base_url(self): |
303 |
# normalize base url(s) |
|
4909
a13c1d1ecc5b
[web server] simplify base-url handling on startup. Ensure config['base-url'] is correctly set once started
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
304 |
baseurl = self['base-url'] or self.default_base_url() |
0 | 305 |
if baseurl and baseurl[-1] != '/': |
306 |
baseurl += '/' |
|
5005
b04ec1b6f7da
don't rewrite config's url during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4909
diff
changeset
|
307 |
if not self.repairing: |
b04ec1b6f7da
don't rewrite config's url during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4909
diff
changeset
|
308 |
self.global_set_option('base-url', baseurl) |
0 | 309 |
httpsurl = self['https-url'] |
310 |
if httpsurl and httpsurl[-1] != '/': |
|
311 |
httpsurl += '/' |
|
5005
b04ec1b6f7da
don't rewrite config's url during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4909
diff
changeset
|
312 |
if not self.repairing: |
b04ec1b6f7da
don't rewrite config's url during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4909
diff
changeset
|
313 |
self.global_set_option('https-url', httpsurl) |
0 | 314 |
|
315 |
def _build_ext_resources(self): |
|
316 |
libresourcesfile = join(self.shared_dir(), 'data', 'external_resources') |
|
317 |
self.ext_resources.update(read_config(libresourcesfile)) |
|
318 |
for path in reversed([self.apphome] + self.cubes_path()): |
|
319 |
resourcesfile = join(path, 'data', 'external_resources') |
|
320 |
if exists(resourcesfile): |
|
321 |
self.debug('loading %s', resourcesfile) |
|
322 |
self.ext_resources.update(read_config(resourcesfile)) |
|
252
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
323 |
resourcesfile = join(self.apphome, 'external_resources') |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
324 |
if exists(resourcesfile): |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
325 |
self.debug('loading %s', resourcesfile) |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
326 |
self.ext_resources.update(read_config(resourcesfile)) |
0 | 327 |
for resource in ('STYLESHEETS', 'STYLESHEETS_PRINT', |
328 |
'IE_STYLESHEETS', 'JAVASCRIPTS'): |
|
329 |
val = self.ext_resources[resource] |
|
330 |
if isinstance(val, str): |
|
331 |
files = [w.strip() for w in val.split(',') if w.strip()] |
|
332 |
self.ext_resources[resource] = files |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
333 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
334 |
# static files handling ################################################### |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
335 |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
336 |
@property |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
337 |
def static_directory(self): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
338 |
return join(self.appdatahome, 'static') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
339 |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
340 |
def static_file_exists(self, rpath): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
341 |
return exists(join(self.static_directory, rpath)) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
342 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
343 |
def static_file_open(self, rpath, mode='wb'): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
344 |
staticdir = self.static_directory |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
345 |
rdir, filename = split(rpath) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
346 |
if rdir: |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
347 |
staticdir = join(staticdir, rdir) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
348 |
os.makedirs(staticdir) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
349 |
return file(join(staticdir, filename), mode) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
350 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
351 |
def static_file_add(self, rpath, data): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
352 |
stream = self.static_file_open(rpath) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
353 |
stream.write(data) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
354 |
stream.close() |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
355 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
356 |
def static_file_del(self, rpath): |
447 | 357 |
if self.static_file_exists(rpath): |
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
358 |
os.remove(join(self.static_directory, rpath)) |