Python flask_login.current_user._get_current_object() Examples
The following are 23
code examples of flask_login.current_user._get_current_object().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_login.current_user
, or try the search function
.
Example #1
Source File: views.py From circleci-demo-python-flask with MIT License | 6 votes |
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)
Example #2
Source File: views.py From Simpleblog with MIT License | 6 votes |
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='写文章') # 草稿
Example #3
Source File: views.py From circleci-demo-python-flask with MIT License | 6 votes |
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)
Example #4
Source File: views.py From Simpleblog with MIT License | 6 votes |
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
Example #5
Source File: views.py From flasky-first-edition with MIT License | 6 votes |
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)
Example #6
Source File: views.py From flasky-first-edition with MIT License | 6 votes |
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)
Example #7
Source File: security_util.py From betterlifepsi with MIT License | 6 votes |
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
Example #8
Source File: change_password.py From flask-react-spa with MIT License | 5 votes |
def change_password(): user = current_user._get_current_object() form = _security.change_password_form(MultiDict(request.get_json())) if form.validate_on_submit(): after_this_request(_commit) change_user_password(user, form.newPassword.data) else: return jsonify({'errors': form.errors}), HTTPStatus.BAD_REQUEST return jsonify({'token': user.get_auth_token()})
Example #9
Source File: check_auth_token.py From flask-react-spa with MIT License | 5 votes |
def check_auth_token(): return jsonify({'user': current_user._get_current_object()})
Example #10
Source File: todo.py From todoism with MIT License | 5 votes |
def new_item(): data = request.get_json() if data is None or data['body'].strip() == '': return jsonify(message=_('Invalid item body.')), 400 item = Item(body=data['body'], author=current_user._get_current_object()) db.session.add(item) db.session.commit() return jsonify(html=render_template('_item.html', item=item), message='+1')
Example #11
Source File: views.py From braindump with MIT License | 5 votes |
def add(): if request.args.get('notebook'): notebook = Notebook.query.filter_by( id=int(request.args.get('notebook'))).first() form = NoteForm(notebook=notebook.id) else: form = NoteForm() form.notebook.choices = [ (n.id, n.title) for n in Notebook.query.filter_by( author_id=current_user.id, is_deleted=False).all()] if form.validate_on_submit(): note = Note( title=form.title.data, body=form.body.data, notebook_id=form.notebook.data, author=current_user._get_current_object()) db.session.add(note) db.session.commit() tags = [] if not len(form.tags.data) == 0: for tag in form.tags.data.split(','): tags.append(tag.replace(" ", "")) note.str_tags = (tags) db.session.commit() return redirect(url_for('main.notebook', id=note.notebook_id)) return render_template('app/add.html', form=form)
Example #12
Source File: middleware.py From maple-bbs with GNU General Public License v3.0 | 5 votes |
def preprocess_request(self): g.user = current_user g.sort_form = SortForm() g.sort_form = set_form(g.sort_form) request.user = current_user._get_current_object() if request.method == 'GET': request.data = request.args.to_dict() else: request.data = request.json if request.data is None: request.data = request.form.to_dict()
Example #13
Source File: views.py From BhagavadGita with GNU General Public License v3.0 | 5 votes |
def create_app(): badge_list = [] form = CreateAppForm() if form.validate_on_submit(): app = App( application_id=gen_salt(10), application_name=form.application_name.data, application_description=form.application_description.data, application_website=form.application_website.data, user_id=current_user.id) db.session.add(app) db.session.flush() item = Client( client_id=gen_salt(40), client_secret=gen_salt(50), _default_scopes='verse chapter', user_id=current_user.id, app_id=app.application_id) db.session.add(item) db.session.commit() send_email( recipient=current_user.email, subject='Application Successfully Registered', template='account/email/confirm_app', user=current_user._get_current_object(), app_name=form.application_name.data) flash('You application has been created.', 'success') return redirect( url_for('account.update_app', application_id=app.application_id)) return render_template( 'account/create_app.html', user=current_user._get_current_object(), form=form, badge_list=badge_list)
Example #14
Source File: views.py From BhagavadGita with GNU General Public License v3.0 | 5 votes |
def confirm_request(): """Respond to new user's request to confirm their account.""" token = current_user.generate_confirmation_token() confirm_link = url_for('account.confirm', token=token, _external=True) send_email( recipient=current_user.email, subject='Confirm Your Account', template='account/email/confirm', # current_user is a LocalProxy, we want the underlying user object user=current_user._get_current_object(), confirm_link=confirm_link) flash( 'A new confirmation link has been sent to {}.'.format( current_user.email), 'warning') return redirect(url_for('main.index'))
Example #15
Source File: views.py From BhagavadGita with GNU General Public License v3.0 | 5 votes |
def change_email_request(): """Respond to existing user's request to change their email.""" badge_list = [] form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_email_change_token(new_email) change_email_link = url_for( 'account.change_email', token=token, _external=True) send_email( recipient=new_email, subject='Confirm Your New Email', template='account/email/change_email', # current_user is a LocalProxy, we want the underlying user # object user=current_user._get_current_object(), change_email_link=change_email_link) flash('A confirmation link has been sent to {}.'.format(new_email), 'warning') return redirect(url_for('main.index')) else: flash('Invalid email or password.', 'form-error') return render_template( 'account/manage.html', form=form, user=current_user, badge_list=badge_list)
Example #16
Source File: app.py From profbit with MIT License | 5 votes |
def global_user(): # evaluate proxy value g.user = current_user._get_current_object()
Example #17
Source File: routes.py From flask-pycon2014 with MIT License | 5 votes |
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)
Example #18
Source File: base_purchase_order.py From betterlifepsi with MIT License | 5 votes |
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
Example #19
Source File: core.py From flask-security with MIT License | 5 votes |
def _identity_loader(): if not isinstance(current_user._get_current_object(), AnonymousUserMixin): identity = Identity(current_user.fs_uniquifier) return identity
Example #20
Source File: views.py From flask-security with MIT License | 5 votes |
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") )
Example #21
Source File: views.py From Simpleblog with MIT License | 5 votes |
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)) # 交互回复评论
Example #22
Source File: views.py From Simpleblog with MIT License | 5 votes |
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)) # 取消赞
Example #23
Source File: views.py From Simpleblog with MIT License | 5 votes |
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) # 点赞