Project

General

Profile

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

theme / ckanext / ozwillo_theme / plugin.py @ c67189db

1 c1b3c044 Serghei MIHAI
import json
2
import os
3
import requests
4
import xml.etree.ElementTree as ET
5
from slugify import slugify
6
7 14fbb44a Serghei MIHAI
from pylons import config as pconfig
8
9 d67246b5 Serghei MIHAI
import ckan.plugins as plugins
10
import ckan.plugins.toolkit as toolkit
11 14fbb44a Serghei MIHAI
from ckan.lib.app_globals import set_global
12 d67246b5 Serghei MIHAI
13 c1b3c044 Serghei MIHAI
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 d67246b5 Serghei MIHAI
36
class OzwilloThemePlugin(plugins.SingletonPlugin):
37
    plugins.implements(plugins.IConfigurer)
38
39
    def update_config(self, config_):
40 14fbb44a Serghei MIHAI
        set_global('ckan.ozwillo_url',
41
                   pconfig.get('%s.ozwillo_url' % __name__))
42 cb0e91e4 Serghei MIHAI
        set_global('ckan.ozwillo_portal_url',
43
                   pconfig.get('%s.ozwillo_portal_url' % __name__))
44 c67189db Guillaume Denis
        set_global('ckan.ozwillo_ckan_app_id',
45
                   pconfig.get('%s.ozwillo_ckan_app_id' % __name__))
46 14fbb44a Serghei MIHAI
47 a5d8476a Serghei MIHAI
        set_global('ckan.localized_links', footer_links())
48 c1b3c044 Serghei MIHAI
49 d67246b5 Serghei MIHAI
        toolkit.add_template_directory(config_, 'templates')
50
        toolkit.add_public_directory(config_, 'public')
51
        toolkit.add_resource('fanstatic', 'theme')