Skip to content

Commit

Permalink
Merge pull request #32 from ViderumGlobal/fix-missing-resource
Browse files Browse the repository at this point in the history
Fix missing resource exception, and json decode errors
  • Loading branch information
ZoranPandovski authored Nov 16, 2017
2 parents 2214567 + a0d77c8 commit 7019a9b
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions ckanext/orgdashboards/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,22 +252,30 @@ def _is_dataset_private(self, package_id):

org_views = OrgViews()


def orgdashboards_get_resource_url(id):
if not resource_id_exists(id, _get_ctx()):
return None

data = _get_action('resource_show', {}, {'id': id})
try:
data = _get_action('resource_show', {}, {'id': id})
except l.NotFound:
return ''
return data['url'] + '/'


def orgdashboards_get_geojson_properties(resource_id):
import requests

url = orgdashboards_get_resource_url(resource_id)

try:
response = requests.get(url)
except Exception as e:
log.error(e)
if url:
response = requests.get(url)
response.raise_for_status()
else:
return 'Wrong resource url'
except requests.exceptions.HTTPError as ex:
return [{'error': ex.message}]

try:
geojson = response.json()
Expand All @@ -280,9 +288,11 @@ def orgdashboards_get_geojson_properties(resource_id):

return result


def orgdashboards_resource_show_map_properties(id):
return orgdashboards_get_geojson_properties(id)



def orgdashboards_convert_to_list(resources):
if not resources.startswith('{'):
return [resources]
Expand All @@ -307,6 +317,7 @@ def orgdashboards_smart_truncate(text, length=800):
return text
return text[:length].rsplit(' ', 1)[0]


def orgdashboards_get_secondary_language(organization_name):
organization = _get_action('organization_show', {}, {'id': organization_name})

Expand All @@ -315,6 +326,7 @@ def orgdashboards_get_secondary_language(organization_name):
else:
return 'none'


def orgdashboards_get_secondary_dashboard(organization_name):
organization = _get_action('organization_show', {}, {'id': organization_name})

Expand All @@ -323,6 +335,7 @@ def orgdashboards_get_secondary_dashboard(organization_name):
else:
return 'none'


def orgdashboards_get_current_url(page, params, controller, action, name, exclude_param=''):

if action == 'show_dashboard_by_domain':
Expand All @@ -344,25 +357,30 @@ def orgdashboards_get_current_url(page, params, controller, action, name, exclud

return url


def orgdashboards_get_country_short_name(current_locale):
for locale in get_available_locales():
if current_locale == str(locale):
return locale.english_name[:3]


def orgdashboards_get_organization_entity_name():
return config.get('ckanext.orgdashboards.organization_entity_name',
'organization')


def orgdashboards_get_group_entity_name():
return config.get('ckanext.orgdashboards.group_entity_name',
'group')


def orgdashboards_get_facet_items_dict(value):
try:
return h.get_facet_items_dict(value)
except:
return None


def orgdashboards_get_dashboard_url(org_name):

org = _get_action('organization_show', {}, {'id': org_name})
Expand All @@ -376,5 +394,6 @@ def orgdashboards_get_dashboard_url(org_name):
else:
return ''


def orgdashboards_get_config_option(key):
return config.get(key)

0 comments on commit 7019a9b

Please sign in to comment.