Skip to content

Commit

Permalink
[#880] Add a helper to convert filestore urls
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelbabu committed Aug 19, 2013
1 parent becf23a commit 1459ac4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -10,6 +10,7 @@
import logging
import re
import urllib
import urlparse
import pprint
import copy
from urllib import urlencode
Expand Down Expand Up @@ -969,6 +970,22 @@ def resource_link(resource_dict, package_id):
return link_to(text, url)


def filestore_url_convert(resource_dict, qualified=False):
if resource_dict['url_type'] != 'filestore':
return resource_dict
resource_url = resource_dict['url']
url_scheme = urlparse.urlsplit(resource_url).scheme
if qualified and not url_scheme:
# return fully qualified url if it isn't one
resource_dict['url'] = ''.join([url('/', locale='default',
qualified=True), resource_url.lstrip('/')])
if not qualified and url_scheme:
# return relative url if it isn't one
resource_dict['url'] = ''.join(['/', resource_url.lstrip(url('/',
locale='default', qualified=True))])
return resource_dict


def related_item_link(related_item_dict):
text = related_item_dict.get('title', '')
url = url_for(controller='related',
Expand Down

0 comments on commit 1459ac4

Please sign in to comment.