本文整理汇总了Python中flask_login.current_user._get_current_object方法的典型用法代码示例。如果您正苦于以下问题:Python current_user._get_current_object方法的具体用法?Python current_user._get_current_object怎么用?Python current_user._get_current_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_login.current_user
的用法示例。
在下文中一共展示了current_user._get_current_object方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def index():
form = PostForm()
if current_user.can(Permission.WRITE_ARTICLES) and \
form.validate_on_submit():
post = Post(body=form.body.data,
author=current_user._get_current_object())
db.session.add(post)
return redirect(url_for('.index'))
page = request.args.get('page', 1, type=int)
show_followed = False
if current_user.is_authenticated:
show_followed = bool(request.cookies.get('show_followed', ''))
if show_followed:
query = current_user.followed_posts
else:
query = Post.query
pagination = query.order_by(Post.timestamp.desc()).paginate(
page, per_page=current_app.config['CIRCULATE_POSTS_PER_PAGE'],
error_out=False)
posts = pagination.items
return render_template('index.html', form=form, posts=posts,
show_followed=show_followed, pagination=pagination)
示例2: post
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def post(id):
post = Post.query.get_or_404(id)
form = CommentForm()
if form.validate_on_submit():
comment = Comment(body=form.body.data,
post=post,
author=current_user._get_current_object())
db.session.add(comment)
flash('Your comment has been published.')
return redirect(url_for('.post', id=post.id, page=-1))
page = request.args.get('page', 1, type=int)
if page == -1:
page = (post.comments.count() - 1) // \
current_app.config['CIRCULATE_COMMENTS_PER_PAGE'] + 1
pagination = post.comments.order_by(Comment.timestamp.asc()).paginate(
page, per_page=current_app.config['CIRCULATE_COMMENTS_PER_PAGE'],
error_out=False)
comments = pagination.items
return render_template('post.html', posts=[post], form=form,
comments=comments, pagination=pagination)
示例3: write
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def write():
form = PostForm()
if current_user.operation(Permission.WRITE_ARTICLES) and \
form.validate_on_submit():
if 'save_draft' in request.form and form.validate():
post = Post(body=form.body.data,
title=form.title.data,
draft= True,
author = current_user._get_current_object())
db.session.add(post)
flash('保存成功!')
elif 'submit' in request.form and form.validate():
post = Post(body=form.body.data,
title=form.title.data,
author=current_user._get_current_object())
db.session.add(post)
flash('发布成功!')
return redirect(url_for('user.write'))
return render_template('user/write.html',
form=form,
post=form.body.data,
title='写文章')
# 草稿
示例4: reply
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def reply(id):
comment = Comment.query.get_or_404(id)
post = Post.query.get_or_404(comment.post_id)
page = request.args.get('page', 1, type=int)
form = ReplyForm()
if form.validate_on_submit():
reply_comment = Comment(body=form.body.data,
unread=True,
post=post,comment_type='reply',
reply_to=comment.author.nickname,
author=current_user._get_current_object())
db.session.add(reply_comment)
flash('你的回复已经发表。')
return redirect(url_for('user.post', id=comment.post_id, page=page))
return render_template('user/reply.html',
form=form,
comment=comment,
title='回复')
# 管理评论
# 恢复评论,即是将Comment模型的disabled的布尔值设为Flase
示例5: filter_columns_by_role
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def filter_columns_by_role(columns, to_filter_cols, role):
"""
Filter columns based on user's role
:param columns: Columns to be filtered
:param to_filter_cols: columns to remove if user does not have that role
:param role: User need this role to show the to_filter_cols
:return: A filtered column list
"""
new_col_list = []
local_user = current_user._get_current_object()
if (not user_has_role(role, local_user)):
for l in columns:
if l[0] not in to_filter_cols:
new_col_list.append(l)
columns = tuple(new_col_list)
return columns
示例6: index
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def index():
form = PostForm()
if current_user.can(Permission.WRITE_ARTICLES) and \
form.validate_on_submit():
post = Post(body=form.body.data,
author=current_user._get_current_object())
db.session.add(post)
return redirect(url_for('.index'))
page = request.args.get('page', 1, type=int)
show_followed = False
if current_user.is_authenticated:
show_followed = bool(request.cookies.get('show_followed', ''))
if show_followed:
query = current_user.followed_posts
else:
query = Post.query
pagination = query.order_by(Post.timestamp.desc()).paginate(
page, per_page=current_app.config['FLASKY_POSTS_PER_PAGE'],
error_out=False)
posts = pagination.items
return render_template('index.html', form=form, posts=posts,
show_followed=show_followed, pagination=pagination)
示例7: post
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def post(id):
post = Post.query.get_or_404(id)
form = CommentForm()
if form.validate_on_submit():
comment = Comment(body=form.body.data,
post=post,
author=current_user._get_current_object())
db.session.add(comment)
flash('Your comment has been published.')
return redirect(url_for('.post', id=post.id, page=-1))
page = request.args.get('page', 1, type=int)
if page == -1:
page = (post.comments.count() - 1) // \
current_app.config['FLASKY_COMMENTS_PER_PAGE'] + 1
pagination = post.comments.order_by(Comment.timestamp.asc()).paginate(
page, per_page=current_app.config['FLASKY_COMMENTS_PER_PAGE'],
error_out=False)
comments = pagination.items
return render_template('post.html', posts=[post], form=form,
comments=comments, pagination=pagination)
示例8: post
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def post(id):
post = Post.query.get_or_404(id)
post.view_num += 1
db.session.add(post)
# 评论
form = CommentForm()
if form.validate_on_submit():
comment = Comment(body=form.body.data,
post=post, unread=True,
author=current_user._get_current_object())
db.session.add(comment)
flash('你的评论已经发表成功。')
return redirect(url_for('user.post', id=post.id, page=-1))
page = request.args.get('page', 1, type=int)
if page == -1:
page = (post.comments.count() - 1) / \
current_app.config['COMMENTS_PER_PAGE'] + 1
pagination = post.comments.order_by(Comment.timestamp.asc()).paginate(
page, per_page=current_app.config['COMMENTS_PER_PAGE'],
error_out=False
)
comments = pagination.items
return render_template('user/post.html', posts=[post],
title=post.title, id=post.id,
post=post, form=form,
comments=comments,
pagination=pagination)
# 点赞
示例9: like
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def like(id):
post = Post.query.get_or_404(id)
if post.like_num.filter_by(liker_id=current_user.id).first() is not None:
flash('你已经点赞。')
return redirect(url_for('user.post', id=post.id))
like = Like(post=post, unread=True,
user=current_user._get_current_object())
db.session.add(like)
flash('点赞成功!')
return redirect(url_for('user.post', id=post.id))
# 取消赞
示例10: unlike
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def unlike(id):
post = Post.query.get_or_404(id)
if post.like_num.filter_by(liker_id=current_user.id).first() is None:
flash('你还未点赞。')
return redirect(url_for('user.post', id=post.id))
# like = Like(post=post,
# user=current_user._get_current_object())
else:
f = post.like_num.filter_by(liker_id=current_user.id).first()
db.session.delete(f)
flash('已取消点赞。')
return redirect(url_for('user.post', id=post.id))
# 交互回复评论
示例11: change_password
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def change_password():
"""View function which handles a change password request."""
form_class = _security.change_password_form
if request.is_json:
form = form_class(MultiDict(request.get_json()), meta=suppress_form_csrf())
else:
form = form_class(meta=suppress_form_csrf())
if form.validate_on_submit():
after_this_request(_commit)
change_user_password(current_user._get_current_object(), form.new_password.data)
if not _security._want_json(request):
do_flash(*get_message("PASSWORD_CHANGE"))
return redirect(
get_url(_security.post_change_view)
or get_url(_security.post_login_view)
)
if _security._want_json(request):
form.user = current_user
return base_render_json(form, include_auth_token=True)
return _security.render_template(
config_value("CHANGE_PASSWORD_TEMPLATE"),
change_password_form=form,
**_ctx("change_password")
)
示例12: _identity_loader
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def _identity_loader():
if not isinstance(current_user._get_current_object(), AnonymousUserMixin):
identity = Identity(current_user.fs_uniquifier)
return identity
示例13: filter_columns_by_organization_type
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def filter_columns_by_organization_type(self, columns):
new_col_list = []
local_user = current_user._get_current_object()
if local_user is not None and local_user.is_anonymous is False:
if local_user.organization.type.code == "FRANCHISE_STORE":
for col in columns:
if col[0] != 'supplier':
new_col_list.append(col)
elif local_user.organization.type.code == "DIRECT_SELLING_STORE":
for col in columns:
if col[0] != 'to_organization':
new_col_list.append(col)
return tuple(new_col_list)
else:
return columns
示例14: profile
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def profile():
form = ProfileForm()
if form.validate_on_submit():
current_user.name = form.name.data
current_user.location = form.location.data
current_user.bio = form.bio.data
db.session.add(current_user._get_current_object())
db.session.commit()
flash('Your profile has been updated.')
return redirect(url_for('talks.user', username=current_user.username))
form.name.data = current_user.name
form.location.data = current_user.location
form.bio.data = current_user.bio
return render_template('talks/profile.html', form=form)
示例15: global_user
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import _get_current_object [as 别名]
def global_user():
# evaluate proxy value
g.user = current_user._get_current_object()