Révision 0f17ccab
Ajouté par Jérôme Schneider il y a environ 12 ans
mandaye/configs/biblio_vincennes.py | ||
---|---|---|
15 | 15 |
biblio_mapping = [ |
16 | 16 |
{ |
17 | 17 |
'path': r'/(?!/*mandaye)', |
18 |
'on_response': [{'filter': filters.resp_html}, |
|
18 |
'on_response': [ |
|
19 |
{ |
|
20 |
'filter': filters.resp_html, |
|
21 |
'content-types': ['application/x-javascript', 'text/html', 'text/css'], |
|
22 |
}, |
|
19 | 23 |
{ |
20 | 24 |
'filter': auth.auto_connection, |
21 | 25 |
'values': { |
... | ... | |
29 | 33 |
'path': r'/sezhame', |
30 | 34 |
'on_response': [{ |
31 | 35 |
'filter': filters.resp_multicompte_html, |
36 |
'content-types': ['text/html'], |
|
32 | 37 |
'values': { |
33 | 38 |
'associate_url': '/mandaye/associate', |
34 | 39 |
'template': 'biblio/multicompte.html', |
mandaye/configs/famille_vincennes.py | ||
---|---|---|
26 | 26 |
'method': 'GET', |
27 | 27 |
'on_response': [{ |
28 | 28 |
'filter': filters.resp_disassociate, |
29 |
'content-types': ['text/html'], |
|
29 | 30 |
'values': {'site_name': 'espace_famille'} |
30 | 31 |
}, |
31 | 32 |
{ |
... | ... | |
43 | 44 |
'path': r"/(?!.*/associate)", |
44 | 45 |
'on_response': [{ |
45 | 46 |
'filter': filters.resp_login_page, |
47 |
'content-types': ['text/html'], |
|
46 | 48 |
'values': { |
47 | 49 |
'connection_url': '/mandaye/connection', |
48 | 50 |
'template': 'famille/login.html', |
mandaye/dispatcher.py | ||
---|---|---|
62 | 62 |
def _parse_mapping(self, mapping): |
63 | 63 |
""" parse the mapping on every request |
64 | 64 |
""" |
65 |
req_mapping = {
|
|
65 |
req_mapping = { |
|
66 | 66 |
'on_request': [], |
67 | 67 |
'on_response': [], |
68 | 68 |
'response': None, |
... | ... | |
70 | 70 |
'redirect': None, |
71 | 71 |
} |
72 | 72 |
|
73 |
if not mapping: |
|
74 |
return req_mapping |
|
73 | 75 |
for mapper in mapping: |
74 | 76 |
if mapper.has_key('path'): |
75 | 77 |
if isinstance(mapper['path'], str): |
... | ... | |
165 | 167 |
|
166 | 168 |
# Calling hook function |
167 | 169 |
for hook in self.req_mapping['on_response']: |
170 |
if hook.has_key('content-types'): |
|
171 |
content_type = response.headers.getheader('content-type') |
|
172 |
if content_type not in hook['content-types']: |
|
173 |
logger.debug("Don't load filter %s (content-type %s doesn't match)" % (hook['filter'], content_type)) |
|
174 |
continue |
|
168 | 175 |
new_response = self._call_hook(hook, request, response) |
169 | 176 |
if new_response: |
170 | 177 |
response = new_response |
mandaye/filters/vincennes.py | ||
---|---|---|
88 | 88 |
""" Global html filter the Vincenne library |
89 | 89 |
This fix the fucking absolute url of the biblio site |
90 | 90 |
""" |
91 |
content_type = response.headers.getheader('content-type') |
|
92 |
if content_type and response.msg and \ |
|
93 |
('application/x-javascript' in content_type or \ |
|
94 |
'text/html' in content_type or \ |
|
95 |
'text/css'in content_type): |
|
91 |
if response.msg: |
|
96 | 92 |
response.msg = response.msg.replace(env["target"].geturl(), |
97 | 93 |
'%s://%s' % (env["mandaye.scheme"], env["HTTP_HOST"])) |
98 | 94 |
if env["mandaye.scheme"] == 'https': |
... | ... | |
116 | 112 |
def resp_multicompte_html(self, env, values, request, response): |
117 | 113 |
""" Modify response html to support multi accounts |
118 | 114 |
""" |
119 |
content_type = response.headers.getheader('content-type') |
|
120 |
if content_type and response.msg and 'text/html' in content_type and \ |
|
121 |
'<h2><div>Mon compte</div></h2>' in response.msg: |
|
115 |
if response.msg and '<h2><div>Mon compte</div></h2>' in response.msg: |
|
122 | 116 |
if env['beaker.session'].get('login'): |
123 | 117 |
current_account = get_current_account(env, values) |
124 | 118 |
template = get_multi_template(env, values, current_account) |
... | ... | |
153 | 147 |
def resp_login_page(self, env, values, request, response): |
154 | 148 |
""" Modify the login_page form |
155 | 149 |
""" |
156 |
content_type = response.headers.getheader('content-type') |
|
157 |
if response.msg and content_type and 'text/html' in content_type \ |
|
158 |
and '<!-- Bloc central > Bloc droite > Acc' in response.msg: |
|
150 |
if response.msg and \ |
|
151 |
'<!-- Bloc central > Bloc droite > Acc' in response.msg: |
|
159 | 152 |
login = serve_template(values.get('template'), **values) |
160 | 153 |
regexp = re.compile(r'(<!-- Bloc central > Bloc droite > Demandes -->)') |
161 | 154 |
sub = re.subn(regexp, |
... | ... | |
182 | 175 |
def resp_disassociate(self, env, values, resquest, response): |
183 | 176 |
""" Add a disassociation link |
184 | 177 |
""" |
185 |
content_type = response.headers.getheader('content-type') |
|
186 |
if content_type and response.msg and 'text/html' in content_type and \ |
|
178 |
if response.msg and\ |
|
187 | 179 |
'<!-- Navigation -->' in response.msg: |
188 | 180 |
login = env['beaker.session'].get('login') |
189 | 181 |
current_account = get_current_account(env, values) |
Formats disponibles : Unified diff
Fix #1278: Support content-types in on_response filters