本文整理匯總了Python中server.models.User.lookup方法的典型用法代碼示例。如果您正苦於以下問題:Python User.lookup方法的具體用法?Python User.lookup怎麽用?Python User.lookup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類server.models.User
的用法示例。
在下文中一共展示了User.lookup方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: staff_group_add
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def staff_group_add(cid, email, aid):
assign = Assignment.query.filter_by(id=aid, course_id=cid).one_or_none()
if not assign or not Assignment.can(assign, current_user, 'grade'):
flash('Cannot access assignment', 'error')
return abort(404)
form = forms.StaffAddGroupFrom()
result_page = url_for('.student_assignment_detail', cid=cid,
email=email, aid=aid)
student = User.lookup(email)
if not student:
return abort(404)
if form.validate_on_submit():
target = User.lookup(form.email.data)
if not target or not target.is_enrolled(cid):
flash("This user is not enrolled", 'warning')
return redirect(result_page)
try:
Group.force_add(current_user, student, target, assign)
except BadRequest as e:
flash("Error: {}".format(str(e.description)), 'error')
return redirect(result_page)
return redirect(result_page)
示例2: test_lookup
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_lookup(self):
email = '[email protected]'
user = User.lookup(email)
assert user is None
db.session.add(User(email=email))
db.session.commit()
user = User.lookup(email)
assert user.email == email
示例3: test_enroll_from_form
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_enroll_from_form(self):
self.setup_course()
Enrollment.enroll_from_form(self.course.id, make_enrollment_form(self.studentB))
user = User.lookup(self.studentB['email'])
self.studentB['id'] = user.id
self.enrollment_matches_info(user, self.studentB)
Enrollment.enroll_from_form(self.course.id, make_enrollment_form(self.lab_assistantA))
lab_assistant = User.lookup(self.lab_assistantA['email'])
self.lab_assistantA['id'] = lab_assistant.id
self.enrollment_matches_info(lab_assistant, self.lab_assistantA)
示例4: test_enroll_from_csv
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_enroll_from_csv(self):
self.setup_course()
template = "{email},{name},{sid},{class_account},{section}"
form = BatchEnrollmentForm()
form.csv.data = template.format(**self.studentA) + "\n" + template.format(**self.studentB)
Enrollment.enroll_from_csv(self.course.id, form)
user_a = User.lookup(self.studentA['email'])
self.studentA['id'] = user_a.id
self.enrollment_matches_info(user_a, self.studentA)
user_b = User.lookup(self.studentB['email'])
self.studentB['id'] = user_b.id
self.enrollment_matches_info(user_b, self.studentB)
示例5: test_score_staff
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_score_staff(self):
self._test_backup(True)
user = User.lookup(self.user1.email)
self.login(self.staff1.email)
response = self.client.post('/api/v3/score/')
self.assert_400(response)
assert response.json['code'] == 400
backup = Backup.query.filter(Backup.submitter_id == user.id).first()
data = {'bid': encode_id(backup.id), 'kind': 'Total',
'score': 128.2, 'message': 'wow'}
response = self.client.post('/api/v3/score/', data=data)
self.assert_200(response)
assert response.json['code'] == 200
self.logout()
self.login(self.admin.email)
data = {'bid': encode_id(backup.id), 'kind': 'Total',
'score': 128.2, 'message': 'wow'}
response = self.client.post('/api/v3/score/', data=data)
self.assert_200(response)
assert response.json['code'] == 200
示例6: staff_flag_backup
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def staff_flag_backup(cid, email, aid):
assign = Assignment.query.filter_by(id=aid, course_id=cid).one_or_none()
if not assign or not Assignment.can(assign, current_user, 'grade'):
return abort(404)
result_page = url_for('.student_assignment_detail', cid=cid,
email=email, aid=aid)
student = User.lookup(email)
if not student:
abort(404)
user_ids = assign.active_user_ids(student.id)
bid = request.form.get('bid')
form = forms.CSRFForm()
if form.validate_on_submit():
backup = Backup.query.filter_by(id=utils.decode_id(bid),
assignment=assign).one_or_none()
if not backup:
flash('{} does not exist'.format(bid, 'error'))
return redirect(result_page)
if not backup.flagged:
result = assign.flag(backup.id, user_ids)
flash('Flagged backup {} for grading'.format(bid), 'success')
else:
result = assign.unflag(backup.id, user_ids)
flash('Removed grading flag on {}'.format(bid), 'success')
return redirect(result_page)
示例7: test_assignment_api
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_assignment_api(self):
self._test_backup(True)
student = User.lookup(self.user1.email)
endpoint = '/api/v3/assignment/{0}'.format(self.assignment.name)
# View a public assignment
response = self.client.get(endpoint)
self.assert_200(response)
# Change assignment to be hidden
self.assignment.visible = False
db.session.commit()
response = self.client.get(endpoint)
self.assert_403(response)
self.assignment.visible = True
db.session.commit()
self.login(self.staff1.email)
response = self.client.get(endpoint)
self.assert_200(response)
self.assertEqual(response.json['data']['name'], self.assignment.name)
# Hidden assignment, but should be visible to staff
self.assignment.visible = False
db.session.commit()
response = self.client.get(endpoint)
self.assert_200(response)
self.login(self.user1.email)
self.assignment.visible = False
db.session.commit()
response = self.client.get(endpoint)
self.assert_403(response)
示例8: test_export_final
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_export_final(self):
self._test_backup(True)
student = User.lookup(self.user1.email)
backup = Backup.query.filter(Backup.submitter_id == student.id).first()
endpoint = '/api/v3/assignment/{0}/submissions/'.format(self.assignment.name)
response = self.client.get(endpoint)
self.assert_403(response)
self.login(self.staff1.email)
response = self.client.get(endpoint)
self.assert_200(response)
backups = response.json['data']['backups']
self.assertEqual(len(backups), 1)
self.assertEqual(backups[0]['is_late'], False)
self.assertEqual(len(backups[0]['group']), 1)
self.assertEqual(backups[0]['group'][0]['email'], self.user1.email)
self.assertEqual(len(backups[0]['messages']), 1)
self.assertEqual(response.json['data']['count'], 1)
self.assertEqual(response.json['data']['has_more'], False)
self.assertEqual(response.json['data']['offset'], 0)
response = self.client.get(endpoint + '?offset=1')
self.assert_200(response)
backups = response.json['data']['backups']
self.assertEqual(len(backups), 0)
self.assertEqual(response.json['data']['count'], 1)
self.assertEqual(response.json['data']['has_more'], False)
self.assertEqual(response.json['data']['offset'], 1)
示例9: test_export_user
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_export_user(self):
self._test_backup(True)
student = User.lookup(self.user1.email)
self.login(self.staff1.email)
backup = Backup.query.filter(Backup.submitter_id == student.id).first()
endpoint = '/api/v3/assignment/{0}/export/{1}'.format(self.assignment.name,
student.email)
response = self.client.get(endpoint)
self.assert_200(response)
backups = response.json['data']['backups']
self.assertEqual(len(backups), 1)
self.assertTrue('submission_time' in backups[0])
self.assertEqual(backups[0]['submission_time'], backups[0]['created'])
self.assertEqual(response.json['data']['count'], 1)
self.assertEqual(response.json['data']['limit'], 150)
self.assertEqual(response.json['data']['offset'], 0)
self.assertEqual(response.json['data']['has_more'], False)
response = self.client.get(endpoint + "?offset=20&limit=2")
self.assert_200(response)
backups = response.json['data']['backups']
self.assertEqual(len(backups), 0)
self.assertEqual(response.json['data']['count'], 1)
self.assertEqual(response.json['data']['limit'], 2)
self.assertEqual(response.json['data']['offset'], 20)
self.assertEqual(response.json['data']['has_more'], False)
示例10: user_from_email
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def user_from_email(email):
"""Get a User with the given email, or create one."""
user = User.lookup(email)
if not user:
user = User(email=email)
db.session.add(user)
db.session.commit()
return user
示例11: user_from_email
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def user_from_email(email):
"""Get a User with the given email, or create one."""
user = User.lookup(email)
if not user:
logger.info("Creating user {}".format(email))
user = User(email=email)
db.session.add(user)
db.session.commit()
return user
示例12: test_get_comments
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_get_comments(self):
self._test_backup(True)
user = User.lookup(self.user1.email)
staff = User.lookup(self.staff1.email)
backup = Backup.query.filter(Backup.submitter_id == user.id).first()
comment_url = "/api/v3/backups/{}/comment/".format(encode_id(backup.id))
comment1 = Comment(
backupid = backup,
author_id = staff.id,
filename = 'fizzbuzz.py',
line = 2,
message = 'hello world'
)
comment2 = Comment(
backupid = backup,
author_id = staff.id,
filename = 'fizzbuzz.py',
line = 5,
message = 'wow'
)
db.session.add(comment1)
db.session.add(comment2)
#check to see if student can view comments on own backup's comments
self.login(self.user1.email)
response = self.client.get(comment_url)
self.assert_200(response)
self.assertEqual(len(response['data']['comments']), 2)
self.assertEqual(response['data']['comments'][0].message, 'hello world')
self.assertEqual(response['data']['comments'][1].message, 'wow')
self.logout()
#check to see if staff can access comments
self.login(self.staff1.email)
response = self.client.get(comment_url)
self.assert_200(response)
self.logout()
#check to see another student can't see others' backup's comments
self.login(self.user2.email)
response = self.client.get(comment_url)
self.assert_403(response)
self.logout()
示例13: test_enroll_twice
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_enroll_twice(self):
self.setup_course()
form = make_enrollment_form(self.studentB)
Enrollment.enroll_from_form(self.course.id, form)
user = User.lookup(self.studentB['email'])
self.studentB['id'] = user.id
self.enrollment_matches_info(user, self.studentB)
form = make_enrollment_form(self.studentB_alt)
Enrollment.enroll_from_form(self.course.id, form)
user_updated = User.lookup(self.studentB['email'])
self.studentB_alt['id'] = user_updated.id
assert user.id == user_updated.id
self.enrollment_matches_info(user, self.studentB_alt)
示例14: test_user_api
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def test_user_api(self):
self._test_backup(True)
self.logout()
student = User.lookup(self.user1.email)
def test_both_endpoints(user):
base_api = '/api/v3/user/{0}'
user1_endpoint = base_api.format(user.email)
current_user_endpoint = base_api.format('')
current = self.client.get(current_user_endpoint)
specific = self.client.get(user1_endpoint)
return current, specific
current, specific = test_both_endpoints(student)
self.assert_401(current)
self.assert_401(specific)
# Should be able to view self
self.login(self.user1.email)
current, specific = test_both_endpoints(student)
self.assert_200(current)
self.assert_200(specific)
members = current.json['data']['participations']
self.assertEqual(len(members), 1)
self.assertEqual(current.json['data'], specific.json['data'])
# Staff don't get permission
self.login(self.staff1.email)
current, specific = test_both_endpoints(student)
self.assert_200(current)
self.assert_403(specific)
# Login as some random user
self.login(self.user3.email)
current, specific = test_both_endpoints(student)
self.assert_200(current)
self.assert_403(specific)
# Admins should have acess
self.login(self.admin.email)
current, specific = test_both_endpoints(student)
self.assert_200(current)
self.assert_200(specific)
self.assertEqual(specific.json['data']['email'], student.email)
# Lab Assistants don't have access
self.login(self.lab_assistant1.email)
current, specific = test_both_endpoints(student)
self.assert_200(current)
self.assert_403(specific)
示例15: sudo_login
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import lookup [as 別名]
def sudo_login(email):
logger.info("Sudo attempt to %s from %s", email, current_user)
if not current_user.is_admin:
logger.info("Unauthorized sudo %s", current_user)
return abort(403, 'Unauthorized to sudo')
user = User.lookup(email)
if not user:
return abort(404, "User does not exist")
logger.info("Sudo Mode: %s from %s", email, current_user)
session['sudo-user'] = current_user.email
return authorize_user(user)