Пример #1
0
def fluent_form_languages(field=None, entity_type=None, object_type=None,
        schema=None):
    """
    Return a list of language codes for this form (or form field)

    1. return field['form_languages'] if it is defined
    2. return schema['form_languages'] if it is defined
    3. get schema from entity_type + object_type then
       return schema['form_languages'] if they are defined
    4. return languages from site configuration
    """
    if field and 'form_languages' in field:
        return field['form_languages']
    if schema and 'form_languages' in schema:
        return schema['form_languages']
    if entity_type and object_type:
        # late import for compatibility with older ckanext-scheming
        from ckanext.scheming.helpers import scheming_get_schema
        schema = scheming_get_schema(entity_type, object_type)
        if schema and 'form_languages' in schema:
            return schema['form_languages']

    langs = []
    for l in get_available_locales():
        if l.language not in langs:
            langs.append(l.language)
    return langs
Пример #2
0
def fluent_form_languages(field=None,
                          entity_type=None,
                          object_type=None,
                          schema=None):
    """
    Return a list of language codes for this form (or form field)

    1. return field['form_languages'] if it is defined
    2. return schema['form_languages'] if it is defined
    3. get schema from entity_type + object_type then
       return schema['form_languages'] if they are defined
    4. return languages from site configuration
    """
    if field and 'form_languages' in field:
        return field['form_languages']
    if schema and 'form_languages' in schema:
        return schema['form_languages']
    if entity_type and object_type:
        # late import for compatibility with older ckanext-scheming
        from ckanext.scheming.helpers import scheming_get_schema
        schema = scheming_get_schema(entity_type, object_type)
        if schema and 'form_languages' in schema:
            return schema['form_languages']

    langs = []
    for l in get_available_locales():
        if l.language not in langs:
            langs.append(l.language)
    return langs
Пример #3
0
    def update_config_schema(self, schema):
        ignore_missing = toolkit.get_validator('ignore_missing')

        charts = {}
        for _ in range(1, 5):
            charts.update({
                'ckanext.eds.chart_{idx}'.format(idx=_):
                [ignore_missing, unicode],
                'ckanext.eds.chart_{idx}_subheader'.format(idx=_):
                [ignore_missing, unicode]
            })

        for l in get_available_locales():
            if l.short_name in toolkit.aslist(
                    config.get('ckanext.eds.available_locales', 'en da_DK')):
                schema.update({
                    'ckan.site_intro_text_{0}'.format(l):
                    [ignore_missing, unicode],
                    'ckan.site_description_{0}'.format(l):
                    [ignore_missing, unicode],
                    'ckan.site_about_{0}'.format(l): [ignore_missing, unicode],
                    'ckan.site_title_{0}'.format(l): [ignore_missing, unicode],
                    'ckan.cookie_notice_content_{0}'.format(l):
                    [ignore_missing, unicode],
                    'api_guides_content_{0}'.format(l):
                    [ignore_missing, unicode],
                    'simple_guides_content_{0}'.format(l):
                    [ignore_missing, unicode]
                })

        schema.update(charts)

        return schema
Пример #4
0
def remove_locales_from_url(url):
    if not url:
        return
    for l in get_available_locales():
        l1 = "/{}/".format(l)
        if l1 in url:
            return url.replace(l1, "/")
    return url
Пример #5
0
def orgportals_get_country_short_name(current_locale):
    locales = []

    if toolkit.check_ckan_version(min_version='2.5.0', max_version='2.5.3'):
        locales = lib_helpers.get_available_locales()
    else:
        locales = i18n.get_available_locales()

    for locale in locales:
        if current_locale == str(locale):
            return locale.english_name[:3]
Пример #6
0
def orgdashboards_get_available_languages():
    ''' Read the languages listed in a json file '''

    languages = []

    for locale in get_available_locales():
        languages.append({'value': locale, 'text': locale.english_name})

    languages.sort()

    languages.insert(0, {'value': 'none', 'text': 'None'})

    return languages
Пример #7
0
def orgportals_get_available_languages():
    languages = []
    locales = []

    if toolkit.check_ckan_version(min_version='2.5.0', max_version='2.5.3'):
        locales = lib_helpers.get_available_locales()
    else:
        locales = i18n.get_available_locales()

    for locale in locales:
        languages.append({'value': locale, 'text': locale.english_name})

    languages.sort()

    languages.insert(0, {'value': 'none', 'text': 'None'})

    return languages
 def get_orig_locale(self, res):
     orig_lang = self.get_orig_language(res)
     available_locales = i18n.get_available_locales()
     for locale in available_locales:
         if locale == orig_lang:
             return locale
Пример #9
0
    def graph_from_catalog(self, catalog_dict, catalog_ref):

        g = self.g

        for prefix, namespace in namespaces.iteritems():
            g.bind(prefix, namespace)

        g.add((catalog_ref, RDF.type, DCAT.Catalog))

        g.add((catalog_ref, DCT.description,
               Literal('Data catalogue of the Government of Macedonia')))

        if config.get('ckan.dcat.publisher', False):
            publisher_details = URIRef(config.get('ckan.dcat.publisher'))
        else:
            publisher_details = URIRef('{}/publisher/'.format(
                config.get('ckan.site_url')))
        g.add((catalog_ref, DCT.publisher, publisher_details))

        self.g.add(
            (publisher_details, DCT.identifier,
             Literal(config.get('ckan.dcat.publisher.identifier', 'MISA'))))
        self.g.add((publisher_details, FOAF.homepage,
                    URIRef(
                        config.get('ckan.dcat.publisher.webpage',
                                   'https://opendata.gov.mk'))))
        self.g.add((publisher_details, RDF.type, FOAF.Agent))

        g.add((catalog_ref, DCT.title,
               Literal(config.get('ckan.dcat.catalog.title', 'data.gov.mk'))))

        locales = get_available_locales()
        for locale in locales:
            g.add((catalog_ref, DCT.language, Literal(str(locale))))

        g.add((catalog_ref, DCT.license,
               URIRef(
                   config.get(
                       'ckan.dcat.catalog.license_url',
                       'https://creativecommons.org/publicdomain/zero/1.0/'))))

        issued = config.get(
            'ckan.dcat.catalog.issued'
        )  # Should be string with supported datetime format
        if issued:
            self._add_date_triple(catalog_ref, DCT.issued, issued)

        g.add(
            (catalog_ref, DCAT.themeTaxonomy,
             URIRef(
                 config.get(
                     'ckan.dcat.theme_taxonomy_uri',
                     "http://publications.europa.eu/mdr/authority/data-theme/")
             )))

        if config.get(DCAT_CATALOG_HAS_PART, False):
            g.add((catalog_ref, DCT.hasPart,
                   URIRef(config.get(DCAT_CATALOG_HAS_PART))))

        if config.get(DCAT_CATALOG_IS_PART_OF, False):
            g.add((catalog_ref, DCT.isPartOf,
                   URIRef(config.get(DCAT_CATALOG_IS_PART_OF))))

        if config.get(DCAT_RIGHTS_STATEMENT, False):
            g.add((catalog_ref, DCT.rights,
                   Literal(config.get(DCAT_RIGHTS_STATEMENT))))

        g.add((catalog_ref, DCT.spatial,
               URIRef(
                   config.get('ckan.dcat.spatial',
                              "http://www.geonames.org/718075"))))
Пример #10
0
def orgdashboards_get_country_short_name(current_locale):
    for locale in get_available_locales():
        if current_locale == str(locale):
            return locale.english_name[:3]