1
|
from quixote import get_request, get_publisher, get_response
|
2
|
from qommon.publisher import get_publisher_class
|
3
|
from quixote.html import htmltext
|
4
|
|
5
|
from wcs.qommon import _, N_
|
6
|
from wcs.qommon import template
|
7
|
from wcs.qommon.admin.texts import TextsDirectory
|
8
|
from wcs.categories import Category
|
9
|
|
10
|
wcs_get_decorate_vars = template.get_decorate_vars
|
11
|
|
12
|
|
13
|
def get_decorate_vars(body, response, generate_breadcrumb=True, template_context=None, **kwargs):
|
14
|
if template_context and 'form_side' in template_context:
|
15
|
# force rendering as it will put new variables in the context
|
16
|
template_context['form_side'] = template_context['form_side']()
|
17
|
|
18
|
for key in ('bigdiv', 'gauche'):
|
19
|
if not key in response.filter:
|
20
|
response.filter[key] = None
|
21
|
|
22
|
return wcs_get_decorate_vars(body, response, generate_breadcrumb)
|
23
|
|
24
|
|
25
|
def render_response(publisher, body):
|
26
|
response = get_response()
|
27
|
|
28
|
if isinstance(body, template.QommonTemplateResponse):
|
29
|
body = template.render(body.templates, body.context)
|
30
|
body = str(body)
|
31
|
|
32
|
root_url = publisher.get_root_url()
|
33
|
wcs_path = publisher.get_request().get_path()[len(root_url) :]
|
34
|
section = wcs_path.split('/')[0]
|
35
|
|
36
|
if section in ('backoffice', 'admin'):
|
37
|
return template.decorate(body, response)
|
38
|
|
39
|
section_title = ''
|
40
|
page_title = response.filter.get('title')
|
41
|
if 'error-page' in response.filter:
|
42
|
pass
|
43
|
elif section == 'consultations':
|
44
|
section_title = '<h2 id="consultations">%s</h2>\n' % _('Consultations')
|
45
|
response.filter['bigdiv'] = 'rub_consultation'
|
46
|
elif section and len(section) > 1:
|
47
|
# XXX: this works but is not efficient
|
48
|
if Category.has_urlname(section):
|
49
|
section_title = '<h2 id="services">%s</h2>\n' % _('Services')
|
50
|
response.filter['bigdiv'] = 'rub_service'
|
51
|
|
52
|
if hasattr(response, 'breadcrumb') and response.breadcrumb:
|
53
|
if len(response.breadcrumb) == 1:
|
54
|
response.breadcrumb = None
|
55
|
|
56
|
return template.decorate(body, response)
|
57
|
|
58
|
|
59
|
template.get_decorate_vars = get_decorate_vars
|
60
|
get_publisher_class().render_response = render_response
|
61
|
|
62
|
TextsDirectory.register('aq-error-assistance', N_('Assistance text next to errors'))
|