<commit_before>import ckan
import ckan.plugins as p
from ckan.lib.base import c
from ckan import model
from ckan.logic import ValidationError, NotFound, get_action
import random
from pylons import config

class OgdchTheme(p.SingletonPlugin):
    """
    Plugin containg the theme for OGDCH
    """
    p.implements(p.IConfigurer)
    p.implements(p.ITemplateHelpers)

    def update_config(self, config):
        # add our templates
        p.toolkit.add_template_directory(config, 'templates/ckan')

    def get_helpers(self):
        return {
            'get_css_version': self.get_css_version,
            'get_license_url': self.get_license_url,
            'get_organization_url': self.get_organization_url,
        }

    def get_css_version(self):
        if config['ckanext.ogdch.css_version'] == 'random':
            return random.randint(100000, 9999999999)

        return config['ckanext.ogdch.css_version']

    def get_license_url(self, pkg_dict):
        for extra in pkg_dict.get('extras', []):
            if extra.get('key') == 'license_url':
                return extra.get('value')
        return ''

    def get_organization_url(self, organization_id):
        context = {'model':model,'user':c.user}
        try:
            org = get_action('organization_show')(context,{'id': organization_id})
            for extra in org.get('extras', []):
                if extra.get('key') == 'website':
                    return extra.get('value').rstrip('/')
            return ''
        except NotFound,e:
            raise ValueError('Organization not found') <commit_msg>Do not fail of organization is not found<commit_after>import ckan
import ckan.plugins as p
from ckan.lib.base import c
from ckan import model
from ckan.logic import ValidationError, NotFound, get_action
import random
from pylons import config

import logging
log = logging.getLogger(__name__)

class OgdchTheme(p.SingletonPlugin):
    """
    Plugin containg the theme for OGDCH
    """
    p.implements(p.IConfigurer)
    p.implements(p.ITemplateHelpers)

    def update_config(self, config):
        # add our templates
        p.toolkit.add_template_directory(config, 'templates/ckan')

    def get_helpers(self):
        return {
            'get_css_version': self.get_css_version,
            'get_license_url': self.get_license_url,
            'get_organization_url': self.get_organization_url,
        }

    def get_css_version(self):
        if config['ckanext.ogdch.css_version'] == 'random':
            return random.randint(100000, 9999999999)

        return config['ckanext.ogdch.css_version']

    def get_license_url(self, pkg_dict):
        for extra in pkg_dict.get('extras', []):
            if extra.get('key') == 'license_url':
                return extra.get('value')
        return ''

    def get_organization_url(self, organization_id):
        context = {'model':model,'user':c.user}
        try:
            org = get_action('organization_show')(context,{'id': organization_id})
            for extra in org.get('extras', []):
                if extra.get('key') == 'website':
                    return extra.get('value').rstrip('/')
            return ''
        except NotFound,e:
            log.error('Organization %s not found' % organization_id)
            return ''
{'fraction_non_alphanumeric': 0.11249241964827168, 'fraction_numerical': 0.009702850212249849, 'mean_word_length': 2.6292629262926295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6166504', 'n_tokens_mistral': 1026, 'n_tokens_neox': 966, 'n_words': 215}