本文整理汇总了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()
示例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()
示例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,
)
示例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("/")
示例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("/")
示例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")
示例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")
示例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)
示例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)
示例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()
示例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]
示例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]
示例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()
#*****************************************************************************#
示例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()
示例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")