1
|
from quixote import get_request, get_publisher, get_response
|
2
|
from quixote.html import htmltext
|
3
|
|
4
|
from qommon import template
|
5
|
from qommon.admin.texts import TextsDirectory
|
6
|
from wcs.categories import Category
|
7
|
|
8
|
wcs_decorate = template.decorate
|
9
|
wcs_error_page = template.error_page
|
10
|
|
11
|
def decorate(body, response):
|
12
|
body = str(body)
|
13
|
|
14
|
for key in ('bigdiv', 'gauche'):
|
15
|
if not response.filter.has_key(key):
|
16
|
response.filter[key] = None
|
17
|
|
18
|
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
|
return wcs_decorate(body, response)
|
24
|
|
25
|
section_title = ''
|
26
|
page_title = response.filter.get('title')
|
27
|
if 'error-page' in response.filter:
|
28
|
pass
|
29
|
elif section == 'consultations':
|
30
|
section_title = '<h2 id="consultations">%s</h2>\n' % _('Consultations')
|
31
|
response.filter['bigdiv'] = 'rub_consultation'
|
32
|
elif section == 'announces':
|
33
|
response.filter['bigdiv'] = 'rub_annonce'
|
34
|
section_title = '<h2 id="announces">%s</h2>\n' % _('Announces to citizens')
|
35
|
if page_title == _('Announces to citizens'):
|
36
|
page_title = ''
|
37
|
elif section == 'agenda':
|
38
|
response.filter['bigdiv'] = 'rub_agenda'
|
39
|
section_title = '<h2 id="agenda">%s</h2>\n' % _('Agenda')
|
40
|
if page_title == _('Agenda'):
|
41
|
page_title = ''
|
42
|
elif section and len(section) > 1:
|
43
|
# XXX: this works but is not efficient
|
44
|
if Category.has_urlname(section):
|
45
|
section_title = '<h2 id="services">%s</h2>\n' % _('Services')
|
46
|
response.filter['bigdiv'] = 'rub_service'
|
47
|
|
48
|
if not 'auquotidien-no-titles-in-section' in response.filter.get('keywords', []):
|
49
|
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
|
else:
|
55
|
page_title = ''
|
56
|
|
57
|
body = '\n'.join((section_title, page_title, body))
|
58
|
|
59
|
if hasattr(response, 'breadcrumb') and response.breadcrumb:
|
60
|
if len(response.breadcrumb) == 1:
|
61
|
response.breadcrumb = None
|
62
|
|
63
|
return wcs_decorate(body, response)
|
64
|
|
65
|
|
66
|
def error_page(*args, **kwargs):
|
67
|
get_response().filter = {}
|
68
|
get_response().filter['error-page'] = None
|
69
|
get_response().filter['keywords'] = template.get_current_theme().get('keywords')
|
70
|
get_response().filter['title'] = template.get_current_theme().get('keywords')
|
71
|
get_response().filter['gauche'] = TextsDirectory.get_html_text('aq-error-assistance')
|
72
|
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
|
|
80
|
|
81
|
TextsDirectory.register('aq-error-assistance', N_('Assistance text next to errors'))
|