Ejemplo n.º 1
0
def check_branch(key, data, errors, context):

    ignore_missing(key, data, errors, context)
    return

    from ckanext.bcgov.util.util import get_organization_branches

    org_key = ('org',)

    org_id = None
    if org_key in data:
        org_id = data[org_key]

    #Check if the organization has any branches
    branches = get_organization_branches(org_id)

    if len(branches) > 0 :
        value = data.get(key)
        if not value or value is missing:
            errors[key].append(_('Missing value'))
            raise StopOnError
Ejemplo n.º 2
0
def check_branch(key, data, errors, context):

    ignore_missing(key, data, errors, context)
    return

    from ckanext.bcgov.util.util import get_organization_branches

    org_key = ('org', )

    org_id = None
    if org_key in data:
        org_id = data[org_key]

    #Check if the organization has any branches
    branches = get_organization_branches(org_id)

    if len(branches) > 0:
        value = data.get(key)
        if not value or value is missing:
            errors[key].append(_('Missing value'))
            raise StopOnError
Ejemplo n.º 3
0
    def organization_list_related(self, ver=None):
        '''
        Returns the list of organizations including parent_of and child_of relationships.
        '''
        # FIXME: use IActions plugin instead
        from ckan.lib.search import SearchError

        help_str =  "Return a list of the names of the site's organizations.\n\n" + \
                    ":param order_by: the field to sort the list by, must be ``'name'`` or \n" + \
                    " ``'packages'`` (optional, default: ``'name'``) Deprecated use sort. \n" + \
                    ":type order_by: string \n" + \
                    ":param sort: sorting of the search results.  Optional.  Default:\n" + \
                    "'name asc' string of field name and sort-order. The allowed fields are \n" + \
                    "'name' and 'packages' \n" + \
                    ":type sort: string \n" + \
                    ":param organizations: a list of names of the groups to return, if given only \n" + \
                    "groups whose names are in this list will be returned (optional) \n" + \
                    ":type organizations: list of strings \n" + \
                    ":param all_fields: return full group dictionaries instead of  just names \n" + \
                    "(optional, default: ``False``) \n" + \
                    ":type all_fields: boolean \n" + \
                    ":rtype: list of strings \n"

        return_dict = {"help": help_str}

        data_dict = self._get_request_data(try_url_params=True)
        all_fields = data_dict.get('all_fields', False)
        order_by = data_dict.get('order_by', 'name')
        sort = data_dict.get('sort', 'name asc')
        organizations = data_dict.get('organizations', [])



        context = {'model': model, 'session': model.Session, 'user': c.user,
                   'api_version': ver, 'auth_user_obj': c.userobj}

        org_list = get_action('organization_list')(context, data_dict)

        if (all_fields):

            #add the child orgs to the response:
            for org in org_list:
                children = []
                branches = get_organization_branches(org['id'])
                group_list = model_dictize.group_list_dictize(branches, context)
                for branch in group_list:
                    d = {}
                    d['title'] = branch['title']
                    children.append(d)

                org['parent_of'] = children

                parents = []
                branches = get_parent_orgs(org['id'])
                group_list = model_dictize.group_list_dictize(branches, context)
                for branch in group_list:
                    d = {}
                    d['title'] = branch['title']
                    parents.append(d)
                org['child_of'] = parents

        return_dict['success'] = True
        return_dict['result'] = org_list
        return self._finish_ok(return_dict)
Ejemplo n.º 4
0
    def organization_list_related(self, ver=None):
        '''
        Returns the list of organizations including parent_of and child_of relationships.
        '''
        # FIXME: use IActions plugin instead
        from ckan.lib.search import SearchError

        help_str =  "Return a list of the names of the site's organizations.\n\n" + \
                    ":param order_by: the field to sort the list by, must be ``'name'`` or \n" + \
                    " ``'packages'`` (optional, default: ``'name'``) Deprecated use sort. \n" + \
                    ":type order_by: string \n" + \
                    ":param sort: sorting of the search results.  Optional.  Default:\n" + \
                    "'name asc' string of field name and sort-order. The allowed fields are \n" + \
                    "'name' and 'packages' \n" + \
                    ":type sort: string \n" + \
                    ":param organizations: a list of names of the groups to return, if given only \n" + \
                    "groups whose names are in this list will be returned (optional) \n" + \
                    ":type organizations: list of strings \n" + \
                    ":param all_fields: return full group dictionaries instead of  just names \n" + \
                    "(optional, default: ``False``) \n" + \
                    ":type all_fields: boolean \n" + \
                    ":rtype: list of strings \n"

        return_dict = {"help": help_str}

        data_dict = self._get_request_data(try_url_params=True)
        all_fields = data_dict.get('all_fields', False)
        order_by = data_dict.get('order_by', 'name')
        sort = data_dict.get('sort', 'name asc')
        organizations = data_dict.get('organizations', [])



        context = {'model': model, 'session': model.Session, 'user': c.user,
                   'api_version': ver, 'auth_user_obj': c.userobj}

        org_list = get_action('organization_list')(context, data_dict)

        if (all_fields):

            #add the child orgs to the response:
            for org in org_list:
                children = []
                branches = get_organization_branches(org['id'])
                group_list = model_dictize.group_list_dictize(branches, context)
                for branch in group_list:
                    d = {}
                    d['title'] = branch['title']
                    children.append(d)

                org['parent_of'] = children

                parents = []
                branches = get_parent_orgs(org['id'])
                group_list = model_dictize.group_list_dictize(branches, context)
                for branch in group_list:
                    d = {}
                    d['title'] = branch['title']
                    parents.append(d)
                org['child_of'] = parents

        return_dict['success'] = True
        return_dict['result'] = org_list
        return self._finish_ok(return_dict)