Project

General

Profile

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

theme / ckanext / ozwillo_theme / plugin.py @ a5d8476a

1
import json
2
import os
3
import requests
4
import xml.etree.ElementTree as ET
5
from slugify import slugify
6

    
7
from pylons import config as pconfig
8

    
9
import ckan.plugins as plugins
10
import ckan.plugins.toolkit as toolkit
11
from ckan.lib.app_globals import set_global
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

    
35

    
36
class OzwilloThemePlugin(plugins.SingletonPlugin):
37
    plugins.implements(plugins.IConfigurer)
38

    
39
    def update_config(self, config_):
40
        set_global('ckan.ozwillo_url',
41
                   pconfig.get('%s.ozwillo_url' % __name__))
42
        set_global('ckan.ozwillo_portal_url',
43
                   pconfig.get('%s.ozwillo_portal_url' % __name__))
44

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

    
47
        toolkit.add_template_directory(config_, 'templates')
48
        toolkit.add_public_directory(config_, 'public')
49
        toolkit.add_resource('fanstatic', 'theme')
(2-2/2)