Projet

Général

Profil

Télécharger (3,07 ko) Statistiques
| Branche: | Tag: | Révision:

root / auquotidien / modules / template.py @ 8b02623d

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 qommon import _
6
from qommon import template
7
from qommon.admin.texts import TextsDirectory
8
from wcs.categories import Category
9

    
10
wcs_error_page = template.error_page
11

    
12
def render_response(publisher, body):
13
    response = publisher.get_request().response
14
    body = str(body)
15

    
16
    for key in ('bigdiv', 'gauche'):
17
        if not response.filter.has_key(key):
18
            response.filter[key] = None
19

    
20
    root_url = publisher.get_root_url()
21
    wcs_path = publisher.get_request().get_path()[len(root_url):]
22
    section = wcs_path.split('/')[0]
23

    
24
    if section in ('backoffice', 'admin'):
25
        return template.decorate(body, response)
26

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

    
50
    if not 'auquotidien-no-titles-in-section' in response.filter.get('keywords', []):
51
        if page_title:
52
            if section_title:
53
                page_title = '<h3>%s</h3>' % page_title
54
            else:
55
                page_title = '<h2 id="info">%s</h2>' % page_title
56
        else:
57
            page_title = ''
58

    
59
        body = '\n'.join((section_title, page_title, body))
60

    
61
    if hasattr(response, 'breadcrumb') and response.breadcrumb:
62
        if len(response.breadcrumb) == 1:
63
            response.breadcrumb = None
64

    
65
    return template.decorate(body, response)
66

    
67

    
68
def error_page(*args, **kwargs):
69
    get_response().filter = {}
70
    get_response().filter['error-page'] = None
71
    get_response().filter['keywords'] = template.get_current_theme().get('keywords')
72
    get_response().filter['title'] = template.get_current_theme().get('keywords')
73
    get_response().filter['gauche'] = TextsDirectory.get_html_text('aq-error-assistance')
74
    error_page = wcs_error_page(*args, **kwargs)
75
    title = get_response().filter['title']
76
    get_response().filter['title'] = None
77
    return htmltext('<div id="info"><h2>%s</h2>' % title) + error_page + htmltext('</div>')
78

    
79
template.error_page = error_page
80
get_publisher_class().render_response = render_response
81

    
82
TextsDirectory.register('aq-error-assistance', N_('Assistance text next to errors'))
(27-27/27)