Skip to content

Commit

Permalink
[#2510] General file uploader interface
Browse files Browse the repository at this point in the history
  • Loading branch information
brew committed Jul 2, 2015
1 parent 5988cef commit 716a89a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
14 changes: 14 additions & 0 deletions ckan/lib/uploader.py
Expand Up @@ -16,6 +16,20 @@
_max_image_size = None


def get_uploader(upload_to, old_filename=None):
'''Query IUploader plugins and return an uploader instance for general
files.'''
upload = None
for plugin in plugins.PluginImplementations(plugins.IUploader):
upload = plugin.get_uploader(upload_to, old_filename)

# default uploader
if upload is None:
upload = Upload(upload_to, old_filename)

return upload


def get_resource_uploader(data_dict):
'''Query IUploader plugins and return a resource uploader instance.'''
upload = None
Expand Down
3 changes: 2 additions & 1 deletion ckan/logic/action/create.py
Expand Up @@ -684,7 +684,7 @@ def _group_or_org_create(context, data_dict, is_org=False):
session = context['session']
data_dict['is_organization'] = is_org

upload = uploader.Upload('group')
upload = uploader.get_uploader('group')
upload.update_data_dict(data_dict, 'image_url',
'image_upload', 'clear_upload')
# get the schema
Expand Down Expand Up @@ -766,6 +766,7 @@ def _group_or_org_create(context, data_dict, is_org=False):
logic.get_action('activity_create')(activity_create_context, activity_dict)

upload.upload(uploader.get_max_image_size())

if not context.get('defer_commit'):
model.repo.commit()
context["group"] = group
Expand Down
12 changes: 7 additions & 5 deletions ckan/logic/action/update.py
Expand Up @@ -499,6 +499,7 @@ def package_relationship_update(context, data_dict):
context['relationship'] = entity
return _update_package_relationship(entity, comment, context)


def _group_or_org_update(context, data_dict, is_org=False):
model = context['model']
user = context['user']
Expand All @@ -515,15 +516,15 @@ def _group_or_org_update(context, data_dict, is_org=False):
# get the schema
group_plugin = lib_plugins.lookup_group_plugin(group.type)
try:
schema = group_plugin.form_to_db_schema_options({'type':'update',
'api':'api_version' in context,
schema = group_plugin.form_to_db_schema_options({'type': 'update',
'api': 'api_version' in context,
'context': context})
except AttributeError:
schema = group_plugin.form_to_db_schema()

upload = uploader.Upload('group', group.image_url)
upload = uploader.get_uploader('group', group.image_url)
upload.update_data_dict(data_dict, 'image_url',
'image_upload', 'clear_upload')
'image_upload', 'clear_upload')

if is_org:
_check_access('organization_update', context, data_dict)
Expand Down Expand Up @@ -609,12 +610,13 @@ def _group_or_org_update(context, data_dict, is_org=False):
# in the group.

upload.upload(uploader.get_max_image_size())

if not context.get('defer_commit'):
model.repo.commit()


return model_dictize.group_dictize(group, context)


def group_update(context, data_dict):
'''Update a group.
Expand Down
6 changes: 4 additions & 2 deletions ckan/plugins/interfaces.py
Expand Up @@ -1467,6 +1467,8 @@ class IUploader(Interface):
be used by resource_create and resource_update actions.
'''

def get_uploader(self):
'''Return an uploader object used to upload general files.'''

def get_resource_uploader(self):
'''Return an alternative resource uploader object for resource
files.'''
'''Return an uploader object used to upload resource files.'''

0 comments on commit 716a89a

Please sign in to comment.