當前位置: 首頁>>代碼示例>>Python>>正文


Python logic.ValidationError方法代碼示例

本文整理匯總了Python中ckan.logic.ValidationError方法的典型用法代碼示例。如果您正苦於以下問題:Python logic.ValidationError方法的具體用法?Python logic.ValidationError怎麽用?Python logic.ValidationError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ckan.logic的用法示例。


在下文中一共展示了logic.ValidationError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_object

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def _get_object(context, data_dict, name, class_name):
    # return the named item if in the data_dict, or get it from
    # model.class_name
    try:
        return context[name]
    except KeyError:
        model = context['model']
        if not data_dict:
            data_dict = {}
        id = data_dict.get('id', None)
        if not id:
            raise logic.ValidationError('Missing id, can not get {0} object'
                                        .format(class_name))
        obj = getattr(model, class_name).get(id)
        if not obj:
            raise logic.NotFound
        # Save in case we need this again during the request
        context[name] = obj
        return obj 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:21,代碼來源:__init__.py

示例2: vocabulary_show

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def vocabulary_show(context, data_dict):
    '''Return a single tag vocabulary.

    :param id: the id or name of the vocabulary
    :type id: string
    :return: the vocabulary.
    :rtype: dictionary

    '''
    _check_access('vocabulary_show', context, data_dict)

    model = context['model']
    vocab_id = data_dict.get('id')
    if not vocab_id:
        raise ValidationError({'id': _('id not in data')})
    vocabulary = model.vocabulary.Vocabulary.get(vocab_id)
    if vocabulary is None:
        raise NotFound(_('Could not find vocabulary "%s"') % vocab_id)
    vocabulary_dict = model_dictize.vocabulary_dictize(vocabulary, context)
    return vocabulary_dict 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:22,代碼來源:get.py

示例3: _follower_list

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def _follower_list(context, data_dict, default_schema, FollowerClass):
    schema = context.get('schema', default_schema)
    data_dict, errors = _validate(data_dict, schema, context)
    if errors:
        raise ValidationError(errors)

    # Get the list of Follower objects.
    model = context['model']
    object_id = data_dict.get('id')
    followers = FollowerClass.follower_list(object_id)

    # Convert the list of Follower objects to a list of User objects.
    users = [model.User.get(follower.follower_id) for follower in followers]
    users = [user for user in users if user is not None]

    # Dictize the list of User objects.
    return model_dictize.user_list_dictize(users, context) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:19,代碼來源:get.py

示例4: _group_or_org_followee_list

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def _group_or_org_followee_list(context, data_dict, is_org=False):

    if not context.get('skip_validation'):
        schema = context.get('schema',
                             ckan.logic.schema.default_follow_user_schema())
        data_dict, errors = _validate(data_dict, schema, context)
        if errors:
            raise ValidationError(errors)

    # Get the list of UserFollowingGroup objects.
    model = context['model']
    user_id = _get_or_bust(data_dict, 'id')
    followees = model.UserFollowingGroup.followee_list(user_id)

    # Convert the UserFollowingGroup objects to a list of Group objects.
    groups = [model.Group.get(followee.object_id) for followee in followees]
    groups = [group for group in groups
              if group is not None and group.is_organization == is_org]

    # Dictize the list of Group objects.
    return [model_dictize.group_dictize(group, context) for group in groups] 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:23,代碼來源:get.py

示例5: _unpick_search

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def _unpick_search(sort, allowed_fields=None, total=None):
    ''' This is a helper function that takes a sort string
    eg 'name asc, last_modified desc' and returns a list of
    split field order eg [('name', 'asc'), ('last_modified', 'desc')]
    allowed_fields can limit which field names are ok.
    total controls how many sorts can be specifed '''
    sorts = []
    split_sort = sort.split(',')
    for part in split_sort:
        split_part = part.strip().split()
        field = split_part[0]
        if len(split_part) > 1:
            order = split_part[1].lower()
        else:
            order = 'asc'
        if allowed_fields:
            if field not in allowed_fields:
                raise ValidationError('Cannot sort by field `%s`' % field)
        if order not in ['asc', 'desc']:
            raise ValidationError('Invalid sort direction `%s`' % order)
        sorts.append((field, order))
    if total and len(sorts) > total:
        raise ValidationError(
            'Too many sort criteria provided only %s allowed' % total)
    return sorts 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:27,代碼來源:get.py

示例6: send_email_notifications

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def send_email_notifications(context, data_dict):
    '''Send any pending activity stream notification emails to users.

    You must provide a sysadmin's API key in the Authorization header of the
    request, or call this action from the command-line via a `paster post ...`
    command.

    '''
    # If paste.command_request is True then this function has been called
    # by a `paster post ...` command not a real HTTP request, so skip the
    # authorization.
    if not request.environ.get('paste.command_request'):
        _check_access('send_email_notifications', context, data_dict)

    if not converters.asbool(
            config.get('ckan.activity_streams_email_notifications')):
        raise ValidationError('ckan.activity_streams_email_notifications'
                              ' is not enabled in config')

    email_notifications.get_and_send_notifications_for_all_users() 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:22,代碼來源:update.py

示例7: test_user_update_without_email_address

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def test_user_update_without_email_address(self):
        '''You have to pass an email address when you call user_update.

        Even if you don't want to change the user's email address, you still
        have to pass their current email address to user_update.

        FIXME: The point of this feature seems to be to prevent people from
        removing email addresses from user accounts, but making them post the
        current email address every time they post to user update is just
        annoying, they should be able to post a dict with no 'email' key to
        user_update and it should simply not change the current email.

        '''
        user = factories.User()
        del user['email']

        assert_raises(logic.ValidationError,
                      helpers.call_action, 'user_update',
                      **user)

    # TODO: Valid and invalid values for the rest of the user model's fields. 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:23,代碼來源:test_update.py

示例8: test_activity_list_actions

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def test_activity_list_actions(self):
        actions = [
            'user_activity_list',
            'package_activity_list',
            'group_activity_list',
            'organization_activity_list',
            'recently_changed_packages_activity_list',
            'user_activity_list_html',
            'package_activity_list_html',
            'group_activity_list_html',
            'organization_activity_list_html',
            'recently_changed_packages_activity_list_html',
            'current_package_list_with_resources',
        ]
        for action in actions:
            nose.tools.assert_raises(
                logic.ValidationError, helpers.call_action, action,
                id='test_user', limit='not_an_int', offset='not_an_int')
            nose.tools.assert_raises(
                logic.ValidationError, helpers.call_action, action,
                id='test_user', limit=-1, offset=-1) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:23,代碼來源:test_get.py

示例9: test_smtp_error_returns_error_message

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def test_smtp_error_returns_error_message(self):

        sysadmin = factories.Sysadmin()
        group = factories.Group()

        context = {
            'user': sysadmin['name']
        }
        params = {
            'email': '[email protected]',
            'group_id': group['id'],
            'role': 'editor'
        }

        assert_raises(logic.ValidationError, helpers.call_action,
                      'user_invite', context, **params)

        # Check that the pending user was deleted
        user = model.Session.query(model.User).filter(
            model.User.name.like('example-invited-user%')).all()

        assert_equals(user[0].state, 'deleted') 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:24,代碼來源:test_create.py

示例10: _save_edit

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def _save_edit(self, id, context):
        try:
            data_dict = clean_dict(dict_fns.unflatten(
                tuplize_dict(parse_params(request.params))))
            context['message'] = data_dict.get('log_message', '')
            data_dict['id'] = id
            context['allow_partial_update'] = True
            group = self._action('group_update')(context, data_dict)
            if id != group['name']:
                self._force_reindex(group)

            h.redirect_to('%s_read' % group['type'], id=group['name'])
        except (NotFound, NotAuthorized), e:
            abort(404, _('Group not found'))
        except dict_fns.DataError:
            abort(400, _(u'Integrity Error'))
        except ValidationError, e:
            errors = e.error_dict
            error_summary = e.error_summary
            return self.edit(id, data_dict, errors, error_summary) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:22,代碼來源:group.py

示例11: activity

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def activity(self, id, offset=0):
        '''Render this group's public activity stream page.'''

        group_type = self._ensure_controller_matches_group_type(id)
        context = {'model': model, 'session': model.Session,
                   'user': c.user, 'for_view': True}
        try:
            c.group_dict = self._get_group_dict(id)
        except (NotFound, NotAuthorized):
            abort(404, _('Group not found'))

        try:
            # Add the group's activity stream (already rendered to HTML) to the
            # template context for the group/read.html
            # template to retrieve later.
            c.group_activity_stream = self._action('group_activity_list_html')(
                context, {'id': c.group_dict['id'], 'offset': offset})

        except ValidationError as error:
            base.abort(400)

        return render(self._activity_template(group_type),
                      extra_vars={'group_type': group_type}) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:25,代碼來源:group.py

示例12: follow

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def follow(self, id):
        '''Start following this group.'''
        self._ensure_controller_matches_group_type(id)
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user}
        data_dict = {'id': id}
        try:
            get_action('follow_group')(context, data_dict)
            group_dict = get_action('group_show')(context, data_dict)
            h.flash_success(_("You are now following {0}").format(
                group_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except NotAuthorized as e:
            h.flash_error(e.message)
        h.redirect_to(controller='group', action='read', id=id) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:21,代碼來源:group.py

示例13: unfollow

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def unfollow(self, id):
        '''Stop following this group.'''
        self._ensure_controller_matches_group_type(id)
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user}
        data_dict = {'id': id}
        try:
            get_action('unfollow_group')(context, data_dict)
            group_dict = get_action('group_show')(context, data_dict)
            h.flash_success(_("You are no longer following {0}").format(
                group_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except (NotFound, NotAuthorized) as e:
            error_message = e.message
            h.flash_error(error_message)
        h.redirect_to(controller='group', action='read', id=id) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:22,代碼來源:group.py

示例14: follow

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def follow(self, id):
        '''Start following this dataset.'''
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user, 'auth_user_obj': c.userobj}
        data_dict = {'id': id}
        try:
            get_action('follow_dataset')(context, data_dict)
            package_dict = get_action('package_show')(context, data_dict)
            h.flash_success(_("You are now following {0}").format(
                package_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except NotAuthorized as e:
            h.flash_error(e.message)
        h.redirect_to(controller='package', action='read', id=id) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:20,代碼來源:package.py

示例15: unfollow

# 需要導入模塊: from ckan import logic [as 別名]
# 或者: from ckan.logic import ValidationError [as 別名]
def unfollow(self, id):
        '''Stop following this dataset.'''
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user, 'auth_user_obj': c.userobj}
        data_dict = {'id': id}
        try:
            get_action('unfollow_dataset')(context, data_dict)
            package_dict = get_action('package_show')(context, data_dict)
            h.flash_success(_("You are no longer following {0}").format(
                package_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except (NotFound, NotAuthorized) as e:
            error_message = e.message
            h.flash_error(error_message)
        h.redirect_to(controller='package', action='read', id=id) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:21,代碼來源:package.py


注:本文中的ckan.logic.ValidationError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。