本文整理汇总了Python中udata.api.api.validate函数的典型用法代码示例。如果您正苦于以下问题:Python validate函数的具体用法?Python validate怎么用?Python validate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validate函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
'''Create a new scheduled job'''
if 'crontab' in request.json and 'interval' in request.json:
api.abort(400, 'Cannot define both interval and crontab schedule')
if 'crontab' in request.json:
form = api.validate(CrontabTaskForm)
else:
form = api.validate(IntervalTaskForm)
return form.save(), 201
示例2: put
def put(self, id):
'''Update a single scheduled job'''
task = self.get_or_404(id)
if 'crontab' in request.json:
task.interval = None
task.crontab = PeriodicTask.Crontab()
form = api.validate(CrontabTaskForm, task)
else:
task.crontab = None
task.interval = PeriodicTask.Interval()
form = api.validate(IntervalTaskForm, task)
return form.save()
示例3: put
def put(self, org):
"""Update a organization given its identifier"""
if org.deleted:
api.abort(410, "Organization has been deleted")
EditOrganizationPermission(org).test()
form = api.validate(OrganizationForm, org)
return form.save()
示例4: put
def put(self, reuse):
'''Update a given reuse'''
if reuse.deleted:
api.abort(410, 'This reuse has been deleted')
ReuseEditPermission(reuse).test()
form = api.validate(ReuseForm, reuse)
return form.save()
示例5: post
def post(self, ident):
'''Validate or reject an harvest source'''
form = api.validate(HarvestSourceValidationForm)
if form.state.data == VALIDATION_ACCEPTED:
return actions.validate_source(ident, form.comment.data)
else:
return actions.reject_source(ident, form.comment.data)
示例6: put
def put(self, reuse):
'''Update a given reuse'''
request_deleted = request.json.get('deleted', True)
if reuse.deleted and request_deleted is not None:
api.abort(410, 'This reuse has been deleted')
ReuseEditPermission(reuse).test()
form = api.validate(ReuseForm, reuse)
return form.save()
示例7: put
def put(self, org, user):
'''Update member status into a given organization.'''
EditOrganizationPermission(org).test()
member = org.member(user)
form = api.validate(MemberForm, member)
form.populate_obj(member)
org.save()
return member
示例8: put
def put(self, community):
'''Update a given community resource'''
form = api.validate(CommunityResourceForm, community)
form.populate_obj(community)
if not community.organization:
community.owner = current_user._get_current_object()
community.modified = datetime.now()
community.save()
return community
示例9: post
def post(self, dataset):
'''Create a new resource for a given dataset'''
ResourceEditPermission(dataset).test()
form = api.validate(ResourceForm)
resource = Resource()
form.populate_obj(resource)
dataset.add_resource(resource)
dataset.last_modified = datetime.now()
dataset.save()
return resource, 201
示例10: post
def post(self, reuse):
'''Create a new badge for a given reuse'''
form = api.validate(BadgeForm)
badge = ReuseBadge(created=datetime.now(),
created_by=current_user.id)
form.populate_obj(badge)
for existing_badge in reuse.badges:
if existing_badge.kind == badge.kind:
return existing_badge
reuse.add_badge(badge)
return badge, 201
示例11: post
def post(self, org):
"""Create a new badge for a given organization"""
Form = badge_form(Organization)
form = api.validate(Form)
badge = Badge(created=datetime.now(), created_by=current_user.id)
form.populate_obj(badge)
for existing_badge in org.badges:
if existing_badge.kind == badge.kind:
return existing_badge
org.add_badge(badge)
return badge, 201
示例12: post
def post(self, org, id):
'''Refuse user membership to a given organization.'''
membership_request = self.get_or_404(org, id)
form = api.validate(MembershipRefuseForm)
membership_request.status = 'refused'
membership_request.handled_by = current_user._get_current_object()
membership_request.handled_on = datetime.now()
membership_request.refusal_comment = form.comment.data
org.save()
return {}, 200
示例13: add
def add(obj):
'''
Handle a badge add API.
- Expecting badge_fieds as payload
- Return the badge as payload
- Return 200 if the badge is already
- Return 201 if the badge is added
'''
Form = badge_form(obj.__class__)
form = api.validate(Form)
kind = form.kind.data
badge = obj.get_badge(kind)
if badge:
return badge
else:
return obj.add_badge(kind), 201
示例14: post
def post(self, id):
'''Add comment and optionnaly close an issue given its ID'''
issue = Issue.objects.get_or_404(id=id)
form = api.validate(IssueCommentForm)
message = Message(
content=form.comment.data,
posted_by=current_user.id
)
issue.discussion.append(message)
close = form.close.data
if close:
CloseIssuePermission(issue).test()
issue.closed_by = current_user._get_current_object()
issue.closed = datetime.now()
issue.save()
if close:
on_issue_closed.send(issue, message=message)
else:
on_new_issue_comment.send(issue, message=message)
return issue