当前位置: 首页>>代码示例>>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;未经允许,请勿转载。