本文整理汇总了Python中daimaduan.models.base.User.objects方法的典型用法代码示例。如果您正苦于以下问题:Python User.objects方法的具体用法?Python User.objects怎么用?Python User.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类daimaduan.models.base.User
的用法示例。
在下文中一共展示了User.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_mail_post
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def send_mail_post():
form = EmailForm(request.forms)
if form.validate():
user = User.objects(email=form.email.data).first()
send_confirm_email(app.config, user.email)
return redirect('/success_sendmail')
return {'form': form}
示例2: create_paste
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def create_paste():
if request.method == 'GET':
# missing csrf
form = PasteForm(data={'codes': [{'title': '', 'content': ''}]})
return render_template('pastes/create.html', form=form)
else:
form = PasteForm(request.form)
if form.validate():
user = current_user.user
paste = save_paste_and_codes(form)
if not paste.is_private:
followers = User.objects(followings=user)
content = NEW_PASTE.format(user_username=user.username,
user_url=url_for('user_app.view', username=user.username),
paste_title=paste.title,
paste_url=url_for('paste_app.view_paste', hash_id=paste.hash_id))
for follower in followers:
message = Message(user=follower,
who=user,
content=content)
message.save()
return jsonify(success=True, hash_id=paste.hash_id)
else:
errors = form.errors
errors['codes'] = [code.errors for code in form.codes]
logger.info('Failed saving paste for reason: %s', errors)
return jsonify(success=False, errors=errors)
示例3: lost_password_post
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def lost_password_post():
form = EmailForm(request.forms)
if form.validate():
user = User.objects(email=form.email.data).first()
send_reset_password_email(app.config, user.email)
return redirect('/reset_password_email_sent')
return {'form': form}
示例4: validate_email
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def validate_email(self, field):
if session['email']:
if session['email'] != field.data:
raise ValidationError(u'不能修改第三方登录的email地址')
user = User.objects(email=field.data).first()
if user:
raise ValidationError(u'Email地址已被使用')
示例5: reset_password_get
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def reset_password_get(token):
email = validate_token(app.config, token)
if email:
user = User.objects(email=email).first()
if user:
return {'form': PasswordForm(), 'token': token}
abort(404)
示例6: validate_username
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def validate_username(self, field):
if current_user.is_authenticated and current_user.user.username == field.data:
return True
user = User.objects(username=field.data).first()
if user:
raise ValidationError(u'用户名已被使用')
示例7: unwatch_user
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def unwatch_user(username):
be_followed_user = User.objects(username=username).first_or_404()
if be_followed_user.is_followed_by(current_user.user):
be_followed_user.followers.remove(current_user.user)
be_followed_user.save()
return jsonify(watchedStatus=be_followed_user.is_followed_by(current_user.user))
示例8: send_email
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def send_email():
form = EmailForm()
if form.validate_on_submit():
user = User.objects(email=form.email.data).first()
send_confirm_email(current_app.config, user.email)
return redirect('/success_sendmail')
return render_template('sendmail.html',
form=form)
示例9: unwatch_user
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def unwatch_user(username):
following_user = User.objects(username=username).first_or_404()
if current_user.user.is_following(following_user):
current_user.user.followings.remove(following_user)
current_user.user.save()
return jsonify(watchedStatus=current_user.user.is_following(following_user))
示例10: view_followers
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def view_followers(username):
page = get_page()
user = User.objects.get_or_404(username=username)
pagination = User.objects(followings=user).paginate(page, per_page=20)
return render_template('users/followers.html',
user=user,
pagination=pagination)
示例11: view_bookmarks
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def view_bookmarks(username):
page = get_page()
user = User.objects(username=username).get_or_404()
pagination = Bookmark.objects(user=user).order_by('-updated_at').paginate(page, per_page=20)
return render_template('bookmarks/index.html',
pagination=pagination)
示例12: index
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def index():
page = get_page()
pagination = Paste.objects(is_private=False).order_by('-updated_at').paginate(page=page, per_page=20)
print datetime.today()
return render_template('index.html',
pagination=pagination,
hot_pastes=Paste.objects(is_private=False).order_by('-views')[:10],
pastes_count=Paste.objects().count(),
comments_count=Comment.objects().count(),
users_count=User.objects().count(),
syntax_count=Syntax.objects().count(),
bookmarks_count=Bookmark.objects().count(),
users_increased=User.objects(created_at__gt=date.today()).count(),
pastes_increased=Paste.objects(created_at__gt=date.today()).count(),
comments_increased=Comment.objects(created_at__gt=date.today()).count(),
bookmarks_increased=Bookmark.objects(created_at__gt=date.today()).count(),
tags=Tag.objects().order_by('-popularity')[:10])
示例13: validate
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def validate(self):
if not Form.validate(self):
return False
user = User.objects(email=self.email.data).first()
if not user:
self.email.errors.append(u'用户不存在')
return False
return True
示例14: validate_email
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def validate_email(self, field):
if current_user.is_authenticated:
field.data = current_user.user.email
return True
if session['email']:
if session['email'] != field.data:
raise ValidationError(u'不能修改第三方登录的email地址')
user = User.objects(email=field.data).first()
if user:
raise ValidationError(u'Email地址已被使用')
示例15: lost_password_get
# 需要导入模块: from daimaduan.models.base import User [as 别名]
# 或者: from daimaduan.models.base.User import objects [as 别名]
def lost_password_get():
if request.method == 'GET':
return render_template('user/lost_password.html',
form=EmailForm())
else:
form = EmailForm(request.forms)
if form.validate():
user = User.objects(email=form.email.data).first()
send_reset_password_email(current_app.config, user.email)
return redirect('/reset_password_email_sent')
return render_template('user/lost_password.html',
form=form)