Project

General

Profile

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

root / extra / modules / template.py @ 6f1fb6bd

1
from quixote import get_request, get_publisher, get_response
2
from quixote.html import htmltext
3

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

    
7
wcs_decorate = template.decorate
8
wcs_error_page = template.error_page
9

    
10
def decorate(body, response):
11
    body = str(body)
12

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

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

    
21
    if section in ('backoffice', 'admin'):
22
        return wcs_decorate(body, response)
23

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

    
45
    if not 'auquotidien-no-titles-in-section' in response.filter.get('keywords', []):
46
        if page_title:
47
            if section_title:
48
                page_title = '<h3>%s</h3>' % page_title
49
            else:
50
                page_title = '<h2 id="info">%s</h2>' % page_title
51
        else:
52
            page_title = ''
53

    
54
        body = '\n'.join((section_title, page_title, body))
55

    
56
    if hasattr(response, 'breadcrumb') and response.breadcrumb:
57
        if len(response.breadcrumb) == 1:
58
            response.breadcrumb = None
59

    
60
    return wcs_decorate(body, response)
61

    
62

    
63
def error_page(*args, **kwargs):
64
    get_response().filter['keywords'] = template.get_current_theme().get('keywords')
65
    get_response().filter['title'] = template.get_current_theme().get('keywords')
66
    error_page = wcs_error_page(*args, **kwargs)
67
    title = get_response().filter['title']
68
    get_response().filter['title'] = None
69
    return htmltext('<div id="info"><h2>%s</h2>' % title) + error_page + htmltext('</div>')
70

    
71
template.decorate = decorate
72
template.error_page = error_page
(16-16/16)