Example #1
0
    def escape_translated_text(self, pkg_dict):
        keys = ('title', 'notes')

        for key in keys:
            for locale in i18n.get_locales():
                if key + '_translated' in pkg_dict:
                    pkg_dict[key + '_translated'][locale] = pkg_dict[
                        key + '_translated'][locale].replace('"', '""')
    def view(self):

        context = {
            'model': model,
            'session': model.Session,
            'user': c.user,
            'for_view': True,
            'auth_user_obj': c.userobj
        }

        # Get the plugin configuration
        site_url = config.get('ckan.site_url') + config.get(
            'ckan.root_path').replace('{{LANG}}', '')
        date_created = config.get(namespace + '.create_date')
        date_modified = d.datetime.now().isoformat()
        publisher = config.get(namespace + '.publisher')
        theme_taxonomy = config.get(namespace + '.theme_taxonomy')
        license_url = config.get(namespace + '.license_url')
        catalog_title = {}
        catalog_desc = {}

        for locale in i18n.get_locales():
            catalog_title[locale] = config.get(namespace + '.catalog_title.' +
                                               locale)
            catalog_desc[locale] = config.get(namespace + '.catalog_desc.' +
                                              locale)

        # Get the dataset catalogue
        packages = t.get_action('package_search')(context, {
            'include_private': False,
            'rows': 1000
        })
        packages = packages['results']

        t.response.headers[
            'Content-Type'] = 'application/rdf+xml; charset=utf-8'
        return t.render('federador.xml',
                        extra_vars={
                            'site_url': site_url,
                            'date_created': date_created,
                            'date_modified': date_modified,
                            'publisher': publisher,
                            'theme_taxonomy': theme_taxonomy,
                            'license_url': license_url,
                            'packages': packages,
                            'catalog_title': catalog_title,
                            'catalog_desc': catalog_desc
                        })
Example #3
0
    def test_output_is_valid(self):
        u'''
        Test that the generated JS files are valid.
        '''
        def check_file(path):
            with codecs.open(path, u'r', encoding=u'utf-8') as f:
                data = json.load(f)
            eq_(data[u''].get(u'domain', None), u'ckan')

        self.build_js_translations()
        files = os.listdir(self.temp_dir)

        # Check that all locales have been generated
        eq_(set(i18n.get_locales()).difference([u'en']),
            set(os.path.splitext(fn)[0] for fn in files))

        # Check that each file is valid
        for filename in files:
            check_file(os.path.join(self.temp_dir, filename))
Example #4
0
    def test_output_is_valid(self):
        u'''
        Test that the generated JS files are valid.
        '''
        def check_file(path):
            with codecs.open(path, u'r', encoding=u'utf-8') as f:
                data = json.load(f)
            eq_(data[u''].get(u'domain', None), u'ckan')

        self.build_js_translations()
        files = os.listdir(self.temp_dir)

        # Check that all locales have been generated
        eq_(
            set(i18n.get_locales()).difference([u'en']),
            set(os.path.splitext(fn)[0] for fn in files))

        # Check that each file is valid
        for filename in files:
            check_file(os.path.join(self.temp_dir, filename))
Example #5
0
 def __init__(self, app, config):
     self.app = app
     self.default_locale = config.get('ckan.locale_default', 'en')
     self.local_list = get_locales()
Example #6
0
 def __init__(self, app, config):
     self.app = app
     self.default_locale = config.get('ckan.locale_default', 'en')
     self.local_list = get_locales()
Example #7
0
# vocabulary name, base URI
THEME_CONCEPTS = ('eu_themes', THEME_BASE_URI)
LANG_CONCEPTS = ('languages', LANG_BASE_URI)
GEO_CONCEPTS = ('places', GEO_BASE_URI)
FREQ_CONCEPTS = ('frequencies', FREQ_BASE_URI)
FORMAT_CONCEPTS = ('filetype', FORMAT_BASE_URI)

DEFAULT_VOCABULARY_KEY = 'OP_DATPRO'
DEFAULT_THEME_KEY = DEFAULT_VOCABULARY_KEY
DEFAULT_FORMAT_CODE = DEFAULT_VOCABULARY_KEY
DEFAULT_FREQ_CODE = 'UNKNOWN'
DEFAULT_LANG = config.get('ckan.locale_default', 'en')

LOCALISED_DICT_NAME_BASE = 'DCATAPIT_MULTILANG_BASE'
LOCALISED_DICT_NAME_RESOURCES = 'DCATAPIT_MULTILANG_RESOURCES'
OFFERED_LANGS = get_locales()

lang_mapping_ckan_to_voc = {
    'it': 'ITA',
    'de': 'DEU',
    'en': 'ENG',
    'en_GB': 'ENG',
    'fr': 'FRA',
}

lang_mapping_xmllang_to_ckan = {
    'it': 'it',
    'de': 'de',
    'en': 'en_GB',
    'fr': 'fr',
}
import json
import logging
from datetime import datetime

from ckan.common import _, config
from ckan.lib.i18n import get_locales
from ckan.logic.validators import url_validator
from ckan.plugins.toolkit import Invalid
from sqlalchemy import and_

from ckanext.dcatapit.mapping import themes_to_aggr_json, themes_parse_to_uris
from ckanext.dcatapit.model.subtheme import Subtheme

DEFAULT_LANG = config.get('ckan.locale_default', 'en')
log = logging.getLogger(__file__)
available_locales = get_locales()


def is_blank(string):
    return not (string and string.strip())


def couple_validator(value, context):
    if not is_blank(value):
        couples = value.split(',')

        for c in couples:
            if not c:
                raise Invalid(_('Invalid couple, one value is missing'))

    return value