本文整理汇总了Python中model.User.add方法的典型用法代码示例。如果您正苦于以下问题:Python User.add方法的具体用法?Python User.add怎么用?Python User.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import add [as 别名]
def main():
"""docstring for main"""
username_list = {}
data = file("data/petster-hamster/ent.petster-hamster")
for item in data.readlines():
if not item.startswith("%"):
res = INFO_PATTERN.findall(item)
info = dict(zip(KEYS, res))
username_list[info["id"]] = info["username"]
user = User(info)
user.add()
data.close()
data = file("data/petster-hamster/out.petster-hamster")
for item in data.readlines():
# print repr(item)
# raw_input()
if not item.startswith("%"):
uid1, uid2 = item.strip().split(" ")
# print repr(uid1), repr(uid2)
# raw_input()
username1 = username_list[uid1]
username2 = username_list[uid2]
user1 = User.get(username1)
user2 = User.get(username2)
user1.follow(username2)
user2.follow(username1)
data.close()
示例2: register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import add [as 别名]
def register():
if request.method == 'GET':
return render_template('register.html', page='signup')
elif request.method == 'POST':
username = request.form.get('username', None)
nickname = request.form.get('nickname', None)
password = request.form.get('password', None)
password_again = request.form.get('password_again', None)
if username is None or nickname is None or password is None or password_again is None:
flash(u'请检查输入是否为空', 'danger')
return redirect(url_for('register'))
password, password_again, username, nickname = unicode(password), unicode(password_again), unicode(username), unicode(nickname)
# 1. 用户名是否存在
user = User.query.filter_by(username=username).first()
if user:
flash(u'该用户名已被注册', 'danger')
return redirect(url_for('register'))
# 2. 密码输入不一致
if password != password_again:
flash(u'两次密码输入不一致', 'danger')
return redirect(url_for('register'))
proc_password = utils.encrypt_password(password, salt=config.SALT)
User.add(User(username, proc_password, nickname))
flash(u'注册成功', 'success')
return redirect(url_for('login'))
示例3: oauth_authorized
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import add [as 别名]
def oauth_authorized(resp):
"""Called after authorization. After this function finished handling,
the OAuth information is removed from the session again. When this
happened, the tokengetter from above is used to retrieve the oauth
token and secret.
Because the remote application could have re-authorized the application
it is necessary to update the values in the database.
If the application redirected back after denying, the response passed
to the function will be `None`. Otherwise a dictionary with the values
the application submitted. Note that Twitter itself does not really
redirect back unless the user clicks on the application name.
"""
next_url = request.args.get('next') or url_for('index')
if resp is None:
#TODO: show friendly message
#flash(u'You denied the request to sign in.')
return redirect(next_url)
screen_name = resp['screen_name']
oauth_token = resp['oauth_token']
oauth_token_secret = resp['oauth_token_secret']
user = User.select_by_screen_name(screen_name)
if not user:
app.logger.debug('User not found on database. Using the Twitter API')
auth = tweepy.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET)
auth.set_access_token(oauth_token, oauth_token_secret)
api = tweepy.API(auth)
twitter_user = api.get_user(screen_name=screen_name)
user = User()
user.id = twitter_user.id
user.screen_name = twitter_user.screen_name
user.blocked = 'N'
user.name = twitter_user.name
user.description = twitter_user.description
user.created_at = twitter_user.created_at
user.friends_count = twitter_user.friends_count
user.followers_count = twitter_user.followers_count
user.statuses_count = twitter_user.statuses_count
user.profile_image_url = twitter_user.profile_image_url
user.lang = twitter_user.lang
user.location = twitter_user.location
user.oauth_token = oauth_token
user.oauth_token_secret = oauth_token_secret
User.add(user)
else:
user.oauth_token = oauth_token
user.oauth_token_secret = oauth_token_secret
flask.session['screen_name'] = resp['screen_name']
flask.session['oauth_token'] = resp['oauth_token']
flask.session['oauth_token_secret'] = resp['oauth_token_secret']
commit()
return flask.redirect(next_url)
示例4: registration_process
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import add [as 别名]
def registration_process():
"""Process registration."""
email = request.form["register-email"]
password = request.form["password"]
if User.get_by_email(email):
flash("That email is already registered. ")
flash("Please register with a different email.")
print "email already taken"
return redirect("/")
User.add(email, password)
flash("Registration successful. Welcome %s!" % email)
return render_template("homepage.html")
示例5: index_post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import add [as 别名]
def index_post():
"""
Check validation for SignIn or SignUp
:rtype: login page with form
"""
action = request.GET.get('action', 'signin')
username = request.forms.get('username')
password = request.forms.get('password')
if action == 'signup':
password_confirm = request.forms.get('password_confirm')
invitation = request.forms.get('invitation')
res, msg = User.add(username, password, password_confirm, invitation)
else:
res, msg = User.auth(username, password)
if res:
response.set_cookie('username', username, secret=COOKIES_SECRET)
redirect('/%s/timeline/' % username)
else:
return template(action, username=username, msg=msg)
示例6: main
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import add [as 别名]
def main():
"""docstring for main"""
data = file('data/petster-hamster/ent.petster-hamster')
for item in data.readlines():
item = item.decode('utf8')
# print repr(item)
# print type(item)
# print item
if not item.startswith('%'):
res = INFO_PATTERN.findall(item)
info = dict(zip(KEYS, res))
print info['username']
res, user = User.add(
username=info['username'],
password='pyneo4jet%s' % info['username'],
password_confirm='pyneo4jet%s' % info['username'],
invitation=INVITATION_CODE,
)
user.update(
name=info['name'],
gender=info['gender'],
hometown=info['hometown'],
)
for key in KEYS:
res, msg = Tweet.add(info['username'],
'My %s is %s' % (key, info[key]),
(
datetime.datetime.now() -
datetime.timedelta(days=random.randrange(0, 365)) -
datetime.timedelta(seconds=random.randrange(0, 86400))
).strftime('%Y-%m-%d %H:%M:%S'),
)
if not res:
print msg
print key
print info[key]
raw_input()
data.close()
data = file('data/petster-hamster/out.petster-hamster')
for item in data.readlines():
# print repr(item)
# raw_input()
if not item.startswith('%'):
username1, username2 = item.strip().split(' ')
print username1, username2
# raw_input()
user1 = User.get(username1)
user2 = User.get(username2)
if user1 and user2:
if (int(username1) + int(username2)) % 2 == 0:
res, msg = user2.follow(username1)
else:
res, msg = user1.follow(username2)
if not res:
print msg
raw_input()
data.close()
db.shutdown()