當前位置: 首頁>>代碼示例>>Python>>正文


Python User.user_id方法代碼示例

本文整理匯總了Python中model.User.user_id方法的典型用法代碼示例。如果您正苦於以下問題:Python User.user_id方法的具體用法?Python User.user_id怎麽用?Python User.user_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在model.User的用法示例。


在下文中一共展示了User.user_id方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_users

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def load_users():
    """Load users from u.user into database."""

    print "Users"

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate users
    User.query.delete()

    # Read u.user file and insert data
    for row in open("seed_data/u.user"):
        row = row.rstrip()
        user_id, age, gender, occupation, zipcode = row.split("|")

        user = User(user_id=int(user_id),
                    age=age,
                    zipcode=zipcode)

        # We need to add to the session or it won't ever be stored
        db.session.add(user)

    # Once we're done, we should commit our work
    db.session.commit() 
開發者ID:kjlundsgaard,項目名稱:ratings,代碼行數:25,代碼來源:seed.py

示例2: load_ratings

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def load_ratings():
    """Load ratings from u.data into database."""
    print "Ratings"
    Rating.query.delete()

    for row in open('seed_data/u.data'):
        row = row.rstrip()
        row = row.split('\t')

        user_id, movie_id, score = row[:3]

        rating = Rating(movie_id=int(movie_id), 
                        user_id=int(user_id),
                        score=int(score))
    
        db.session.add(rating)

    db.session.commit() 
開發者ID:kjlundsgaard,項目名稱:ratings,代碼行數:20,代碼來源:seed.py

示例3: prompt_arrangment

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def prompt_arrangment():
    """Allow a user to input parameters about wall generation from gallery."""

    gallery_id = request.args.get('gallery_id')
    gallery = Gallery.query.get(gallery_id)

    # This is a get request because it does not have side effects, but check
    # they are the curator of this gallery or that it is site sample.
    if gallery.curator_id not in [session.get('user_id'), DEFAULT_USER_ID]:
        flash("That gallery doesnt exist or you don't have permission to view it.")
        return redirect('/galleries')

    arrange_options = utils.get_arrange_options_for_display()

    return render_template("arrange.html",
                           gallery=gallery,
                           arrange_options=arrange_options,
                           ) 
開發者ID:elsabirch,項目名稱:gallery-wall,代碼行數:20,代碼來源:server.py

示例4: signup_process

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def signup_process():
    """Process signup form"""

    email = request.form["email"]
    password = request.form["password"]
    first_name = request.form["firstname"]
    last_name = request.form["lastname"]
    foo = request.form
    print "*********"
    print "foo: "
    print "type: ", type(foo)
    print "keys: ", foo.keys()

    new_user = User(email=email, password=password, first_name=first_name, last_name=last_name)
    db.session.add(new_user)
    db.session.commit()

    session["user_id"] = new_user.user_id
    flash("User %s added." % email)
    flash("Logged in")
    return redirect("/") 
開發者ID:AnliYang,項目名稱:bobafetch,代碼行數:23,代碼來源:server.py

示例5: login_process

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def login_process():
    """Process login."""

    email = request.form["email"]
    password = request.form["password"]

    user = User.query.filter(User.email==email).first()

    if not user:
        flash("No such user")
        return redirect("/login")

    if user.password != password:
        flash("Incorrect password")
        return redirect("/login")

    session["user_id"] = user.user_id
    flash("Logged in")
    return redirect("/") 
開發者ID:AnliYang,項目名稱:bobafetch,代碼行數:21,代碼來源:server.py

示例6: add_to_favorites

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def add_to_favorites():
    """Add a favorite restaurant for a user"""

    yelp_location_id = request.form.get("yelp-id")
    user_id = session.get("user_id")

    if user_id:
        new_favorite = Favorite_Restaurant(user_id=user_id,
                                           yelp_location_id=yelp_location_id)
        db.session.add(new_favorite)
        db.session.commit()

        return jsonify(status="favorite", id=yelp_location_id)

    else:
        return jsonify(status="logged-out-user") 
開發者ID:AnliYang,項目名稱:bobafetch,代碼行數:18,代碼來源:server.py

示例7: add_to_visited

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def add_to_visited():
    """Add a visited restaurant for a user"""

    yelp_location_id = request.form.get("yelp-id")
    user_id = session.get("user_id")

    if user_id:
        new_visit = Visited_Restaurant(user_id=user_id,
                                           yelp_location_id=yelp_location_id)
        db.session.add(new_visit)
        db.session.commit()

        return jsonify(status="visited", id=yelp_location_id)

    else:
        return jsonify(status="logged-out-user") 
開發者ID:AnliYang,項目名稱:bobafetch,代碼行數:18,代碼來源:server.py

示例8: find_all

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def find_all(self):
        return self.__db_session.query(User.user_id) 
開發者ID:fontman,項目名稱:fontman-server,代碼行數:4,代碼來源:UserService.py

示例9: find_by_user_id

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def find_by_user_id(self, user_id):
        return self.__db_session.query(User).filter_by(user_id=user_id) 
開發者ID:fontman,項目名稱:fontman-server,代碼行數:4,代碼來源:UserService.py

示例10: load_users

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def load_users():
    """Load fake users for testing from file"""

    User.query.delete()

    for row in open("seed_data/MOCK_DATA_test.csv"):
        row = row.rstrip()
        user_id, username, email, password, account_created = row.split(",")

        user = User(user_id=user_id, username=username, email=email, 
                    password=password, account_created=account_created)

        db.session.add(user)
        db.session.commit() 
開發者ID:ceorourke,項目名稱:game_recommendations,代碼行數:16,代碼來源:seed.py

示例11: load_usersystems

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def load_usersystems():
    """Make all users own systems"""

    users = db.session.query(User.user_id).all()
    systems = db.session.query(System.system_id).all()

    for user in users:
        for system in systems:
            usersystem = UserSystem(user_id=user, system_id=system)
            db.session.add(usersystem)
            db.session.commit()
        print "Added systems for user #", user[0] 
開發者ID:ceorourke,項目名稱:game_recommendations,代碼行數:14,代碼來源:seed.py

示例12: load_ratings

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def load_ratings():
    """Load fake ratings for testing"""

    Rating.query.delete()

    users = db.session.query(User.user_id).all()
    games = db.session.query(Game.game_id).all()

    for user in users:
        for game in games:
            rating = randint(1,5)
            user_rating = Rating(user_id=user, game_id=game, score=rating)
            db.session.add(user_rating)
            db.session.commit()
        print "Added ratings for user #", user[0] 
開發者ID:ceorourke,項目名稱:game_recommendations,代碼行數:17,代碼來源:seed.py

示例13: set_val_user_id

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def set_val_user_id():
    """Set value for the next user_id after seeding database"""

    # Get the Max user_id in the database
    result = db.session.query(func.max(User.user_id)).one()
    max_id = int(result[0])

    # Set the value for the next user_id to be max_id + 1
    query = "SELECT setval('users_user_id_seq', :new_id)"
    db.session.execute(query, {'new_id': max_id + 1})
    db.session.commit()


#*****************************************************************************# 
開發者ID:ceorourke,項目名稱:game_recommendations,代碼行數:16,代碼來源:seed.py

示例14: set_val_user_id

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def set_val_user_id():
    """Set value for the next user_id after seeding database"""

    # Get the Max user_id in the database
    result = db.session.query(func.max(User.user_id)).one()
    max_id = int(result[0])

    # Set the value for the next user_id to be max_id + 1
    query = "SELECT setval('users_user_id_seq', :new_id)"
    db.session.execute(query, {'new_id': max_id + 1})
    db.session.commit() 
開發者ID:kjlundsgaard,項目名稱:ratings,代碼行數:13,代碼來源:seed.py

示例15: index

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import user_id [as 別名]
def index():
    """Homepage."""

    if 'user_id' in session:
        return redirect('/navigation')
    else:
        return render_template("homepage.html") 
開發者ID:elsabirch,項目名稱:gallery-wall,代碼行數:9,代碼來源:server.py


注:本文中的model.User.user_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。