当前位置: 首页>>代码示例>>Python>>正文


Python User.find_by_id方法代码示例

本文整理汇总了Python中models.User.find_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.find_by_id方法的具体用法?Python User.find_by_id怎么用?Python User.find_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.User的用法示例。


在下文中一共展示了User.find_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
def create_user():
    data = json.loads(request.data)
    if not (data.get('email') or data.get('facebook_id')):
        return json_error("missing attribute: email or facebook_id")

    # get the user id from the signed request and compare it to the 
    # facebook profile information to see if we have access to this user
    sr = data.get('signed_request')
    fb_d, err = facebook.get_data_from_signed_request(sr)
    if err:
        return json_error(err)

    if fb_d.get('user_id') != data.get('facebook_id'):
        return json_error("invalid facebook cookie")

    # find the user in the database, return if found
    facebook_id = data.get('facebook_id')
    user = User.find_by_facebook_id(db, facebook_id)
    if user:
        return json.dumps(user)

    # otherwise create and return the new user
    user_id = User.create(db, data)
    if not user_id:
        return json_error("couldn't create user")

    user = User.find_by_id(db, user_id)
    return json.dumps(user)
开发者ID:shreyansb,项目名称:massivelyoffline,代码行数:30,代码来源:app.py

示例2: follow

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
def follow(target_id):
    self_id = session.get('user_id')
    target = User.find_by_id(target_id)
    tasks = User.retrieve_published_tasks(target_id)
    if self_id and target:
        User.follow_user(self_id, target_id)
        return redirect(url_for('show_user', user_id=target_id))
    return redirect(url_for('index'))
开发者ID:BlackieXS,项目名称:helping_system,代码行数:10,代码来源:views.py

示例3: index

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
def index():
    user_id = session.get('user_id')
    if user_id:
        user = User.find_by_id(user_id)
        posts = User.retrieve_feed(user_id)
        return render_template('index.html',  posts = posts, nickname=user['nickname'], user_portrait_url = user['portrait'])
    else:
        posts = get_recent_posts()
        return render_template('index.html', posts = posts)
开发者ID:zhengqm,项目名称:neo4j-weibo,代码行数:11,代码来源:controllers.py

示例4: index

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
def index():
    user_id = session.get('user_id')
    if user_id:
        user = User.find_by_id(user_id)
        tasks = User.retrieve_feed(user_id)
        return render_template('index.html',  tasks = tasks, user_name=user[1], user_portrait_url = user[6])
    else:
        tasks = get_recent_tasks()
        return render_template('index.html', tasks = tasks)
开发者ID:BlackieXS,项目名称:helping_system,代码行数:11,代码来源:views.py

示例5: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
 def post(self, request, userId, *args, **kwargs):
     args = sanitize_dict(parse_json(request.body), {"ts": int, "auth": basestring})
     ts, auth = args["ts"], args["auth"]
     if abs(ts - time() * 1000) > 600000:  # out of 10 mins
         return errors.TIMEOUT
     sessionId = User.find_by_id(userId).session_id
     rawAuth = "{}:{}:{}".format(sessionId, userId, ts)
     expectedAuth = sha256(rawAuth).hexdigest()
     if auth != expectedAuth:
         return errors.PERMISSION_DENIED
     return OKResponse()
开发者ID:jacky8hyf,项目名称:CS169CombatingSnake,代码行数:13,代码来源:views.py

示例6: before_request

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
def before_request():
	g.is_active = is_active
	g.db = database_session()
	if session.has_key('u') and session.has_key('p'):
		u = User.find_by_id(session['u'])
		if u and u.password == session['p']:
			g.user = u
		else:
			g.user = None
	else:
		g.user = None
开发者ID:SpicyHorse,项目名称:delivery,代码行数:13,代码来源:__init__.py

示例7: show_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
def show_user(user_id):
    self_id = session.get('user_id')
    user = User.find_by_id(user_id)
    friends_2_hop = User.retrieve_2_hop_friends(user_id)
    user_info = User.fetch_self_information(user_id).one
    if user:
        if self_id:
            posts = User.retrieve_posts(user_id, self_id)
            liked_posts = User.retrieve_liked_posts(user_id, self_id)
            if User.is_following(self_id, user_id):
                return render_template('user_page.html', nickname=user['nickname'], posts=posts, user_id=user_id, is_following = True, liked_posts=liked_posts, user_portrait_url = user['portrait'], user_info=user_info)
            else:
                return render_template('user_page.html', nickname=user['nickname'], posts=posts, user_id=user_id, is_following = False, friends_2_hop=friends_2_hop, user_portrait_url = user['portrait'], user_info=user_info)
        else:
            posts = User.retrieve_posts(user_id)
            return render_template('user_page.html', nickname=user['nickname'], posts=posts, user_id=user_id, user_portrait_url = user['portrait'], user_info=user_info)
    else:
        return redirect(url_for('index'))
开发者ID:zhengqm,项目名称:neo4j-weibo,代码行数:20,代码来源:controllers.py

示例8: put

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
    def put(self, request, roomId, memberId, *args, **kwargs):

        returnRoom = getBooleanParam(request, "return-room")

        if validate_master_key(request):
            user = User.find_by_id(memberId)
        else:
            user = fetch_user(request)
            if memberId != user.strId:
                return errors.PERMISSION_DENIED
        room = Room.find_by_id(str(roomId)).raise_if_cannot_join(user)
        user.enter_room(room).save()

        if not returnRoom:
            return OKResponse()
        else:
            return OKResponse(
                Room.find_by_id(str(roomId)).to_dict(
                    includeCreatorProfile=True, includeMembers=True, includeMemberProfile=True
                )
            )
开发者ID:jacky8hyf,项目名称:CS169CombatingSnake,代码行数:23,代码来源:views.py

示例9: add_comment

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
def add_comment():
    user_id = session.get('user_id')
    if user_id:
        content = request.form['content']
        post_id = request.form['post_id']
        target_user_id = request.form['target_user_id']
        if not content or len(content) == 0:
            flash('评论内容不能为空','danger')
        else:
            if target_user_id:
                target_user = User.find_by_id(target_user_id)
                if content.find(target_user['nickname']) and content.index(target_user['nickname']) == 2:
                    content = content[content.index(target_user['nickname']) + len(target_user['nickname']) + 1:]
                    User.add_comment_on_comment(user_id, target_user_id, post_id, content, 'tags')
                    flash('成功评论', 'success')
                    return redirect(url_for('show_post', post_id=post_id))
            post_user_id = Post.find_poster(post_id)
            User.add_comment_on_post(user_id, user_id, post_id, content, 'tags')
            flash('成功评论', 'success')
            return redirect(url_for('show_post', post_id=post_id))
    return redirect(url_for('index'))
开发者ID:zhengqm,项目名称:neo4j-weibo,代码行数:23,代码来源:controllers.py

示例10: show_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
def show_user(user_id):
    self_id = session.get('user_id')
    user = User.find_by_id(user_id)
    friends_2_hop = User.retrieve_2_hop_friends(user_id)
    user_follower_count = User.fetch_follower_count(user_id)
    user_following_count = User.fetch_following_count(user_id)
    score_as_helper = User.fetch_score_as_helper(user_id)
    score_as_helpee = User.fetch_score_as_helpee(user_id)
    if user:
        if self_id:
            tasks = User.retrieve_published_tasks(user_id, self_id)
            adopted_tasks = User.retrieve_adopted_tasks(user_id, self_id)
            if User.is_following(self_id, user_id):
                return render_template('user_page.html', user_name=user[1], tasks=tasks, user_id=user_id, is_following = True, adopted_tasks=adopted_tasks, user_portrait_url = user[6], user_following_count=user_following_count, user_follower_count = user_follower_count, score_as_helper = score_as_helper[0], score_as_helpee = score_as_helpee[0])
            else:
                return render_template('user_page.html', user_name=user[1], tasks=tasks, user_id=user_id, is_following = False, friends_2_hop=friends_2_hop, user_portrait_url = user[6], user_following_count=user_following_count, user_follower_count = user_follower_count, score_as_helper = score_as_helper[0], score_as_helpee = score_as_helpee[0])
        else:
            tasks = User.retrieve_published_tasks(user_id)
            return render_template('user_page.html', user_name=user[1], tasks=tasks, user_id=user_id, user_portrait_url = user[6], user_following_count=user_following_count, user_follower_count = user_follower_count, score_as_helper = score_as_helper[0], score_as_helpee = score_as_helpee[0])
    else:
        return redirect(url_for('index'))
开发者ID:BlackieXS,项目名称:helping_system,代码行数:23,代码来源:views.py

示例11: delete

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
    def delete(self, request, roomId, memberId, *args, **kwargs):

        returnRoom = getBooleanParam(request, "return-room")

        if validate_master_key(request):
            user = User.find_by_id(memberId)
        else:
            user = fetch_user(request)
            if memberId != user.strId:
                return errors.PERMISSION_DENIED
        room = Room.find_by_id(str(roomId))
        user.exit_room(room).save()

        if room.roomId is None or not returnRoom:
            # room.roomId is None only if exit_room deletes the room
            return OKResponse()
        else:
            return OKResponse(
                Room.find_by_id(str(roomId)).to_dict(
                    includeCreatorProfile=True, includeMembers=True, includeMemberProfile=True
                )
            )
开发者ID:jacky8hyf,项目名称:CS169CombatingSnake,代码行数:24,代码来源:views.py

示例12: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
 def get(self, request, userId, *args, **kwargs):
     ''' get user profile'''
     includeProfile = request.GET.get('profile', False)
     user = User.find_by_id(str(userId))
     return OKResponse(user.to_dict(includeProfile = includeProfile))
开发者ID:ShihengJiang666,项目名称:CS169CombatingSnake,代码行数:7,代码来源:views.py

示例13: initialize

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
 def initialize(self, *a, **kw):
     webapp2.RequestHandler.initialize(self, *a, **kw)
     uid = self.read_cookie('user_id')
     self.user = uid and User.find_by_id(int(uid))
开发者ID:michael-mao,项目名称:thewikihub,代码行数:6,代码来源:handlers.py

示例14: fetch_follower

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
def fetch_follower(user_id):
    self_id = session.get('user_id')
    followers = User.find_follower(user_id, self_id)
    user = User.find_by_id(user_id)
    return render_template('follower.html', followers=followers, user=user)
开发者ID:BlackieXS,项目名称:helping_system,代码行数:7,代码来源:views.py

示例15: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by_id [as 别名]
 def get(self, request, userId, *args, **kwargs):
     """ get user profile"""
     includeProfile = getBooleanParam(request, "profile")
     includeScores = getBooleanParam(request, "scores")
     user = User.find_by_id(str(userId))
     return OKResponse(user.to_dict(includeProfile=includeProfile, includeScores=includeScores))
开发者ID:jacky8hyf,项目名称:CS169CombatingSnake,代码行数:8,代码来源:views.py


注:本文中的models.User.find_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。