Example #1
0
def package_update_rest_minimal(context, data_dict):
    setup()
    package= ''
    fulltext = ''
    old_fulltext = ''
    if data_dict.has_key('extras'):
        if 'full_text_search' in data_dict['extras'].keys():
            fulltext = data_dict['extras']['full_text_search']
            data_dict = _del_extra_field_from_list(data_dict, 'full_text_search')
            package = update.package_update_rest(context, data_dict)
            old_fulltext = None
            
            if package.has_key('id'):
                old_fulltext = Session.query(PackageFulltext) \
                                    .filter(PackageFulltext.package_id==package['id']) \
                                    .first()
            fulltext_dict_save(fulltext, old_fulltext, package, context)
        else:
            package = update.package_update(context, data_dict)
    else:
        package = update.package_update_rest(context, data_dict)

    if check_logged_in(context):
        fulltext = _get_fulltext(package['id'])
        if fulltext:
            package['extras']['full_text_search'] = fulltext.text 
        return package
    
    minimal_package = _del_extra_field_from_list(package)
    minimal_package = _del_main_field_from_dict(minimal_package)
    return minimal_package
Example #2
0
def package_update_rest_minimal(context, data_dict):
    setup()
    package = ''
    fulltext = ''
    old_fulltext = ''
    if data_dict.has_key('extras'):
        if 'full_text_search' in data_dict['extras'].keys():
            fulltext = data_dict['extras']['full_text_search']
            data_dict = _del_extra_field_from_list(data_dict,
                                                   'full_text_search')
            package = update.package_update_rest(context, data_dict)
            old_fulltext = None

            if package.has_key('id'):
                old_fulltext = Session.query(PackageFulltext) \
                                    .filter(PackageFulltext.package_id==package['id']) \
                                    .first()
            fulltext_dict_save(fulltext, old_fulltext, package, context)
        else:
            package = update.package_update(context, data_dict)
    else:
        package = update.package_update_rest(context, data_dict)

    if check_logged_in(context):
        fulltext = _get_fulltext(package['id'])
        if fulltext:
            package['extras']['full_text_search'] = fulltext.text
        return package

    minimal_package = _del_extra_field_from_list(package)
    minimal_package = _del_main_field_from_dict(minimal_package)
    return minimal_package
Example #3
0
def package_update_minimal(context, data_dict):
    '''Update a dataset (package).

    You must be authorized to edit the dataset and the groups that it belongs
    to.
    
    It is recommended to call
    :py:func:`ckan.logic.action.get.package_show`, make the desired changes to
    the result, and then call ``package_update()`` with it.

    Plugins may change the parameters of this function depending on the value
    of the dataset's ``type`` attribute, see the
    :py:class:`~ckan.plugins.interfaces.IDatasetForm` plugin interface.

    For further parameters see
    :py:func:`~ckan.logic.action.create.package_create`.

    :param id: the name or id of the dataset to update
    :type id: string

    :returns: the updated dataset (if ``'return_package_dict'`` is ``True`` in
              the context, which is the default. Otherwise returns just the
              dataset id)
    :rtype: dictionary
    '''
    setup()
    package= ''
    fulltext = ''
    old_fulltext = ''
    if data_dict.has_key('extras'):
        contains = _contains_key(data_dict['extras'], 'full_text_search')
        if(contains): 
            fulltext = contains
            data_dict = _del_extra_field_from_dict(data_dict, 'full_text_search')
        
            package = update.package_update(context, data_dict)
            old_fulltext = None
            if package.has_key('id'):
                old_fulltext = Session.query(PackageFulltext) \
                                    .filter(PackageFulltext.package_id==package['id']) \
                                    .first()
            fulltext_dict_save(fulltext, old_fulltext, package, context)
        else:
            package = update.package_update(context, data_dict)
    else:
        package = update.package_update(context, data_dict)

    if check_logged_in(context):
        fulltext = _get_fulltext(package['id'])
        if fulltext:
            fulltext_dict = { 'key': 'full_text_search',
                              'value': fulltext.text
                            }
            package['extras'].append(fulltext_dict) 
        return package
    
    minimal_package = _del_extra_field_from_dict(package)
    minimal_package = _del_main_field_from_dict(minimal_package)
    return minimal_package
Example #4
0
def package_update_minimal(context, data_dict):
    '''Update a dataset (package).

    You must be authorized to edit the dataset and the groups that it belongs
    to.
    
    It is recommended to call
    :py:func:`ckan.logic.action.get.package_show`, make the desired changes to
    the result, and then call ``package_update()`` with it.

    Plugins may change the parameters of this function depending on the value
    of the dataset's ``type`` attribute, see the
    :py:class:`~ckan.plugins.interfaces.IDatasetForm` plugin interface.

    For further parameters see
    :py:func:`~ckan.logic.action.create.package_create`.

    :param id: the name or id of the dataset to update
    :type id: string

    :returns: the updated dataset (if ``'return_package_dict'`` is ``True`` in
              the context, which is the default. Otherwise returns just the
              dataset id)
    :rtype: dictionary
    '''
    setup()
    package = ''
    fulltext = ''
    old_fulltext = ''
    if data_dict.has_key('extras'):
        contains = _contains_key(data_dict['extras'], 'full_text_search')
        if (contains):
            fulltext = contains
            data_dict = _del_extra_field_from_dict(data_dict,
                                                   'full_text_search')

            package = update.package_update(context, data_dict)
            old_fulltext = None
            if package.has_key('id'):
                old_fulltext = Session.query(PackageFulltext) \
                                    .filter(PackageFulltext.package_id==package['id']) \
                                    .first()
            fulltext_dict_save(fulltext, old_fulltext, package, context)
        else:
            package = update.package_update(context, data_dict)
    else:
        package = update.package_update(context, data_dict)

    if check_logged_in(context):
        fulltext = _get_fulltext(package['id'])
        if fulltext:
            fulltext_dict = {'key': 'full_text_search', 'value': fulltext.text}
            package['extras'].append(fulltext_dict)
        return package

    minimal_package = _del_extra_field_from_dict(package)
    minimal_package = _del_main_field_from_dict(minimal_package)
    return minimal_package
Example #5
0
def _get_fulltext(package_id):
    '''Returns the fulltext of a package.
    
    @param package_id: id of the package
    '''
    setup()
    if package_id:
        fulltext = Session.query(PackageFulltext) \
                            .filter(PackageFulltext.package_id==package_id) \
                            .first()
        return fulltext
    return None
Example #6
0
def _get_fulltext(package_id):
    '''Returns the fulltext of a package.
    
    @param package_id: id of the package
    '''
    setup()
    if package_id:
        fulltext = Session.query(PackageFulltext) \
                            .filter(PackageFulltext.package_id==package_id) \
                            .first()
        return fulltext
    return None
Example #7
0
def package_create_rest_minimal(context, data_dict):

    setup()
    package = ''
    fulltext = ''
    old_fulltext = ''
    categories = []

    if all(isinstance(n, basestring) for n in data_dict['groups']):
        groups = data_dict['groups']
        for g in groups:
            categories.append({'name': g})
        data_dict['groups'] = categories

    if all(isinstance(n, basestring) for n in data_dict['tags']):
        tags = []
        for tag in data_dict['tags']:
            tags.append({'name': tag})

        data_dict['tags'] = tags

    if data_dict.has_key('extras'):
        if 'full_text_search' in data_dict['extras'].keys():
            fulltext = data_dict['extras']['full_text_search']
            data_dict = _del_extra_field_from_list(data_dict,
                                                   'full_text_search')
            data_dict['extras'] = _get_extras_dict(data_dict['extras'])
            package = create.package_create(context, data_dict)
            old_fulltext = None
            if package.has_key('id'):
                old_fulltext = Session.query(PackageFulltext) \
                                    .filter(PackageFulltext.package_id==package['id']) \
                                    .first()

            fulltext_dict_save(fulltext, old_fulltext, package, context)
        else:
            data_dict['extras'] = _get_extras_dict(data_dict['extras'])
            package = create.package_create(context, data_dict)

    else:
        data_dict['extras'] = _get_extras_dict(data_dict['extras'])
        package = create.package_create(context, data_dict)

    if check_logged_in(context):
        fulltext = _get_fulltext(package['id'])
        if fulltext:
            package['extras']['full_text_search'] = fulltext.text
        return package

    minimal_package = _del_extra_field_from_list(package)
    minimal_package = _del_main_field_from_dict(minimal_package)
    return minimal_package
Example #8
0
def package_create_rest_minimal(context, data_dict):
   
    setup()
    package= ''
    fulltext = ''
    old_fulltext = ''
    categories = []

    if all(isinstance(n, basestring) for n in data_dict['groups']):
        groups = data_dict['groups']
        for g in groups:
             categories.append({'name': g})
        data_dict['groups']= categories
        
    if all(isinstance(n, basestring) for n in data_dict['tags']):
        tags = []
        for tag in data_dict['tags']:
            tags.append({'name': tag})
        
        data_dict['tags'] = tags

    if data_dict.has_key('extras'):
        if 'full_text_search' in data_dict['extras'].keys():
            fulltext = data_dict['extras']['full_text_search']
            data_dict = _del_extra_field_from_list(data_dict, 'full_text_search')
            data_dict['extras'] = _get_extras_dict(data_dict['extras'])
            package = create.package_create(context, data_dict)
            old_fulltext = None
            if package.has_key('id'):
                old_fulltext = Session.query(PackageFulltext) \
                                    .filter(PackageFulltext.package_id==package['id']) \
                                    .first()

            fulltext_dict_save(fulltext, old_fulltext, package, context)
        else:
            data_dict['extras'] = _get_extras_dict(data_dict['extras'])
            package = create.package_create(context, data_dict)

    else:
        data_dict['extras'] = _get_extras_dict(data_dict['extras'])
        package = create.package_create(context, data_dict)

    if check_logged_in(context):
        fulltext = _get_fulltext(package['id'])
        if fulltext:
            package['extras']['full_text_search'] = fulltext.text 
        return package
    
    minimal_package = _del_extra_field_from_list(package)
    minimal_package = _del_main_field_from_dict(minimal_package)
    return minimal_package
Example #9
0
def fulltext_delete(context, data_dict):  
    '''Deletes Fulltext.
    
    @param data_dict: dict containig the id of the package
    '''
    setup()
   
    old_fulltext = ''
    if data_dict.has_key('id'):
        old_fulltext = Session.query(PackageFulltext) \
                            .filter(PackageFulltext.package_id==package['id']) \
                            .first()

        fulltext_dict_save(None, old_fulltext, data_dict, context)    
    return true
Example #10
0
def fulltext_delete(context, data_dict):
    '''Deletes Fulltext.
    
    @param data_dict: dict containig the id of the package
    '''
    setup()

    old_fulltext = ''
    if data_dict.has_key('id'):
        old_fulltext = Session.query(PackageFulltext) \
                            .filter(PackageFulltext.package_id==package['id']) \
                            .first()

        fulltext_dict_save(None, old_fulltext, data_dict, context)
    return true
Example #11
0
def package_create_minimal(context, data_dict):  
    '''Create a new dataset (package).

    You must be authorized to create new datasets. If you specify any groups
    for the new dataset, you must also be authorized to edit these groups.

    Plugins may change the parameters of this function depending on the value
    of the ``type`` parameter, see the
    :py:class:`~ckan.plugins.interfaces.IDatasetForm` plugin interface.

    :param name: the name of the new dataset, must be between 2 and 100
        characters long and contain only lowercase alphanumeric characters,
        ``-`` and ``_``, e.g. ``'warandpeace'``
    :type name: string
    :param title: the title of the dataset (optional, default: same as
        ``name``)
    :type title: string
    :param author: the name of the dataset's author (optional)
    :type author: string
    :param author_email: the email address of the dataset's author (optional)
    :type author_email: string
    :param maintainer: the name of the dataset's maintainer (optional)
    :type maintainer: string
    :param maintainer_email: the email address of the dataset's maintainer
        (optional)
    :type maintainer_email: string
    :param license_id: the id of the dataset's license, see
        :py:func:`~ckan.logic.action.get.license_list` for available values
        (optional)
    :type license_id: license id string
    :param notes: a description of the dataset (optional)
    :type notes: string
    :param url: a URL for the dataset's source (optional)
    :type url: string
    :param version: (optional)
    :type version: string, no longer than 100 characters
    :param state: the current state of the dataset, e.g. ``'active'`` or
        ``'deleted'``, only active datasets show up in search results and
        other lists of datasets, this parameter will be ignored if you are not
        authorized to change the state of the dataset (optional, default:
        ``'active'``)
    :type state: string
    :param type: the type of the dataset (optional),
        :py:class:`~ckan.plugins.interfaces.IDatasetForm` plugins
        associate themselves with different dataset types and provide custom
        dataset handling behaviour for these types
    :type type: string
    :param resources: the dataset's resources, see
        :py:func:`resource_create` for the format of resource dictionaries
        (optional)
    :type resources: list of resource dictionaries
    :param tags: the dataset's tags, see :py:func:`tag_create` for the format
        of tag dictionaries (optional)
    :type tags: list of tag dictionaries
    :param extras: the dataset's extras (optional), extras are arbitrary
        (key: value) metadata items that can be added to datasets, each extra
        dictionary should have keys ``'key'`` (a string), ``'value'`` (a
        string)
    :type extras: list of dataset extra dictionaries
    :param relationships_as_object: see :py:func:`package_relationship_create`
        for the format of relationship dictionaries (optional)
    :type relationships_as_object: list of relationship dictionaries
    :param relationships_as_subject: see :py:func:`package_relationship_create`
        for the format of relationship dictionaries (optional)
    :type relationships_as_subject: list of relationship dictionaries
    :param groups: the groups to which the dataset belongs (optional), each
        group dictionary should have one or more of the following keys which
        identify an existing group:
        ``'id'`` (the id of the group, string), ``'name'`` (the name of the
        group, string), ``'title'`` (the title of the group, string), to see
        which groups exist call :py:func:`~ckan.logic.action.get.group_list`
    :type groups: list of dictionaries
    :param owner_org: the id of the dataset's owning organization, see
        :py:func:`~ckan.logic.action.get.organization_list` or
        :py:func:`~ckan.logic.action.get.organization_list_for_user` for
        available values (optional)
    :type owner_org: string

    :returns: the newly created dataset (unless 'return_id_only' is set to True
              in the context, in which case just the dataset id will
              be returned)
    :rtype: dictionary

    '''
    setup()
    package= ''
    fulltext = ''
    old_fulltext = ''
 
    if data_dict.has_key('extras'):
        contains = _contains_key(data_dict['extras'], 'full_text_search')
        if(contains): 
            fulltext = contains
            data_dict = _del_extra_field_from_dict(data_dict, 'full_text_search')
            package = create.package_create(context, data_dict)
            old_fulltext = None
            
            if package.has_key('id'):
                old_fulltext = Session.query(PackageFulltext) \
                                    .filter(PackageFulltext.package_id==package['id']) \
                                    .first()
            fulltext_dict_save(fulltext, old_fulltext, package, context)
        else:
            package = create.package_create(context, data_dict)
    else:
        package = create.package_create(context, data_dict)
      
    if check_logged_in(context):
        if fulltext:
            # why fulltext.text? Left it for compatibility
            if isinstance(fulltext,unicode): 
                valueFulltext = fulltext
            else:
                valueFulltext = fulltext.text
            fulltext_dict = { 'key': 'full_text_search',
                              'value': valueFulltext
                            }
            package['extras'].append(fulltext_dict) 
        return package
    
    minimal_package = _del_extra_field_from_dict(package)
    minimal_package = _del_main_field_from_dict(minimal_package)
    return minimal_package
Example #12
0
def package_create_minimal(context, data_dict):
    '''Create a new dataset (package).

    You must be authorized to create new datasets. If you specify any groups
    for the new dataset, you must also be authorized to edit these groups.

    Plugins may change the parameters of this function depending on the value
    of the ``type`` parameter, see the
    :py:class:`~ckan.plugins.interfaces.IDatasetForm` plugin interface.

    :param name: the name of the new dataset, must be between 2 and 100
        characters long and contain only lowercase alphanumeric characters,
        ``-`` and ``_``, e.g. ``'warandpeace'``
    :type name: string
    :param title: the title of the dataset (optional, default: same as
        ``name``)
    :type title: string
    :param author: the name of the dataset's author (optional)
    :type author: string
    :param author_email: the email address of the dataset's author (optional)
    :type author_email: string
    :param maintainer: the name of the dataset's maintainer (optional)
    :type maintainer: string
    :param maintainer_email: the email address of the dataset's maintainer
        (optional)
    :type maintainer_email: string
    :param license_id: the id of the dataset's license, see
        :py:func:`~ckan.logic.action.get.license_list` for available values
        (optional)
    :type license_id: license id string
    :param notes: a description of the dataset (optional)
    :type notes: string
    :param url: a URL for the dataset's source (optional)
    :type url: string
    :param version: (optional)
    :type version: string, no longer than 100 characters
    :param state: the current state of the dataset, e.g. ``'active'`` or
        ``'deleted'``, only active datasets show up in search results and
        other lists of datasets, this parameter will be ignored if you are not
        authorized to change the state of the dataset (optional, default:
        ``'active'``)
    :type state: string
    :param type: the type of the dataset (optional),
        :py:class:`~ckan.plugins.interfaces.IDatasetForm` plugins
        associate themselves with different dataset types and provide custom
        dataset handling behaviour for these types
    :type type: string
    :param resources: the dataset's resources, see
        :py:func:`resource_create` for the format of resource dictionaries
        (optional)
    :type resources: list of resource dictionaries
    :param tags: the dataset's tags, see :py:func:`tag_create` for the format
        of tag dictionaries (optional)
    :type tags: list of tag dictionaries
    :param extras: the dataset's extras (optional), extras are arbitrary
        (key: value) metadata items that can be added to datasets, each extra
        dictionary should have keys ``'key'`` (a string), ``'value'`` (a
        string)
    :type extras: list of dataset extra dictionaries
    :param relationships_as_object: see :py:func:`package_relationship_create`
        for the format of relationship dictionaries (optional)
    :type relationships_as_object: list of relationship dictionaries
    :param relationships_as_subject: see :py:func:`package_relationship_create`
        for the format of relationship dictionaries (optional)
    :type relationships_as_subject: list of relationship dictionaries
    :param groups: the groups to which the dataset belongs (optional), each
        group dictionary should have one or more of the following keys which
        identify an existing group:
        ``'id'`` (the id of the group, string), ``'name'`` (the name of the
        group, string), ``'title'`` (the title of the group, string), to see
        which groups exist call :py:func:`~ckan.logic.action.get.group_list`
    :type groups: list of dictionaries
    :param owner_org: the id of the dataset's owning organization, see
        :py:func:`~ckan.logic.action.get.organization_list` or
        :py:func:`~ckan.logic.action.get.organization_list_for_user` for
        available values (optional)
    :type owner_org: string

    :returns: the newly created dataset (unless 'return_id_only' is set to True
              in the context, in which case just the dataset id will
              be returned)
    :rtype: dictionary

    '''
    setup()
    package = ''
    fulltext = ''
    old_fulltext = ''

    if data_dict.has_key('extras'):
        contains = _contains_key(data_dict['extras'], 'full_text_search')
        if (contains):
            fulltext = contains
            data_dict = _del_extra_field_from_dict(data_dict,
                                                   'full_text_search')
            package = create.package_create(context, data_dict)
            old_fulltext = None

            if package.has_key('id'):
                old_fulltext = Session.query(PackageFulltext) \
                                    .filter(PackageFulltext.package_id==package['id']) \
                                    .first()
            fulltext_dict_save(fulltext, old_fulltext, package, context)
        else:
            package = create.package_create(context, data_dict)
    else:
        package = create.package_create(context, data_dict)

    if check_logged_in(context):
        if fulltext:
            # why fulltext.text? Left it for compatibility
            if isinstance(fulltext, unicode):
                valueFulltext = fulltext
            else:
                valueFulltext = fulltext.text
            fulltext_dict = {'key': 'full_text_search', 'value': valueFulltext}
            package['extras'].append(fulltext_dict)
        return package

    minimal_package = _del_extra_field_from_dict(package)
    minimal_package = _del_main_field_from_dict(minimal_package)
    return minimal_package
Example #13
0
 def init_fulltext_table(self):
     '''Creates a new table called package_fulltext 
     in the database or on a remote server.
     '''
     setup()