예제 #1
0
def resource_create(context, data_dict):
    '''
    This runs the 'resource_create' action from core ckan's create.py
    It allows us to do some minor changes and wrap it.
    '''

    process_batch_mode(context, data_dict)
    flag_if_file_uploaded(context, data_dict)

    if data_dict.get('resource_type', '') != 'file.upload':
        #If this isn't an upload, it is a link so make sure we update
        #the url_type otherwise solr will screw everything up
        data_dict['url_type'] = 'api'

        # we need to overwrite size field (not just setting it to None or pop) otherwise
        # ckan.lib.dictization.model_save.resource_dict_save() keeps the old value
        data_dict['size'] = 0
    else:
        try:
            data_dict['size'] = request.content_length
            data_dict['mimetype'] = request.files['upload'].mimetype
        except RuntimeError as re:
            log.debug(
                'This usually happens for tests when there is no HTTP request: '
                + unicode(re))

    result_dict = core_create.resource_create(context, data_dict)
    return result_dict
def resource_create(context, data_dict):
  if not tk.asbool(config.get('ckan.cloud_storage_enable')) or data_dict.get('url'):
    return origin.resource_create(context, data_dict)
  
  model = context['model']
  user = context['user']

  package_id = _get_or_bust(data_dict, 'package_id')
  data_dict.pop('package_id')

  pkg_dict = _get_action('package_show')(context, {'id': package_id})

  _check_access('resource_create', context, data_dict)

  if not 'resources' in pkg_dict:
    pkg_dict['resources'] = []

  upload = uploader.S3Upload(data_dict)

  pkg_dict['resources'].append(data_dict)

  try:
    context['defer_commit'] = True
    context['use_cache'] = False
    _get_action('package_update')(context, pkg_dict)
    context.pop('defer_commit')
  except ValidationError, e:
    errors = e.error_dict['resources'][-1]
    raise ValidationError(errors)
예제 #3
0
def resource_create(context, data_dict):
    if 'url' not in data_dict:
        url = ""
        data_dict['url'] = url
    resource_dict = create.resource_create(context, data_dict)
    send_resource_log(context, resource_dict, 'Resource created',
                      'ResourcePublished')

    return resource_dict
예제 #4
0
def res_create(context, data_dict=None):
    ret_val = resource_create(context, data_dict)
    
    dataset_obj = context['package']
    data_dict = {'id': dataset_obj.id,
                 'name': dataset_obj.name}
    if not dataset_obj.private: # dataset is public
        log.debug("resource_create sync dataset")
        queue.put(data_dict)
    
    return ret_val
예제 #5
0
def resource_create(context, data_dict):
    '''
    This runs the 'resource_create' action from core ckan's create.py
    It allows us to do some minor changes and wrap it.
    '''

    process_batch_mode(context, data_dict)

    if data_dict.get('resource_type', '') != 'file.upload':
        #If this isn't an upload, it is a link so make sure we update
        #the url_type otherwise solr will screw everything up
        data_dict['url_type'] = 'api'
    result_dict = core_create.resource_create(context, data_dict)
    return result_dict