本文整理汇总了Python中model.User.objects方法的典型用法代码示例。如果您正苦于以下问题:Python User.objects方法的具体用法?Python User.objects怎么用?Python User.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def test_create_user(self):
response = self.client.post(
url_for('api.create_users'),
headers={
'Content-Type': 'application/json'
},
data=json.dumps([
{
"uid": "1",
"name": "John Doe",
"date": "2015-05-12T14:36:00.451765",
"md5checksum": "e8c83e232b64ce94fdd0e4539ad0d44f"
},
{
"uid": "2",
"name": "Jane Doe",
"date": "2015-05-13T14:36:00.451765",
"md5checksum": "b419795d50db2a35e94c8364978d898f"
}
]
)
)
results = response.json['status']
# Verify the results are returned correctly
self.assertEqual(results[0]['saved'], 1)
self.assertEqual(results[1]['saved'], 0)
# Verify if the database is updated
users = User.objects(uid=1)
self.assertEqual(len(users), 1)
user = users[0]
self.assertEqual(user.name, "John Doe")
self.assertEqual(user.date, parse("2015-05-12T14:36:00.451"))
示例2: _get_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def _get_user(self):
try:
user = User.objects(account = self.account.data).first()
except MultipleObjectsReturned:#若搜尋到兩個以上的使用者,則抓取第一個
user = user[0]
return user
示例3: block_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def block_user(user):
username = request.forms.get('username')
access = eval(request.forms.get('access'))
user = User.objects(username=username).first()
user.access = not access
user.save()
redirect('/administration')
示例4: change_group
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def change_group(user):
username = request.forms.get('username')
user = User.objects(username=username).first()
group = request.forms.get('group')
user['group'] = UserGroup(name=group)
user.save()
redirect("/user/" + username)
示例5: regist
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def regist(userid='', deviceid='', email='', passwd=''):
user = []
if userid.__len__() == 0:
user = new_user(deviceid, userid)
user.email = email
user.passwd = passwd
user.nick_name = str_util.get_random_string(8)
user.haslogin = 1
user.follow_count = 0
user.fans_count = 0
user.share_count = 0
user.save()
elif check_hasemail(email):
return {}, 0, '该email已经存在'
else:
user = User.objects(id=userid)[0]
user.email = email
user.passwd = passwd
user.nick_name = str_util.get_random_string(8)
user.haslogin = 1
user.follow_count = 0
user.fans_count = 0
user.share_count = 0
user.save()
return user.to_mongo(), 1, ''
示例6: userLogin
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def userLogin(username, password):
user_object = User.objects(uname = username)
if len(user_object) == 0:
return 0
user = user_object[0]
if user.password == password:
return 1
return 2
示例7: change_avater
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def change_avater(userid='', image=''):
user = User.objects(id=userid)
if user.__len__() == 0:
return {}, 0, '用户不存在'
user = user[0]
user.avater = image
user.save()
return user.to_mongo(), 1, ''
示例8: testInsertLabeledRes
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def testInsertLabeledRes():
print "test lalbel results inserting function"
user = User.objects(uname = "ys")[0]
cluster_list = [[[29129,134]],[[29096,134]],[[29130,134]],[[29109,134]],[[29121,134]],[[29100,134]],\
[[29108,134]],[[29099,134]],[[29116,134]],[[29112,134]],[[29092,134]],[[29143,134]],[[29119,134]],\
[[29111,134],[29101,134],[29118,134],[29125,134],[29136,134],[29137,134]],[[29097,134]]]
PhraseUtils.insertLabeledRes(user, cluster_list)
示例9: register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def register(email, pwd):
exists = User.objects(email=email)
if len(exists):
return {'success':False, 'error':'exists user'}
user = User(email=email)
user.password = User.encrypted_password(pwd)
user.save()
login_user(user)
return {'success': True}
示例10: new_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def new_user(deviceid, userid):
user = []
if userid.__len__() > 0:
user = User.objects(id=userid)
if user.__len__() > 0:
user = user[0]
user.logindate = datetime.now()
user.deviceid = deviceid
user.save()
elif User.objects(deviceid=deviceid).__len__() > 0:
user = User.objects(deviceid=deviceid)[0]
user.logindate = datetime.now()
user.save()
else:
user = User(deviceid=deviceid, device_ids=[deviceid, ], createdate=datetime.now(), haslogin=0)
user.save()
return user
示例11: login
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.objects(email=form.email.data).first()
if user is not None and user.verify_password(form.password.data):
login_user(user, form.remember_me.data)
return redirect(request.args.get("next") or url_for("index"))
flash("Invalid username or password")
return render_template("login.html", form=form)
示例12: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def post(self):
u=User.objects(username=self.get_argument('username')).first()
if not u:
return self.write({'err':'用户不存在'})
if u.password!=self.get_argument('password'):
return self.write({'err':'密码错误'})
sid=sessions.createSession(u)
self.set_cookie('sid',sid)
return self.write({'role':u.__class__.__name__})
示例13: change_nickname
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def change_nickname(userid='', name=''):
user = User.objects(id=userid)
if user.__len__() == 0:
return {}, 0, '用户不存在'
user = user[0]
user.nick_name = name
user.save()
return {
'nickname': name
}, 1, ''
示例14: change_signature
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def change_signature(userid='', signature=''):
user = User.objects(id=userid)
if user.__len__() == 0:
return {}, 0, '用户不存在'
user = user[0]
user.signature = signature
user.save()
return {
'signature': signature
}, 1, ''
示例15: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import objects [as 别名]
def post(self):
errors=dict()
action=request.args.get('action')
def dict2str(get_dict):
this_list = get_dict.values()
return this_list[0]
if action=='add':
user_dict = get_dict(request.form, 'account', 'pwd', 'name', 'email' )
try:
User(**user_dict).save()
except ValidationError as e:
return redirect(url_for('admin.list',**e.errors))
except:
errors=dict({"unique":u"帳號重複請重新輸入"})
return redirect(url_for('admin.list',**errors))
if action=='modify':
user_dict=get_dict(request.form, 'set__account', 'set__name' ,'set__email')
to_md5_dict = get_dict(request.form, 'set__pwd')
to_md5_list=to_md5_dict.values()
to_md5_str=str(to_md5_list[0])
set_pwd_md5 = hashlib.md5()# use hashlib.md5
set_pwd_md5.update(to_md5_str) # to md5
set_pwd = set_pwd_md5.hexdigest()#print 編碼後的結果至終端
user_dict['set__pwd'] = set_pwd
try:
User.objects(id=request.form['objid']).update(**user_dict)
except ValidationError as e:
return redirect(url_for('admin.list',**e.errors))
if action=='delete':
try:
User(id=request.form["objid"]).delete()
except ValidationError as e:
return redirect(url_for('admin.list',**e.errors))
return redirect(url_for('admin.list'))