Project

General

Profile

« Previous | Next » 

Revision c1b3c044

Added by Serghei Mihai about 9 years ago

footer links localized (#6707)

View differences:

ckanext/ozwillo_theme/plugin.py
1
import json
2
import os
3
import requests
4
import xml.etree.ElementTree as ET
5
from slugify import slugify
6

  
1 7
from pylons import config as pconfig
2 8

  
3 9
import ckan.plugins as plugins
4 10
import ckan.plugins.toolkit as toolkit
5 11
from ckan.lib.app_globals import set_global
6 12

  
13
def footer_links():
14
    url = 'https://www.ozwillo.com/footer.xml'
15
    langs = {}
16

  
17
    response = requests.get(url)
18
    menuset = ET.fromstring(response.text.encode('utf-8'))
19

  
20
    items = ('News', 'Discovering', 'Co-construct', 'Let\'s go', 'Contact',
21
             'Projects', 'Project team', 'Ozwillo', 'User guide', 'Developers',
22
             'Legal Notices', 'General terms of use')
23

  
24

  
25
    for menu in menuset.findall('menu'):
26
        locale = menu.find('locale').text
27
        c = 0
28
        langs[locale] = {}
29
        for item in menu.findall('item'):
30
            if 'href' in item.attrib:
31
                langs[locale][slugify(items[c])] = item.get('href')
32
                c += 1
33
    return langs
34

  
7 35

  
8 36
class OzwilloThemePlugin(plugins.SingletonPlugin):
9 37
    plugins.implements(plugins.IConfigurer)
......
14 42
        set_global('ckan.ozwillo_portal_url',
15 43
                   pconfig.get('%s.ozwillo_portal_url' % __name__))
16 44

  
45
        set_global('ckan.footer_links', footer_links())
46

  
17 47
        toolkit.add_template_directory(config_, 'templates')
18 48
        toolkit.add_public_directory(config_, 'public')
19 49
        toolkit.add_resource('fanstatic', 'theme')

Also available in: Unified diff