本文整理汇总了Python中models.User.get_user_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_user_by_id方法的具体用法?Python User.get_user_by_id怎么用?Python User.get_user_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.get_user_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: facebook_login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def facebook_login():
"""Handles the login from the facebook login button)"""
user_id = str(request.form.get('user_id'))
current_access_token = request.form.get('accessToken')
print current_access_token
print user_id
print type(user_id)
graph = facebook.GraphAPI(access_token=current_access_token)
friends = graph.get_connections(id='me', connection_name='friends')
profile_pic = graph.get_connections(id='me', connection_name='picture')[
'url'] # Todo: this line seems to be very slow,try
user_details = graph.get_object(id=user_id, fields='name, email, gender, age_range, birthday, location')
user_id = int(user_id)
name = user_details.get('name')
email = user_details.get('email')
gender = user_details.get('gender')
age_range = user_details.get('age_range').get('min')
if user_details.get('age_range', None):
age_range = user_details.get('age_range').get('min')
location = user_details.get('location', None)
if user_details.get('location', None):
location = user_details.get('location').get('name')
current_access_token = request.form.get('accessToken')
friend_ids = parsing_friends_data(friends)
print friend_ids
user = User.get_user_by_id(user_id)
if user:
"""the user has previously logged in to Opinionated"""
print "Hi, you're already a user."
session["loggedin"] = user.user_id
session["current_access_token"] = current_access_token
flash("Login successful!")
if friend_ids:
for friend_id in friend_ids:
friend = User.get_user_by_id(friend_id)
print "friend is ", friend
# check to see if the friend is also an user in the app
if friend:
if not user.is_following(friend):
user.follow(friend)
flash('Thanks for logging into Opinionated')
return redirect('/home') # the return is not needed because this is a json post, do redirect in json
else:
# todo: need to generate random password for facebook user, password cannot be None
new_user = User.create(user_id=user_id, email=email, user_name=name, age_range=int(age_range),
gender=gender, location=location, password="", friend_ids=friend_ids,
profile_pic=profile_pic)
session["loggedin"] = new_user.user_id
session["current_access_token"] = current_access_token
flash("Thanks for logging into Opinionated")
return redirect("/home")
示例2: unfollow
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def unfollow(user_id):
user = User.get_user_by_id(user_id)
viewer_id = session.get('loggedin')
viewer = User.get_user_by_id(viewer_id)
if user is None:
flash('Invalid user.')
if viewer.is_following(user):
viewer.unfollow(user)
flash('You are now not following %s' % user.user_name)
return redirect(url_for('user_profile', user_id=user_id))
示例3: user_profile
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def user_profile(user_id):
"""this is the page that will show users' all posts, and all things they have voted on"""
posts = Post.get_posts_by_author_id(user_id)
session["post_ids"] = [post.post_id for post in posts]
user = User.get_user_by_id(user_id)
viewer_id = session.get('loggedin')
viewer = User.get_user_by_id(viewer_id)
votes = Vote.get_votes_by_user_id(user_id)
return render_template("user_profile.html", posts=posts, votes=votes, user=user, viewer=viewer)
示例4: follow
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def follow(user_id):
user = User.get_user_by_id(user_id)
viewer_id = session.get('loggedin')
viewer = User.get_user_by_id(viewer_id)
if user is None:
flash('Invalid user.')
return redirect(url_for('show_all_posts'))
if viewer.is_following(user):
flash('You are already following %s' % user.user_name)
return redirect(url_for('user_profile', user_id=user_id))
viewer.follow(user)
flash('You are now following %s' % user.user_name)
return redirect(url_for('user_profile', user_id=user_id))
示例5: show_all_posts
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def show_all_posts():
"""the homepage of the site where all the posts will be shown in a table"""
show_followed = False
# get the variable "show-all" from the template to determine whether to show all posts or followed ones
show_what = request.args.get('show-all')
page = request.args.get('page', 1, type=int)
print show_what, "this is show_what"
if show_what == "false":
show_followed = True
if show_followed:
viewer_id = session.get('loggedin', None)
viewer = User.get_user_by_id(viewer_id)
posts_all = viewer.followed_posts()
pagination = viewer.followed_posts_pagination(page)
else:
posts_all = Post.get_all_posts()
pagination = Post.get_all_posts_pagination(page)
if posts_all:
session["post_ids"] = [post.post_id for post in posts_all]
tags = Tag.sort_all_tags_by_popularity()
posts = pagination.items # the records in the current page
return render_template('post_list.html', posts=posts, tags=tags, pagination=pagination)
示例6: followeds
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def followeds(user_id):
user = User.get_user_by_id(user_id)
if user is None:
flash('Invalid user.')
return redirect(url_for('show_all_posts'))
followeds = user.get_all_followeds()
return render_template('followeds.html', followeds=followeds, user=user)
示例7: test_get_user_by_id
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def test_get_user_by_id(self):
email = 'test_email'
password = 'test_password'
user = User(email=email, password=password)
add_to_database(user)
assert user in db.session
assert len(User.query.filter_by(id=1).all()) == 1
user_from_db = User.get_user_by_id(1)
assert user_from_db.email == email
示例8: edit_profile_process
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def edit_profile_process():
user_id = session.get('loggedin')
user = User.get_user_by_id(user_id)
user_name = request.form.get('name')
location = request.form.get('location')
gender = request.form.get('gender')
age_range = int(request.form.get('age'))
print age_range
about_me = request.form.get('about_me')
profile_pic = request.form.get('profile_pic')
user.update_user_info(user_name=user_name, location=location, gender=gender, age_range=age_range,
about_me=about_me, profile_pic=profile_pic)
flash("Your information has been updated")
return redirect(url_for('user_profile', user_id=user_id))
示例9: process_comments
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def process_comments(post_id):
"""process the comments the users entered """
content = request.form.get('comment')
user_id = session.get('loggedin', None)
if user_id:
user = User.get_user_by_id(user_id)
user_name = user.user_name
user_pic = user.profile_pic
new_comment = Comment.create(content=content, user_id=user_id, post_id=post_id)
comment_id = new_comment.comment_id
comment_timestamp = new_comment.timestamp
has_delete_button = user_id == new_comment.user_id
return jsonify(user_id=user_id, user_name=user_name, user_pic=user_pic, content=content,
has_delete_button=has_delete_button, comment_id=comment_id, comment_timestamp=comment_timestamp)
else:
return jsonify(user_id="undefined")
示例10: wrapper
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def wrapper(self, *args, **kwargs):
if 'oauth_access_token' not in self.session:
return HttpResponseRedirect('/login')
else:
access_token = self.session['oauth_access_token']
expires_in = self.session['oauth_request_expires']
uid = self.session['oauth_uid']
logging.info('access_token: %s, expires_in: %s' % (access_token,
expires_in))
logging.debug('access_token: %s, expires_in: %s' % (access_token,
expires_in))
login_backurl = self.build_absolute_uri('/login_check')
self.auth_client = sinat_helper.get_oauth(login_backurl,
access_token, expires_in)
self.uid = uid
self.user = User.get_user_by_id(uid)
return method(self, *args, **kwargs)
示例11: edit_profile
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def edit_profile():
user_id = session.get("loggedin")
user = User.get_user_by_id(user_id)
return render_template('edit_profile.html', user=user)
示例12: load_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def load_user(userid):
return User.get_user_by_id(userid)
示例13: test_user_doesnt_exist_returns_none
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def test_user_doesnt_exist_returns_none(self):
user = User.get_user_by_email("bla")
assert user is None
user2 = User.get_user_by_id(100000)
assert user2 is None
示例14: initialize
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def initialize(self, *a, **kw):
webapp2.RequestHandler.initialize(self, *a, **kw)
uid = self.read_secure_cookie('user_id')
self.user = uid and User.get_user_by_id(int(uid))
示例15: before_request
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_user_by_id [as 别名]
def before_request():
g.user = None
if 'user_id' in session:
g.user = User.get_user_by_id(session['user_id'])