本文整理汇总了Python中models.User.name方法的典型用法代码示例。如果您正苦于以下问题:Python User.name方法的具体用法?Python User.name怎么用?Python User.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fb_oauth_request
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def fb_oauth_request():
"""handle facebook oauth requests"""
user = None
user_info = {}
# do not request real data if testing
if app.config["TESTING"] is True:
print "testing enabled, adding fake fb user"
# and request.data == 'testytesttest':
for f in fb_user_info_fields:
user_info[f] = "test_%s" % f
login_session["state"] = "testingstate"
login_session["user_info"] = user_info
flash("You are now logged in as %s" % user_info["name"])
user = User()
user.fb_id = "12345"
user.email = user_info["email"]
user.picture = user_info["picture"]
user.provider = user_info["provider"]
user.name = user_info["name"]
session.add(user)
session.commit()
# add id after .commit() assigns it
user_info["user_id"] = user.id
return make_json_response(json.dumps("ok"), 200)
else:
if request.args.get("state") != login_session["state"]:
print "fbconnect: bad state parameter"
flash("bad login state parameter")
return make_json_response(json.dumps("invalid state parameter."), 401)
# continue oauth flow
user_info = getUserDataFB(request)
if "error" in user_info.keys():
return make_json_response(user_info["error"], 400)
# oauth successful
# check db for existing user
try:
user = session.query(User).filter_by(email=user_info["email"]).one()
except db.NoResultFound:
# create a new user
user = User()
user.fb_id = user_info["facebook_id"]
user.email = user_info["email"]
user.picture = user_info["picture"]
user.provider = user_info["provider"]
user.name = user_info["name"]
session.add(user)
session.commit()
user_info["user_id"] = user.id
flash("You are now logged in as %s" % user_info["name"])
# add user to session
login_session["user_info"] = user_info
return make_json_response(json.dumps("ok"), 200)
示例2: create
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def create():
existing = User.query.filter(User.facebook_id == request.form["facebook_id"]).first()
if existing is not None:
existing.gcm = request.form["gcm"]
db.session.commit()
return jsonify({
"creation": "success",
"token": existing.token
})
user = User()
user.name = request.form["name"]
user.token_id = request.form["token_id"]
user.facebook_id = request.form["facebook_id"]
user.gcm = request.form["gcm"]
user.hash_password(request.form["facebook_id"])
db.session.add(user)
db.session.commit()
return jsonify({
"creation": "success",
"token": user.token
})
示例3: create_digest
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def create_digest(self, item_type, github_items):
"""
builds a DigestData instance filled with the digest
"""
issue_list = list(self.get_issues())
digest = DigestData(item_type)
digest.user = self._user
digest.repo = self._repository_name
for github_item in github_items:
if github_item.state == ItemStates.OPEN:
digest.total_opened += 1
elif github_item.state == ItemStates.CLOSED:
digest.total_closed += 1
digest.total_items += 1
item = Item()
item.url = github_item.html_url
item.label = '{}/{}#{}'.format(self._user, self._repository_name, github_item.number)
item.title = github_item.title
item.state = github_item.state
github_user = github_item.user
display_name = github_user.name or github_user.login
if display_name not in digest.users:
user = User()
user.name = display_name
user.gravatar = github_user.avatar_url
digest.users[display_name] = user
digest.items.setdefault(display_name, []).append(item)
return digest
示例4: get_digest
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def get_digest(self):
"""
builds a DigestData instance filled with the digest
"""
issue_list = list(self.get_issues())
digest = DigestData()
digest.user = self._user
digest.repo = self._repository_name
for github_issue in issue_list:
if github_issue.state == IssueStates.OPEN:
digest.total_opened += 1
elif github_issue.state == IssueStates.CLOSED:
digest.total_closed += 1
digest.total_issues += 1
issue = Issue()
issue.url = github_issue.html_url
issue.label = '{}/{}#{}'.format(self._user, self._repository_name, github_issue.number)
issue.title = github_issue.title
issue.state = github_issue.state
github_user = github_issue.user
display_name = github_user.name or github_user.login
if display_name not in digest.users:
user = User()
user.name = display_name
user.gravatar = github_user.avatar_url
digest.users[display_name] = user
digest.issues.setdefault(display_name, []).append(issue)
return digest
示例5: save
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def save(self, *args, **kwargs):
"Form processor"
profile = None
if self.invitation:
# Create DjangoUser
django_user = django_auth.User(
username=self.cleaned_data['username'], password='')
django_user.set_password(self.cleaned_data['password'])
django_user.save()
# Crate profile
try:
profile = django_user.profile
except:
profile = User()
profile.user = django_user
profile.name = django_user.username
profile.default_group = self.invitation.default_group
profile.save()
# Create contact
try:
contact_type = ContactType.objects.get(
Q(name='Person') | Q(slug='person'))
except:
contact_type = ContactType.objects.all()[0]
try:
# Check if contact has already been created (e.g. by a signals
contact = profile.get_contact()
if not contact:
contact = Contact()
except:
contact = Contact()
contact.name = self.cleaned_data['name']
contact.contact_type = contact_type
contact.related_user = profile
contact.save()
# Set email
try:
emailfield = contact_type.fields.filter(field_type='email')[0]
email = ContactValue(
value=self.invitation.email, field=emailfield, contact=contact)
email.save()
except:
pass
# Add quick start widget
widget = Widget(user=profile,
perspective=profile.get_perspective(),
module_name='anaf.core',
widget_name='widget_welcome')
widget.save()
return profile
示例6: sign_up
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def sign_up():
_name = request.form['inputName']
_user_name = request.form['inputUserName']
_password = request.form['inputPassword']
username_list = g.sql_session.query(User.username).all()
if (_user_name,) not in username_list:
user = User()
user.name = _name
user.username = _user_name
user.password = generate_password_hash(_password)
user.type = 1
g.sql_session.add(user)
try:
g.sql_session.commit()
except Exception as e:
flash(str(e))
g.sql_session.rollback()
return redirect(url_for('.show_sign_up'))
session['user'] = _user_name
session['name'] = _name
session['type'] = user.type
return redirect(url_for('.user_home'))
else:
flash("The duplicated username")
return redirect(url_for('.show_sign_up'))
示例7: auth_callback
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def auth_callback(self):
client_token = request.args.get('token')
# Check the provided token is valid.
token_user = current_app.trello.fetch_member('me', client_token)
user_id = token_user['id']
user_email = token_user['email']
user_name = token_user['fullName']
# Create/Update existing user...
user = current_app.db.session.query(User).filter_by(trello_id=user_id).first()
if user is None:
# Make a user
user = User(trello_id=user_id)
current_app.db.session.add(user)
# Update their details
user.name = user_name
user.email = user_email
user.trello_token = client_token
current_app.db.session.commit()
# And log them in...
login_user(user, remember=True)
return redirect(url_for('IndexView:index'))
示例8: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def post(self):
if self.user:
self.redirect(self.uri_for('www-dashboard-admin'))
return
if self.request.get('email') and self.request.get('first_name') and self.request.get('last_name') and self.request.get('password'):
email = self.request.get('email').strip().lower()
name = self.request.get('first_name') + " " + self.request.get('last_name')
phone = self.request.get('phone')
password = self.request.get('password')
user = User.get_by_id(email)
if user:
self.redirect(self.uri_for('www-register', error="User already exist. Please log in."))
return
user = User(id=email)
user.email = email
user.password = hash_password(email, password)
user.name = name
user.phone = phone
user.put()
self.login(user)
if self.request.get('goto'):
self.redirect(self.request.get('goto'))
else:
self.redirect(self.uri_for('www-dashboard-admin'))
return
else:
self.redirect(self.uri_for('www-register', Error="Please enter the all information required."))
示例9: register
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def register():
if request.method == 'POST':
logger.info('Registration POST: %s%s%s'\
% (request.form['email'], \
request.form['name'],\
request.form['tel']))
user = User()
user.name = request.form.get('name', None)
user.email = request.form.get('email', None)
user.tel = request.form.get('tel', None)
user.msg = request.form.get('message', None)
if not user.is_valid:
logger.error('No valid form. Request:%s' % request)
return jsonify(False)
try:
user.save()
except:
logger.error('Don\'t save in base. Request:%s' % request)
return jsonify('Error')
logger.info('Register:Done!')
send_email(user)
return jsonify(True)
else:
return jsonify(False)
示例10: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def post(self):
fbid = self.request.get('fbid')
fbtoken = self.request.get('fbtoken')
fbexpires = self.request.get('fbexpires')
email = self.request.get('email')
picture = self.request.get('picture')
name = self.request.get('name')
nick = self.request.get('nick')
user = User.query(User.email == email).get()
if user == None:
user = User()
user.status = '1'
user.email = email
user.name = name
user.nick = nick
user.picture = picture
user.fb = json.dumps({'status': 0, 'id': fbid, 'token': fbtoken, 'expires': fbexpires})
user.put()
ret = {'status': 0, 'message': 'User ' + email + ' set.'}
self.response.out.write(json.dumps(ret))
示例11: add_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def add_user(data):
user = User(id=data["email"])
user.password = data["password"]
user.name = data["name"]
user.email = data["email"]
user.contacts = data["contacts"]
user.permissions = data["permissions"]
user.put()
return user
示例12: createAccount
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def createAccount(request):
fromNumber = request.REQUEST['From']
user = request.REQUEST['Name']
current_tab = request.REQUEST['currentTab']
u = User()
u.name = user
u.currentTab= current_tab
u.number = fromNumber[1:]
u.save()
return HttpResponse()
示例13: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def post(self):
username = self.get_argument('name')
password = self.get_argument('password')
user = User()
user.name = username
user.password = password
self.session.add(user)
self.session.commit()
self.set_secure_cookie('user', str(user.id))
self.redirect(self.get_argument("next", "/"))
示例14: save_users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def save_users():
for udata in iterate_file("user", shortcircuit=False):
user = User()
user.user_id = udata['user_id']
user.name = udata['name']
user.review_count = int(udata['review_count'])
user.average_stars = decimal.Decimal(udata.get('average_stars', 0))
user.useful_votes = int(udata['votes']['useful'])
user.funny_votes = int(udata['votes']['funny'])
user.cool_votes = int(udata['votes']['cool'])
user.save()
示例15: decorated
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import name [as 别名]
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
User.objects.delete()
user = User()
user.name = auth.username
user.save()
g.user = user
return f(*args, **kwargs)