Skip to content
Snippets Groups Projects
Select Git revision
  • 116a73db77a54716650d609aed191ba04d4dc90f
  • main default protected
  • OZG-7986-mandat-anfragen
  • OZG-6978-prevent-other-pages-from-being-called
  • OZG-8378-ods-heading
  • optimize-storybook
  • OZG-8405-Alfa-Bearbeiter-auswählen-und-entfernen-Design
  • OZG-8314-Alfa-Vorgang-Bearbeiter-Zuweisung-entfernen
  • testing-imports
  • storybook-improvements
  • OZG-7287-forward-saml-token
  • release-administration
  • OZG-8422-BenutzerSpeichern
  • release-info
  • release
  • OZG-7856_schadcode-scanner-e2e
  • OZG-7985-fix-sorting
  • OZG-8305-Create-webpack-sbom
  • tooltip-improvements
  • OZG-7714-UpgradeKeycloakDependencyTo25
  • OZG-8086-Admin-Datenanfrage-erstellen
  • 1.12.1-administration
  • 1.12.0-administration
  • 1.12.0-info
  • 2.27.0-alfa
  • 1.11.0-info
  • 1.11.0-administration
  • 2.26.0-alfa
  • 1.10.0-info
  • 1.10.0-administration
  • 2.25.0-alfa
  • 1.9.0-info
  • 1.9.0-administration
  • 2.24.0-alfa
  • 1.8.0-info
  • 1.8.0-administration
  • 2.23.0-alfa
  • 1.7.0-info
  • 1.7.0-administration
  • 2.22.0-alfa
  • 1.6.0-info
41 results

user-profile-in-header.component.html

Blame
  • helpers.py 2.78 KiB
    import logging
    import traceback
    import ast
    import ckan.plugins.toolkit as toolkit
    import ckan.logic as logic
    import ckan.model as model
    import json
    from ckan.common import  c
    
    get_action = logic.get_action
    log = logging.getLogger(__name__)
    
    def odsh_openness_score_dataset_html(dataset):
        score = 0
        #dataset = json.loads(dataset)
        resources = dataset.get('resources')
        if resources is None:
            return 0
        for resource in resources:
            r_qa = resource.get('qa')
            if r_qa:
                try:
                    qa = None
                    if isinstance(r_qa, basestring): # r_qa might be a string of a dictionary when 'dataset' is send from solr
                        qa = ast.literal_eval(r_qa)
                    else:
                        qa = r_qa
                    resource_score = qa.get('openness_score')
                    if resource_score > score:
                        score = resource_score
                except AttributeError, e:
                    log.error('Error while calculating openness score %s: %s\nException: %s',
                        e.__class__.__name__,  unicode(e), traceback.format_exc())
        return score
    
    def odsh_get_resource_details(resource_id):
        resource_details = toolkit.get_action('resource_show')(
            data_dict={'id': resource_id})
        return resource_details
        
    
    def odsh_get_resource_views(pkg_dict, resource):
    
            context = {'model': model, 'session': model.Session,
                       'user': c.user, 'for_view': True,
                       'auth_user_obj': c.userobj}
            return get_action('resource_view_list')(
                context, {'id': resource['id']})
    
    def odsh_get_bounding_box(pkg_dict):
        try:
            extras=pkg_dict.get('extras')
            spatial=None
            for f in extras:
                if 'key' in f and f['key'] == 'spatial':
                    spatial=f['value']
                    break
    
            if spatial is not None:
                d = json.loads(spatial)
                if 'coordinates' in d:
                    coords=d['coordinates']
                    return compute_bounding_box(coords)
        except Exception, e:
            log.error('Error while bounding box %s: %s\nException: %s',
                e.__class__.__name__,  unicode(e), traceback.format_exc())
        return None 
    
    def compute_bounding_box(coords):
        if len(coords)==0:
            return None
    
        coords = [c for sublist in coords for c in sublist]
    
        minx = min(coords, key = lambda t: t[0])[0]
        maxx = max(coords, key = lambda t: t[0])[0]
        miny = min(coords, key = lambda t: t[1])[1]
        maxy = max(coords, key = lambda t: t[1])[1]
         
        return [maxx, minx, maxy, miny]
    
    def odsh_get_spatial_text(pkg_dict):
        extras=pkg_dict.get('extras')
        spatial=None
        for f in extras:
            if 'key' in f and f['key'] == 'spatial_text':
                spatial=f['value']
                return spatial
        return None