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


Python User.make_valid_nickname方法代碼示例

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


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

示例1: after_login

# 需要導入模塊: from app.users.models import User [as 別名]
# 或者: from app.users.models.User import make_valid_nickname [as 別名]
def after_login(resp):
    if resp.email is None or resp.email == "":
        flash(gettext('Invalid login. Please try again.'))
        return redirect(url_for('login_view'))
    user = User.query.filter_by(email = resp.email).first()
    userdetails = UserDetails(user=user)
    if user is None:
        nickname = resp.nickname
        if nickname is None or nickname == "":
            nickname = resp.email.split('@')[0]
        nickname = User.make_valid_nickname(nickname)
        nickname = User.make_unique_nickname(nickname)
        user = User(nickname = nickname, email = resp.email, role = ROLE_USER)
        
        db.session.add(user)
        db.session.add(userdetails)
        db.session.commit()
        # make the user follow him/herself
        db.session.add(user.follow(user))
        db.session.commit()
        
    userdetails = UserDetails.query.filter_by(user=user).first()
    if userdetails is None:
        userdetails = UserDetails(user=user)
        db.session.add(userdetails)
        db.session.commit()
        
    remember_me = False
    if 'remember_me' in session:
        remember_me = session['remember_me']
        session.pop('remember_me', None)
    login_user(user, remember = True)
    return redirect(request.args.get('next') or url_for('main_flow.index'))
開發者ID:nava45,項目名稱:connection,代碼行數:35,代碼來源:views.py

示例2: validate

# 需要導入模塊: from app.users.models import User [as 別名]
# 或者: from app.users.models.User import make_valid_nickname [as 別名]
	def validate(self):
		valid = True
		if not Form.validate(self):
			valid = False

		if self.name.data != User.make_valid_name(self.name.data):
			self.name.errors.append(gettext('This name has invalid characters'))
			valid = False

		if self.nickname.data != User.make_valid_nickname(self.nickname.data):
			self.nickname.errors.append(gettext('This nickname has invalid characters'))
			valid = False

		if User.is_email_taken(self.email.data):
			self.email.errors.append(gettext('This email is already in use. Please choose another one.'))
			valid = False			

		if User.is_nickname_taken(self.nickname.data):
			self.nickname.errors.append(gettext('This nickname is already in use. Please choose another one.'))
			valid = False
		return valid
開發者ID:Tibodef,項目名稱:PythonBlog,代碼行數:23,代碼來源:forms.py


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