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 |
14fbb44a
|
Serghei MIHAI
|
|
45 |
a5d8476a
|
Serghei MIHAI
|
set_global('ckan.localized_links', footer_links())
|
46 |
c1b3c044
|
Serghei MIHAI
|
|
47 |
d67246b5
|
Serghei MIHAI
|
toolkit.add_template_directory(config_, 'templates')
|
48 |
|
|
toolkit.add_public_directory(config_, 'public')
|
49 |
|
|
toolkit.add_resource('fanstatic', 'theme')
|