本文整理汇总了Python中app.needs.Need.exception方法的典型用法代码示例。如果您正苦于以下问题:Python Need.exception方法的具体用法?Python Need.exception怎么用?Python Need.exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.needs.Need
的用法示例。
在下文中一共展示了Need.exception方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: score
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def score(self, obj, user, data):
"""
Sets composition score
:param obj: (object) target
:param user: (object) caller
:param data: (dictionary) data
:return: (int) score
"""
need = Need('grade')
if not obj.can(user, need, obj):
raise need.exception()
score = models.Score(
score=data['score'],
message=data['message'],
grader=user.key)
grade = score.put()
submission = obj.submission.get()
# Create or updated based on existing scores.
if data['source'] == 'composition':
# Only keep any autograded scores.
submission.score = [autograde for autograde in submission.score \
if score.autograder]
submission.score.append(score)
else:
submission.score.append(score)
submission.put()
return score
示例2: get_students
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def get_students(self, course, user, data):
query = models.Participant.query(
models.Participant.course == course.key)
need = Need('staff')
if not models.Participant.can(user, need, course, query):
raise need.exception()
return list(query.fetch())
示例3: post
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def post(self, user, data):
need = Need('create')
if not self.model.can(user, need, None):
raise need.exception()
job_type, filters = data['job_type'], data['filters']
if not isinstance(filters, list):
raise BadValueError('filters must be a list of triples')
for filter in filters:
if len(filter) != 3:
raise BadValueError('filters must be a list of triples')
if job_type not in analytics.available_jobs:
raise BadValueError('job must be of the following types: %s' %
', '.join(list(analytics.available_jobs.keys())))
job = analytics.get_job(job_type, user, filters)
job.start()
return (201, 'success', {
'key': job.job_dump.key.id()
})
示例4: reject_invitation
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def reject_invitation(self, group, user, data):
# can only reject an invitation if you are in the invited_members
need = Need('invitation')
if not group.can(user, need, group):
raise need.exception()
group.invited_members.remove(user.key)
group.put()
示例5: index
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def index(self, user, data):
"""
Index HTTP method. Should be called from GET when no key is provided.
Processes cursor and num_page URL arguments for pagination support.
:param user: (object) caller
:param data: (dictionary)
:return: results for query
"""
query = self.model.query()
need = Need('index')
result = self.model.can(user, need, query=query)
if not result:
raise need.exception()
query = filter_query(result, data, self.model)
created_prop = getattr(self.model, 'created', None)
if not query.orders and created_prop:
logging.info('Adding default ordering by creation time.')
query = query.order(-created_prop, self.model.key)
page = int(request.args.get('page', 1))
# default page length is 100
num_page = int(request.args.get('num_page', 100))
query_results = paginate(query, page, num_page)
add_statistics = request.args.get('stats', False)
if add_statistics:
query_results['statistics'] = self.statistics()
return query_results
示例6: remove_staff
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def remove_staff(self, course, user, data):
need = Need("staff")
if not course.can(user, need, course):
raise need.exception()
if data['staff_member'] in course.staff:
course.staff.remove(data['staff_member'])
course.put()
示例7: remove_member
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def remove_member(self, group, user, data):
# can only remove a member if you are a member
need = Need('member')
if not group.can(user, need, group):
raise need.exception()
if data['member'] in group.members:
group.members.remove(data['member'])
elif data['member'] in group.invited_members:
group.invited_members.remove(data['member'])
if len(group.members) == 0:
group.key.delete()
description = "Deleted group"
else:
group.put()
description = "Changed group"
audit_log_message = models.AuditLog(
event_type='Group.remove_member',
user=user.key,
obj=group.key,
description=description
)
audit_log_message.put()
示例8: get_staff
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def get_staff(self, course, user, data):
need = Need('staff')
if not course.can(user, need, course):
raise need.exception()
query = models.Participant.query(
models.Participant.course == course.key,
models.Participant.role == 'staff')
return list(query.fetch())
示例9: current
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def current(self, obj, user, data):
need = Need('get')
if not obj.can(user, need, obj):
raise need.exception()
if not obj.current_version:
raise BadValueError(
'Invalid version resource. Contact an administrator.')
return obj.current_version
示例10: add_staff
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def add_staff(self, course, user, data):
need = Need('staff')
if not course.can(user, need, course):
raise need.exception()
user = models.User.get_or_insert(data['email'])
if user not in course.staff:
models.Participant.add_role(user, course, STAFF_ROLE)
示例11: remove_staff
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def remove_staff(self, course, user, data):
need = Need('staff')
if not course.can(user, need, course):
raise need.exception()
removed_user = models.User.lookup(data['email'])
if removed_user:
models.Participant.remove_role(removed_user, course, STAFF_ROLE)
示例12: invite
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def invite(self, group, user, data):
need = Need('invite')
if not group.can(user, need, group):
return need.exception()
error = group.invite(data['email'])
if error:
raise BadValueError(error)
示例13: download
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def download(self, obj, user, data):
need = Need('get')
if not obj.can(user, need, obj):
raise need.exception()
if 'version' not in data:
download_link = obj.download_link()
else:
download_link = obj.download_link(data['version'])
return redirect(download_link)
示例14: add_staff
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def add_staff(self, course, user, data):
need = Need("staff")
if not course.can(user, need, course):
raise need.exception()
if data['staff_member'] not in course.staff:
user = models.User.get_or_insert(data['staff_member'].id())
course.staff.append(user.key)
course.put()
示例15: create_staff
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import exception [as 别名]
def create_staff(self, obj, user, data):
# Must be a staff to create a staff user
need = Need("staff")
if not obj.can(user, need, obj):
raise need.exception()
user = models.User.get_or_insert(data['email'].id())
user.role = data['role']
user.put()