Project

General

Profile

Download (1.94 KB) Statistics
| Branch: | Tag: | Revision:

root / extra / modules / template.py @ 9e6caf99

1
from quixote import get_request, get_publisher
2

    
3
from qommon import template
4
from wcs.categories import Category
5

    
6
wcs_decorate = template.decorate
7

    
8
def decorate(body, response):
9
    body = str(body)
10

    
11
    for key in ('bigdiv', 'gauche'):
12
        if not response.filter.has_key(key):
13
            response.filter[key] = None
14

    
15
    root_url = get_publisher().get_root_url()
16
    wcs_path = get_request().get_path()[len(root_url):]
17
    section = wcs_path.split('/')[0]
18

    
19
    if section in ('backoffice', 'admin'):
20
        return wcs_decorate(body, response)
21

    
22
    section_title = ''
23
    page_title = response.filter.get('title')
24
    if section == 'consultations':
25
        section_title = '<h2 id="consultations">%s</h2>\n' % _('Consultations')
26
        response.filter['bigdiv'] = 'rub_consultation'
27
    elif section == 'announces':
28
        response.filter['bigdiv'] = 'rub_annonce'
29
        section_title = '<h2 id="announces">%s</h2>\n' % _('Announces to citizens')
30
        if page_title == _('Announces to citizens'):
31
            page_title = ''
32
    elif section == 'agenda':
33
        response.filter['bigdiv'] = 'rub_agenda'
34
        section_title = '<h2 id="agenda">%s</h2>\n' % _('Agenda')
35
        if page_title == _('Agenda'):
36
            page_title = ''
37
    elif section and len(section) > 1:
38
        # XXX: this works but is not efficient
39
        if Category.has_urlname(section):
40
            section_title = '<h2 id="services">%s</h2>\n' % _('Services')
41
            response.filter['bigdiv'] = 'rub_service'
42

    
43
    if page_title:
44
        if section_title:
45
            page_title = '<h3>%s</h3>' % page_title
46
        else:
47
            page_title = '<h2 id="info">%s</h2>' % page_title
48
    else:
49
        page_title = ''
50

    
51
    body = '\n'.join((section_title, page_title, body))
52

    
53
    if hasattr(response, 'breadcrumb') and response.breadcrumb:
54
        if len(response.breadcrumb) == 1:
55
            response.breadcrumb = None
56

    
57
    return wcs_decorate(body, response)
58

    
59
template.decorate = decorate
60

    
(15-15/15)