Skip to content

Commit

Permalink
Helper function for resource urls
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Sep 24, 2012
1 parent 1eaa73e commit e395065
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -1158,6 +1158,35 @@ def include_resource(resource):
r = getattr(fanstatic_resources, resource)
r.need()

def urls_for_resource(resource):
''' Returns a list of urls for the resource specified. If the resource
is a group or has dependencies then there can be multiple urls.
NOTE: This is for special situations only and is not the way to generaly
include resources. It is advised not to use this function.'''
r = getattr(fanstatic_resources, resource)
resources = list(r.resources)
core = fanstatic_resources.fanstatic_extensions.core
f = core.get_needed()
lib = resources[0].library
root_path = f.library_url(lib)

resources = core.sort_resources(resources)
if f._bundle:
resources = core.bundle_resources(resources)
out = []
for resource in resources:
if isinstance(resource, core.Bundle):
paths = [resource.relpath for resource in resource.resources()]
relpath = ';'.join(paths)
relpath = core.BUNDLE_PREFIX + relpath
else:
relpath = resource.relpath

out.append('%s/%s' % (root_path, relpath))
return out


def debug_inspect(arg):
''' Output pprint.pformat view of supplied arg '''
return literal('<pre>') + pprint.pformat(arg) + literal('</pre>')
Expand Down Expand Up @@ -1403,6 +1432,7 @@ def resource_preview(resource, pkg_id):
'get_facet_items_dict',
'unselected_facet_items',
'include_resource',
'urls_for_resource',
'build_nav_main',
'debug_inspect',
'dict_list_reduce',
Expand Down

0 comments on commit e395065

Please sign in to comment.