1 |
6f1fb6bd
|
Frédéric Péters
|
from quixote import get_request, get_publisher, get_response
|
2 |
|
|
from quixote.html import htmltext
|
3 |
c2ffbce0
|
Frédéric Péters
|
|
4 |
b1c812cb
|
Frédéric Péters
|
from qommon import template
|
5 |
01908fa1
|
Frédéric Péters
|
from qommon.admin.texts import TextsDirectory
|
6 |
c2ffbce0
|
Frédéric Péters
|
from wcs.categories import Category
|
7 |
|
|
|
8 |
|
|
wcs_decorate = template.decorate
|
9 |
6f1fb6bd
|
Frédéric Péters
|
wcs_error_page = template.error_page
|
10 |
c2ffbce0
|
Frédéric Péters
|
|
11 |
|
|
def decorate(body, response):
|
12 |
|
|
body = str(body)
|
13 |
|
|
|
14 |
b7a2808c
|
Frédéric Péters
|
for key in ('bigdiv', 'gauche'):
|
15 |
|
|
if not response.filter.has_key(key):
|
16 |
|
|
response.filter[key] = None
|
17 |
|
|
|
18 |
6a703f5c
|
Frédéric Péters
|
root_url = get_publisher().get_root_url()
|
19 |
|
|
wcs_path = get_request().get_path()[len(root_url):]
|
20 |
|
|
section = wcs_path.split('/')[0]
|
21 |
|
|
|
22 |
|
|
if section in ('backoffice', 'admin'):
|
23 |
c3773788
|
Frédéric Péters
|
return wcs_decorate(body, response)
|
24 |
c2ffbce0
|
Frédéric Péters
|
|
25 |
|
|
section_title = ''
|
26 |
|
|
page_title = response.filter.get('title')
|
27 |
01908fa1
|
Frédéric Péters
|
if 'error-page' in response.filter:
|
28 |
|
|
pass
|
29 |
|
|
elif section == 'consultations':
|
30 |
c2ffbce0
|
Frédéric Péters
|
section_title = '<h2 id="consultations">%s</h2>\n' % _('Consultations')
|
31 |
b7a2808c
|
Frédéric Péters
|
response.filter['bigdiv'] = 'rub_consultation'
|
32 |
6a703f5c
|
Frédéric Péters
|
elif section == 'announces':
|
33 |
b7a2808c
|
Frédéric Péters
|
response.filter['bigdiv'] = 'rub_annonce'
|
34 |
c2ffbce0
|
Frédéric Péters
|
section_title = '<h2 id="announces">%s</h2>\n' % _('Announces to citizens')
|
35 |
8d66bd48
|
Frédéric Péters
|
if page_title == _('Announces to citizens'):
|
36 |
|
|
page_title = ''
|
37 |
6a703f5c
|
Frédéric Péters
|
elif section == 'agenda':
|
38 |
fa229320
|
Frédéric Péters
|
response.filter['bigdiv'] = 'rub_agenda'
|
39 |
d571c185
|
Frédéric Péters
|
section_title = '<h2 id="agenda">%s</h2>\n' % _('Agenda')
|
40 |
|
|
if page_title == _('Agenda'):
|
41 |
|
|
page_title = ''
|
42 |
c2ffbce0
|
Frédéric Péters
|
elif section and len(section) > 1:
|
43 |
|
|
# XXX: this works but is not efficient
|
44 |
175cb67b
|
Frédéric Péters
|
if Category.has_urlname(section):
|
45 |
c2ffbce0
|
Frédéric Péters
|
section_title = '<h2 id="services">%s</h2>\n' % _('Services')
|
46 |
b7a2808c
|
Frédéric Péters
|
response.filter['bigdiv'] = 'rub_service'
|
47 |
c2ffbce0
|
Frédéric Péters
|
|
48 |
6f1fb6bd
|
Frédéric Péters
|
if not 'auquotidien-no-titles-in-section' in response.filter.get('keywords', []):
|
49 |
28b7b336
|
Frédéric Péters
|
if page_title:
|
50 |
|
|
if section_title:
|
51 |
|
|
page_title = '<h3>%s</h3>' % page_title
|
52 |
|
|
else:
|
53 |
|
|
page_title = '<h2 id="info">%s</h2>' % page_title
|
54 |
c2ffbce0
|
Frédéric Péters
|
else:
|
55 |
28b7b336
|
Frédéric Péters
|
page_title = ''
|
56 |
c2ffbce0
|
Frédéric Péters
|
|
57 |
28b7b336
|
Frédéric Péters
|
body = '\n'.join((section_title, page_title, body))
|
58 |
c2ffbce0
|
Frédéric Péters
|
|
59 |
930d9990
|
Frédéric Péters
|
if hasattr(response, 'breadcrumb') and response.breadcrumb:
|
60 |
|
|
if len(response.breadcrumb) == 1:
|
61 |
|
|
response.breadcrumb = None
|
62 |
|
|
|
63 |
c2ffbce0
|
Frédéric Péters
|
return wcs_decorate(body, response)
|
64 |
|
|
|
65 |
|
|
|
66 |
6f1fb6bd
|
Frédéric Péters
|
def error_page(*args, **kwargs):
|
67 |
01908fa1
|
Frédéric Péters
|
get_response().filter = {}
|
68 |
|
|
get_response().filter['error-page'] = None
|
69 |
6f1fb6bd
|
Frédéric Péters
|
get_response().filter['keywords'] = template.get_current_theme().get('keywords')
|
70 |
|
|
get_response().filter['title'] = template.get_current_theme().get('keywords')
|
71 |
01908fa1
|
Frédéric Péters
|
get_response().filter['gauche'] = TextsDirectory.get_html_text('aq-error-assistance')
|
72 |
6f1fb6bd
|
Frédéric Péters
|
error_page = wcs_error_page(*args, **kwargs)
|
73 |
|
|
title = get_response().filter['title']
|
74 |
|
|
get_response().filter['title'] = None
|
75 |
|
|
return htmltext('<div id="info"><h2>%s</h2>' % title) + error_page + htmltext('</div>')
|
76 |
|
|
|
77 |
|
|
template.decorate = decorate
|
78 |
|
|
template.error_page = error_page
|
79 |
01908fa1
|
Frédéric Péters
|
|
80 |
|
|
|
81 |
|
|
TextsDirectory.register('aq-error-assistance', N_('Assistance text next to errors'))
|