本文整理匯總了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))
示例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()