本文整理汇总了Python中models.users.User.username方法的典型用法代码示例。如果您正苦于以下问题:Python User.username方法的具体用法?Python User.username怎么用?Python User.username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.users.User
的用法示例。
在下文中一共展示了User.username方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def get(self):
api = QQAPIClient(config.get('qq_apiid'),
config.get('qq_appkey'),
redirect_uri=config.get('qq_callback_url'))
code = self.request.query_arguments.get('code')[0]
print code
access_token = api.request_access_token(code)
api.set_access_token(access_token['access_token'],
access_token['expires_in'])
user_info = api.get.user__get_user_info()
openid = api.get_openid()
now = datetime.utcnow()
user = User.objects.filter(third_info__third_type='qq',
third_info__openid=openid).first()
if not user:
user = User(create_on=now, modify_on=now, last_login=now)
else:
user.modify_on = now
user.last_login = now
user.username = openid
user.nick_name = user_info.get('nickname', '')
user.email = '%[email protected]' % openid
gender = 'm' if user_info.get('gender') == u'男' else 'f'
user.gender = gender
user.avatar = user_info.get('figureurl_qq_2', '')
user.third_info = {'third_type': 'qq', 'info': dict(user_info), 'openid': openid}
user.save()
# set user cookie
self.set_secure_cookie(config.get('uname'), openid)
self.write(json.dumps(make_success_response(user_info)))
示例2: fake_users
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def fake_users(session, request):
u = User()
u.username = 'test_user'
u.password = 'test_password'
session.add(u)
session.commit()
yield u
示例3: setup
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def setup():
db.create_all(app=manager.app)
with manager.app.app_context():
u = User()
u.username = 'admin'
u.password = 'admin123'
db.session.add(u)
db.session.commit()
示例4: createUser
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def createUser(self, twitter_user, account_status, messages_per_day):
user = User()
user.twitter = twitter_user
user.username = twitter_user
user.account_status = account_status
user.messages_per_day = messages_per_day
user.put()
return user
示例5: setUp
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
# Preparing datastore by prepopulating some data
user = User()
user.username = "da_zbur"
user.twitter = "da_zbur"
user.total_points = 0
user.put()
示例6: create_user
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def create_user():
name = request.form.get('username', None)
password = request.form.get('password', None)
if all([name, password]):
u = User()
u.password = password
u.username = name
db.session.add(u)
db.session.commit()
return 'OK', 200
return 'Error', 400
示例7: test_users
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def test_users(session):
u = User()
u.username = 'test_user'
u.password = 'testpassword'
session.add(u)
session.commit()
t = session.query(User).filter(User.username == 'test_user').first()
assert t is not None
assert u == t
assert t.password == u.password
assert t.api_key is None
示例8: testAddNewLearnListItem
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def testAddNewLearnListItem(self):
# Preparing datastore by prepopulating some data
user = User()
user.username = "ny_blin"
user.twitter = "ny_blin"
user.total_points = 0
user.put()
json_file = open("files/direct_message2.json")
message_json = simplejson.load(json_file)
twitter_dm = DirectMessage.NewFromJsonDict(message_json)
processMessage(twitter_dm)
query = LearnList.all().filter('twitter_user =','ny_blin')
results = query.fetch(2)
self.assertEqual(1, len(results))
self.assertEqual('ny_blin', results[0].twitter_user)
self.assertEqual(2.5, results[0].interval_days)
self.assertEqual(1.5, results[0].efactor)
self.assertEqual(1, results[0].total_served)
now_plus_two = datetime.date.today() +\
datetime.timedelta(days=2)
self.assertEqual(now_plus_two, results[0].next_serve_date)
示例9: post
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def post(self):
model = model_from_request(self.request, RegisterModel)
# validate data; on error, redisplay form with error messages
if not model.validate():
self.view(model)
return
# save new user
user = User()
user.username = model.user_name
user.email = model.email
# todo: hash password
user.password = model.password
user.put()
# put him into session
set_current_user(user)
# redirect to the home page
self.redirect("/")
示例10: post
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import username [as 别名]
def post(self):
twitter = Twitter.getInstance()
model = model_from_request(self.request, RegisterModel)
# validate data; on error, redisplay form with error messages
if not model.validate():
self.view(model)
return
# save new user
user = User()
user.username = model.twitter_name
user.twitter = model.twitter_name
user.email = ""
pwd_hash = hashlib.md5()
pwd_hash.update(model.password)
user.password = pwd_hash.hexdigest()
user.timezone = ""
user.next_run_time = 0
user.message_type = "reply"
user.account_status = "enabled"
user.repeat_times = 6
user.followed_by = ""
user.i_follow = ""
user.messages_per_day = 10
user.default_source_lang = "en"
user.follow_lang_list = "en"
user.total_points = 0
user.put()
try:
twitter.api.CreateFriendship(model.twitter_name)
except:
pass
# put him into session
set_current_user(user)
# redirect to the home page
self.redirect("/profile")