当前位置: 首页>>代码示例>>Python>>正文


Python logic.validate方法代码示例

本文整理汇总了Python中ckan.logic.validate方法的典型用法代码示例。如果您正苦于以下问题:Python logic.validate方法的具体用法?Python logic.validate怎么用?Python logic.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ckan.logic的用法示例。


在下文中一共展示了logic.validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: followee_count

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import validate [as 别名]
def followee_count(context, data_dict):
    '''Return the number of objects that are followed by the given user.

    Counts all objects, of any type, that the given user is following
    (e.g. followed users, followed datasets, followed groups).

    :param id: the id of the user
    :type id: string

    :rtype: int

    '''
    model = context['model']
    followee_users = _followee_count(context, data_dict,
                                     model.UserFollowingUser)

    # followee_users has validated data_dict so the following functions don't
    # need to validate it again.
    context['skip_validation'] = True

    followee_datasets = _followee_count(context, data_dict,
                                        model.UserFollowingDataset)
    followee_groups = _followee_count(context, data_dict,
                                      model.UserFollowingGroup)

    return sum((followee_users, followee_datasets, followee_groups)) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:28,代码来源:get.py

示例2: powerview_create

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import validate [as 别名]
def powerview_create(context, data_dict):
    '''Create a new powerview.

    You must provide your API key in the Authorization header.

    :param title: title of the powerview
    :type title: string
    :param description: a description for the powerview (optional)
    :type description: string
    :param view_type: type of view
    :type view_type: string
    :param resources: resource ids available for this view (optional)
    :type resources: list
    :param config: options necessary to recreate a view state (optional)
    :type config: JSON string
    :param owner_org: id of the owning organization (optional)
    :type owner_org: string
    :param private: determines if view is publicly accessible (optional,
        defaults to False)
    :type private: boolean

    '''
    toolkit.check_access('ckanext_powerview_create', context, data_dict)

    user = context['user']
    user_obj = model.User.get(user)
    data_dict['created_by'] = user_obj.id

    powerview = PowerView(**data_dict)

    session = context['session']
    session.add(powerview)
    session.commit()

    for res_id in data_dict.get('resources', []):
        # We validate for id duplication, so this shouldn't be true during
        # create.
        if PowerviewResourceAssociation.exists(powerview_id=powerview.id,
                                               resource_id=res_id):
            raise toolkit.ValidationError("Resource already associated with powerview.",
                                          error_summary=u"The resource, {0}, is already in the powerview".format(res_id))

        # create the association
        PowerviewResourceAssociation.create(resource_id=res_id,
                                            powerview_id=powerview.id)

    return powerview.as_dict() 
开发者ID:OCHA-DAP,项目名称:ckanext-powerview,代码行数:49,代码来源:create.py


注:本文中的ckan.logic.validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。