本文整理汇总了Python中models.users.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_all_user_blogs
def get_all_user_blogs(user_id=None):
if user_id is not None:
user = User.get_by_id(user_id)
else:
user = User.get_by_email(session['email'])
blogs = user.get_blogs()
return render_template('/user_page/user_blogs.html', blogs=blogs, email=user._email)
示例2: fake_users
def fake_users(session, request):
u = User()
u.username = 'test_user'
u.password = 'test_password'
session.add(u)
session.commit()
yield u
示例3: setup
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: create_user
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
示例5: done
def done(self):
#make sure the user doesn't already exist
u = User.by_name(self.username)
if u:
msg = 'That user already exists.'
self.render('signup-form.html', error_username = msg)
else:
u = User.register(self.username, self.password, self.email)
u.put()
self.login(u)
self.redirect('/')
示例6: user_login
def user_login():
if request.method == 'GET':
#return render_template('/login/login.html')
return login()
else:
email = request.form['email']
passwd = request.form['password']
if User.login_valid(email, passwd):
User.login(email)
return render_template('/user_page/user_profile_page.html', email=session['email'])
else:
session['email'] = None
return login()
示例7: test_users
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: register_user
def register_user():
if request.method == 'GET':
return render_template('/register/register.html')
else:
email = request.form['email']
passwd = request.form['password']
if User.get_by_email(email):
return 'user already exists'
else:
User.register(email, passwd)
return render_template('/user_page/user_profile_page.html', email=session['email'])
示例9: login
def login():
user_name = request.form['username'];
password = request.form['password'];
for user in User.objects(user_name=user_name):
if(user.password == password):
return json.dumps({"result_code":1, "result_message":"Login succeded"})
return json.dumps({"result_code":0, "result_message":"Login failed"})
示例10: post
def post(self):
"""Checks if user already exists, otherwise creates a new User in db"""
args = post_parser.parse_args()
user = User(args.email, args.password)
# Check if already registered
user_already_exists = User.query.filter(User.email == args.email).first()
if user_already_exists:
return {'success': False, 'message': 'That user already exists', 'data': None}
# Try saving the user to db
try:
user.save()
return {'success': True, 'message': 'User successfully added', 'data': None}
except ValueError as e:
return {'success': False, 'message': str(e), 'data': None}
示例11: get_friends_list
def get_friends_list(self, user):
twitterApi = Twitter.getInstance()
friends_list = []
l = []
# Very bad hack. Need to move all these to model.validate
try:
# Twitter API doesn't allow to get all friends infor at once.
# Instead you can only get all friends Ids and the use UserLookup
# to get full user infor but only in batches of 100 user at once
follow_list = twitterApi.api.GetFriendIDs(user.twitter)["ids"]
while len(follow_list) > 100:
l = l + twitterApi.api.UsersLookup(follow_list[0:100])
follow_list = follow_list[100:len(follow_list)]
l = l + twitterApi.api.UsersLookup(follow_list[0:len(follow_list)])
for friend in l:
friend_in_db = User.all().filter("twitter =", friend.screen_name)
if friend_in_db.count() == 1:
friends_list.append(friend.screen_name)
except TwitterError:
friends_list = ['not_authorized']
return friends_list
示例12: test_clustering
def test_clustering():
me = User.create(name="Jon")
for x in range(10):
Photo.create(user_id=me.user_id, name=str(x))
for x in Photo.objects(user_id=me.user_id):
print x.name
示例13: test_polymorphism
def test_polymorphism():
me = User.create(name="pete")
Photo.create(user_id=me.user_id, name="sunset")
Video.create(user_id=me.user_id, name="kickball")
for content in Video.objects(user_id=me.user_id):
print content
示例14: prepareEmailMessagesGenerator
def prepareEmailMessagesGenerator():
# This must be run after buildDailyList
# Since only there a daily message limit is applied
# though, this limit can be different for emails
path_current = os.path.dirname(__file__)
root_path = os.path.split(path_current)[0]
view_path = root_path + "/views/daily_email.html"
today = datetime.date.today()
emails_dict = {}
for user in User.all().filter("account_status =", "enabled").\
filter("use_daily_email =", "yes"):
parameters = {}
parameters["dict_row"] = []
for lli in LearnList.all().\
filter("next_serve_date =", today).\
filter("twitter_user =", user.twitter):
l = []
l.append(lli.dict_entry.word + " " + lli.dict_entry.pronounce)
l.append(lli.dict_entry.meaning)
parameters["dict_row"].append(l)
emails_dict["email"] = user.email
emails_dict["message"] = template.\
render(view_path, parameters)
yield emails_dict
示例15: users
def users(self):
"""
List users, for the asmins
"""
tmpl = config.lookup.get_template("users.html")
ulist = list(User.select())
return tmpl.render(env=config.htmlEnv, users=ulist, session=cherrypy.session)