本文整理匯總了Python中server.models.User類的典型用法代碼示例。如果您正苦於以下問題:Python User類的具體用法?Python User怎麽用?Python User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了User類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: qq_weibo_get_code
def qq_weibo_get_code():
code = request.args['code']
openid = request.args['openid']
openkey = request.args['openkey']
qqbot = db.session.query(Bot).filter(Bot.type == 1).one()
bot = qqbot.build_bot()
resp = bot.request_access_token(code)
resp.openid = openid
resp.openkey = openkey
logger.debug(resp)
u = db.session.query(User).filter(User.openid == openid)
if u.count():
u = u.one()
u.assign(resp)
else:
u = User()
u.assign(resp)
db.session.add(u)
logger.info('Created new user <%s %s>' % (u.name, u.openid))
db.session.commit()
if not u.token:
u.generate_token()
return 'your arm server token: %s' % (u.token)
示例2: post
def post(self):
data = request.form
print data
if len(set(['name', 'cost', 'payer', 'buyins']) &
set([x for x in data])) == 4:
# Validate that users involved have accounts
# Extract payer id
payer = User.objects(username=data['payer'])
payer_id = payer[0].id
# Extract ids of those who buy in
buyins = User.objects(username__in=data['buyins'])
buyin_ids = map(lambda x: x.id, buyins)
purchase = Purchase(name=data['name'],
cost=data['cost'],
payer=payer_id,
buyins=buyin_ids,
time=datetime.datetime.now())
purchase.save()
debt_up_to_date = self.updateDebt(purchase)
return jsonify({'res': True,
'messsage': 'Purchase added',
'debts': debt_up_to_date})
return jsonify({'res': False,
'message': 'default'})
示例3: test_user_password
def test_user_password(self, testapp):
""" Test password hashing and checking """
admin = User('admin', 'supersafepassword')
assert admin.username == 'admin'
assert admin.check_password('supersafepassword')
示例4: setUp
def setUp(self):
t = Tool(id=1, name='test_tool', status=1, status_message='working ok')
t.save()
u = User(id=1, name='Test user', subscribed=True)
u.card_set.add(Card(card_id='12345678'))
u.save()
示例5: staff_group_add
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)
示例6: test_is_staff
def test_is_staff(self):
self.setup_course()
random_user = User(name=self.studentA['name'], email=self.studentA['email'])
db.session.add(random_user)
db.session.commit()
self.assertTrue(self.staff1.is_staff())
self.assertTrue(self.admin.is_staff())
self.assertFalse(self.user1.is_staff())
self.assertFalse(random_user.is_staff())
示例7: post
def post(self):
try:
username = generate_username()
user = User(username=username)
user.save()
self.write(json.dumps(user.to_representation()))
except Chat.DoesNotExist:
self.clear()
self.set_status(404)
self.finish({'error': 'not found'})
示例8: test_lookup
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
示例9: post
def post(self):
if self.registration_form.validate_on_submit():
try:
user = User(self.registration_form.login.data, self.registration_form.password.data)
user.email = self.registration_form.email.data
db.session.add(user)
db.session.commit()
session['userId'] = user.id
flash('Willkommen Benutzer "%s".' % user.login, 'info')
return redirect(url_for('vote.home.inactive'))
except IntegrityError:
self.registration_form.login.errors.append("Eine Benutzer mit diesem Login existiert bereits")
return self.render()
return self.render()
示例10: me
def me(user: User):
"""
User object representation ready for JSON serialization.
:param user: User object
:return: Dictionary with User representation fields
"""
return {
'id': user.id,
'nickname': user.nickname,
'university': University.query.get(user.university).name,
'gender': user.get_gender(),
'boards': [board(b) for b in user.get_boards()],
'profilepic': user.profilepic
}
示例11: test_enroll_from_form
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)
示例12: test_basic
def test_basic(self):
i = User(username='alice', email='[email protected]')
j = User(username='bob', email='[email protected]')
db.session.add(i)
db.session.add(j)
db.session.commit()
t = i.create_task(title='I want to test', abstract='a test', content='I want to test the test part.')
# db.session.add(t)
# db.session.commit()
assert len(i.watched_tasks) == 1
assert len(t.watcher.all()) == 1
j.watch_task(t)
assert len(i.watched_tasks) == 1
assert len(t.watcher.all()) == 2
assert j in t.watcher.all()
示例13: test_score_staff
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
示例14: test_export_final
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)
示例15: test_export_user
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)