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