本文整理汇总了Python中models.user.User.get方法的典型用法代码示例。如果您正苦于以下问题:Python User.get方法的具体用法?Python User.get怎么用?Python User.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_fixtures
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def load_fixtures():
users = [
{"username": "user1", "password": "user1"},
{"username": "user2", "password": "user2"},
{"username": "user3", "password": "user3"}
]
with db.atomic():
User.insert_many(users).execute()
u1 = User.get( User.username == "user1")
u2 = User.get( User.username == "user2")
todos = [(u1, 'Vivamus tempus'),
(u1, 'lorem ac odio'),
(u1, 'Ut congue odio'),
(u1, 'Sodales finibus'),
(u1, 'Accumsan nunc vitae'),
(u2, 'Lorem ipsum'),
(u2, 'In lacinia est'),
(u2, 'Odio varius gravida'),
(u2, 'Extra entry to trigger pagination 1'),
(u2, 'Extra entry to trigger pagination 2'),
(u2, 'Extra entry to trigger pagination 3'),
(u2, 'Extra entry to trigger pagination 4'),
(u2, 'Extra entry to trigger pagination 5')]
with db.atomic():
for u, d in todos:
Todo.insert(user=u, description=d, completed=False).execute()
示例2: log_in_route
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def log_in_route(request):
"""
Log in user.
"""
name = request['params'].get('name') or ''
name = name.lower()
user = User.get(name=name)
if not user:
user = User.get(email=request['params'].get('name'))
if not user:
return 404, {
'errors': [{
'name': 'name',
'message': c('no_user'),
}],
'ref': 'FYIPOI8g2nzrIEcJYSDAfmti'
}
if not user.is_password_valid(request['params'].get('password')):
return 400, {
'errors': [{
'name': 'password',
'message': c('no_match'),
}],
'ref': 'UwCRydZ7Agi7LYKv9c1y07ft'
}
return _log_in(user)
示例3: index
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def index():
if not g.user.is_super_leader():
abort(403)
salers = User.sales()
if request.method == 'POST':
f_saler = int(request.values.get('f_saler', 0))
t_saler = int(request.values.get('t_saler', 0))
if not f_saler or not t_saler:
flash(u'请选择正确的员工', 'danger')
return tpl('/account/turnover/index.html', salers=salers)
f_user = User.get(f_saler)
t_user = User.get(t_saler)
client_orders = ClientOrder.all()
douban_orders = DoubanOrder.all()
for k in client_orders:
if f_user in k.salers and t_user not in k.replace_sales:
k.replace_sales = k.replace_sales + [t_user]
k.save()
if k.creator == f_user and t_user not in k.replace_sales:
k.replace_sales = k.replace_sales + [t_user]
k.save()
for k in douban_orders:
if f_user in k.salers and t_user not in k.replace_sales:
k.replace_sales = k.replace_sales + [t_user]
k.save()
if k.creator == f_user and t_user not in k.replace_sales:
k.replace_sales = k.replace_sales + [t_user]
k.save()
flash(u'成功', 'success')
return tpl('/account/turnover/index.html', salers=salers)
示例4: test_add_and_get_users
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def test_add_and_get_users(self):
bid0 = Board.add("board0", "A")
board0 = Board.get(bid0)
uid0 = User.add("test1", "password", "[email protected]")
user0 = User.get(uid0)
uid1 = User.add("test2", "password", "[email protected]")
user1 = User.get(uid0)
board0.add_user(user0)
assert str(uid0) in board0.get_user_ids()
assert str(uid1) not in board0.get_user_ids()
示例5: reply
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def reply(self):
if self.is_active() and self.message.text == 'Yes':
self.activate(False)
try:
User.get(User.chat_id == self.message.chat_id).delete_instance()
return {'message': self.dialogs['reply'], 'keyboard': None}
except:
return {'message': "You're already deleted!", 'keyboard': None}
if self.is_active() and self.message.text == 'No':
self.activate(False)
return {'message': "Ok, I won't delete you.", 'keyboard': None}
else:
self.activate()
return {'message': "Are you sure?", 'keyboard': [['Yes', 'No']]}
示例6: test_add_and_get_cards
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def test_add_and_get_cards(self):
uid0 = User.add("test_user1", "password", "[email protected]")
user0 = User.get(uid0)
uid1 = User.add("test_user2", "password", "[email protected]")
user1 = User.get(uid1)
bid0 = Board.add("board1", "A")
lid0 = List.add("List0", bid0)
caid0 = Card.add("card1", lid0, uid0)
caid1 = Card.add("card2", lid0, uid1)
card0 = Card.get(caid0)
print caid0, user0.get_card_ids()
assert str(caid0) in user0.get_card_ids()
assert str(caid1) not in user0.get_card_ids()
示例7: get_current_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def get_current_user(self):
sk = self.get_argument('sk', '')
try:
email = serializer.loads(sk)
except BadSignature:
raise APIError(401)
return User.get(email)
示例8: test_set_learning_context
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def test_set_learning_context(db_conn, users_table):
"""
Expect to set the learning context.
"""
users_table.insert({"id": "abcd1234", "name": "Dalton", "email": "[email protected]", "password": "abcd1234"}).run(
db_conn
)
user = User.get(id="abcd1234")
user.set_learning_context(card={"entity_id": "A"})
assert user.get_learning_context() == {"card": {"entity_id": "A"}}
user.set_learning_context(
unit={"entity_id": "B", "name": "Banana", "body": "Banana"}, set={"entity_id": "C", "name": "Coconut"}
)
assert user.get_learning_context() == {
"card": {"entity_id": "A"},
"unit": {"entity_id": "B", "name": "Banana", "body": "Banana"},
"set": {"entity_id": "C", "name": "Coconut"},
}
user.set_learning_context(set=None)
assert user.get_learning_context() == {
"card": {"entity_id": "A"},
"unit": {"entity_id": "B", "name": "Banana", "body": "Banana"},
}
user.set_learning_context(card=None, unit=None)
assert user.get_learning_context() == {}
示例9: __init__
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def __init__(self, user, comment, idea):
self._name = "idea:comment"
author_key = Idea.author.get_value_for_datastore(idea)
author = User.get(author_key)
if(author.email_idea_comment):
self._data = {
"user": {
"id": user.key().id(),
},
"comment":{
"id": comment.key().id(),
"text": comment.text,
},
"idea": {
"id": idea.key().id(),
"title": idea.title,
"author": {
"username": author.username,
"name": author.name,
"email": author.email,
},
"positive": idea.positive,
"negative": idea.negative,
"comments": idea.comments,
}
}
self.send()
示例10: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def post(self, *args, **kwargs):
user_kw = {
"uid": self.get_argument("uid", None),
"pwd": self.get_argument("pwd", None),
"sex": self.get_argument("sex", None),
"major": self.get_argument("major", None),
"grade": self.get_argument("grade", None),
}
print user_kw
try:
user = User.get(user_kw["uid"])
if user:
if user_kw["pwd"]:
user.pwd = user_kw["pwd"]
if user_kw["sex"]:
user.sex = user_kw["sex"]
if user_kw["major"]:
user.major = user_kw["major"]
if user_kw["grade"]:
user.grade = user_kw["grade"]
user.save()
self.write(self.make_result(1, "user update OK", None))
else:
self.write(self.make_result(0, "user not found or wrong password", None))
except ValueError, e:
self.write(self.make_result(0, str(e), None))
示例11: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def post(self):
user_key =self.get_secure_cookie("user_key")
r = None
user_data = {}
info_data = {}
userInfo = UserInfo()
user = User()
user.key = user_key
user.data = user.get(user_key)
user.data['nickname'] = self.get_argument("user_nickname",None)
userInfo.key = user_key
userInfo_data = userInfo.get(user_key)
if userInfo_data:
userInfo.data = userInfo_data
userInfo.data['city'] = self.get_argument("user_city","")
userInfo.data['url'] = self.get_argument("user_url","")
userInfo.data['desc'] = self.get_argument("user_description","")
userInfo.post()
user.post()
self.redirect('/settings/')
示例12: save
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def save(self):
"""
Overwrite save method to add to Elasticsearch.
"""
# TODO-2 should we validate the save worked before going to ES?
from models.topic import Topic
from models.user import User
data = json_prep(self.deliver())
topic = Topic.get(id=self['topic_id'])
if topic:
data['topic'] = json_prep(topic.deliver())
user = User.get(id=self['user_id'])
if user:
data['user'] = json_prep(user.deliver())
es.index(
index='entity',
doc_type='post',
body=data,
id=self['id'],
)
return super().save()
示例13: from_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def from_user(self, receivers=None, text=None, *_):
if receivers is None:
return ERR_NORECIPIENT(self.command, self.actor)
if text is None:
return ERR_NOTEXTTOSEND(self.actor)
resp = []
# TODO: check for ERR_TOOMANYTARGETS
for receiver in receivers.split(','):
if Channel.exists(receiver):
users = [user
for user in Channel.get(receiver).users
if user is not self.user]
resp.append(M(
ActorCollection(users),
self.command, str(receiver), text,
prefix=str(self.user)))
elif User.exists(receiver):
resp.append(M(
Actor.by_user(User.get(receiver)),
self.command, str(receiver), text,
prefix=str(self.user)))
# TODO: Implement wildcards
# TODO: check for ERR_WILDTOPLEVEL, RPL_AWAY, ERR_NOTOPLEVEL
else:
resp.append(ERR_NOSUCHNICK(receiver, self.actor))
return resp
示例14: test_user_subscriptions
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def test_user_subscriptions():
seed_user = User.get()
subscription = Subscription.get()
# Query checking if the subscription is in the user.
count_query = (UserSubscription.select()
.where(UserSubscription.user == seed_user,
UserSubscription.subscription == subscription))
# Unsubscribe first (regardless of subscription).
seed_user.unsubscribe(subscription)
assert count_query.count() == 0
assert subscription.num_subscribers() == 0
# Resubscribe.
seed_user.subscribe(subscription)
assert count_query.count() == 1
assert subscription.num_subscribers() == 1
# Resubscribe again.
seed_user.subscribe(subscription)
assert count_query.count() == 1
assert subscription.num_subscribers() == 1
# Unsubscribe again.
seed_user.unsubscribe(subscription)
assert count_query.count() == 0
assert subscription.num_subscribers() == 0
示例15: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get [as 别名]
def post(self, group_id):
user_id = self.get_argument('user_id', '')
user = User.get(user_id)
group = Group.get(group_id)
user.groups.append(group)
user.save()
self.redirect(self.reverse_url('member_addition', group_id))