我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用flask.ext.login.current_user.username()。
def edit_profile_admin(id): user = User.query.get_or_404(id) form = EditProfileAdminForm(user=user) if form.validate_on_submit(): user.email = form.email.data user.username = form.username.data user.confirmed = form.confirmed.data user.role = Role.query.get(form.role.data) user.name = form.name.data user.location = form.location.data user.about_me = form.about_me.data db.session.add(user) flash('The profile has been updated.') return redirect(url_for('.user', username=user.username)) form.email.data = user.email form.username.data = user.username form.confirmed.data = user.confirmed form.role.data = user.role_id form.name.data = user.name form.location.data = user.location form.about_me.data = user.about_me return render_template('edit_profile.html', form=form, user=user)
def edit_profile(): form = EditProfileForm() if form.validate_on_submit(): current_user.location = form.location.data current_user.about_me = form.about_me.data current_user.username = form.username.data db.session.add(current_user) db.session.commit() flash('??????!') return redirect(url_for('main.user_profile', username=current_user.username)) form.username.data = current_user.username form.about_me.data = current_user.about_me form.location.data = current_user.location return render_template('edit_profile.html', form=form) # ????????????
def edit_profile_admin(id): user = User.query.get_or_404(id) form = EditProfileAdminForm(user=user) if form.validate_on_submit(): user.email = form.email.data user.username = form.username.data user.confirmed = form.confirmed.data user.role = Role.query.get(form.role.data) user.location = form.location.data user.about_me = form.about_me.data db.session.add(user) db.session.commit() flash('??????!') return redirect(url_for('main.user_profile', username=user.username)) form.email.data = user.email form.username = user.username form.confirmed = user.confirmed form.role.data = user.role form.location.data = user.location form.about_me = user.about_me return render_template('edit_profile.html', form=form) # ??????
def followers(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('main.index')) page = request.args.get('page', 1, type=int) pagination = user.followers.paginate( page, per_page=10, error_out=False ) follows = [{'user': item.followers, 'timestamp': item.timestamp} for item in pagination.items] return render_template('followers.html', user=user, title="Followers of", endpoint='main.followers', pagination=pagination, follows=follows)
def edit_profile_admin(id): user = User.query.get_or_404(id) form = EditProfileAdminForm(user = user) if form.validate_on_submit(): user.email = form.email.data user.username = form.username.data print 'Role.query.get(form.role.data) = ', Role.query.get(form.role.data) user.role = Role.query.get(form.role.data) user.name = form.name.data user.location = form.location.data user.about_me = form.about_me.data db.session.add(user) flash('The profile has been updated.') return redirect(url_for('.user', username = user.username)) form.email.data = user.email form.username.data = user.username form.confirmed.data = user.confirmed form.role.data = user.role_id form.name.data = user.name form.location.data = user.location form.about_me.data = user.about_me return render_template('edit_profile.html', form = form, user = user)
def edit_profile(): form = EditProfileForm() if form.validate_on_submit(): current_user.name = form.name.data current_user.location = form.location.data current_user.about_me = form.about_me.data db.session.add(current_user) flash('Your profile has been updated.') # ???????? return redirect(url_for('.user', username=current_user.username)) form.name.data = current_user.name form.location.data = current_user.location form.about_me.data = current_user.about_me return render_template('edit_profile.html', form=form) # Admin??????profile
def edit_profile_admin(id): user = User.query.get_or_404(id) form = EditProfileAdminForm(user=user) if form.validate_on_submit(): user.email = form.email.data user.username = form.username.data user.confirmed = form.confirmed.data user.role = Role.query.get(form.role.data) user.name = form.name.data user.location = form.location.data user.about_me = form.about_me.data db.session.add(user) flash('The profile has been updated.') return redirect(url_for('.user', username=user.username)) form.email.data = user.email form.username.data = user.username form.confirmed.data = user.confirmed form.role.data = user.role_id form.name.data = user.name form.location.data = user.location form.about_me.data = user.about_me return render_template('edit_profile.html', form=form, user=user) #???????????
def followed_by(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) page = request.args.get('page', 1, type=int) pagination = user.followed.paginate( page, per_page=current_app.config['FLASKY_FOLLOWERS_PER_PAGE'], error_out=False) follows = [{'user': item.followed, 'timestamp': item.timestamp} for item in pagination.items] return render_template('followers.html', user=user, title="Followed by", endpoint='.followed_by', pagination=pagination, follows=follows) #??????
def user(username): user = User.query.filter_by(username=username).first_or_404() page = request.args.get('page', 1, type=int) pagination = user.posts.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('user.html', user=user, posts=posts, pagination=pagination)
def edit_profile(): form = EditProfileForm() if form.validate_on_submit(): current_user.name = form.name.data current_user.location = form.location.data current_user.about_me = form.about_me.data db.session.add(current_user) flash('Your profile has been updated.') return redirect(url_for('.user', username=current_user.username)) form.name.data = current_user.name form.location.data = current_user.location form.about_me.data = current_user.about_me return render_template('edit_profile.html', form=form)
def follow(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if current_user.is_following(user): flash('You are already following this user.') return redirect(url_for('.user', username=username)) current_user.follow(user) flash('You are now following %s.' % username) return redirect(url_for('.user', username=username))
def unfollow(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if not current_user.is_following(user): flash('You are not following this user.') return redirect(url_for('.user', username=username)) current_user.unfollow(user) flash('You are not following %s anymore.' % username) return redirect(url_for('.user', username=username))
def followed_by(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) page = request.args.get('page', 1, type=int) pagination = user.followed.paginate( page, per_page=current_app.config['FLASKY_FOLLOWERS_PER_PAGE'], error_out=False) follows = [{'user': item.followed, 'timestamp': item.timestamp} for item in pagination.items] return render_template('followers.html', user=user, title="Followed by", endpoint='.followed_by', pagination=pagination, follows=follows)
def edit_profile(): form = EditProfileForm() if form.validate_on_submit(): current_user.kindle_loc = form.kindle_loc.data db.session.add(current_user) db.session.commit() flash(u'???????.') return redirect(url_for('.index')) form.kindle_loc.data = current_user.kindle_loc return render_template('edit_profile.html', form=form) # @main.route('/letschat',methods = ['GET','POST']) # def letschat(): # form = MessageForm() # messages = Message.query.order_by(Message.time.desc()).all() # if form.validate_on_submit(): # if current_user.id == -1: # flash(u'???????') # return redirect(url_for('.letschat')) # message = Message(user_name=current_user.username,user_id=current_user.id,\ # message = form.message.data) # db.session.add(message) # db.session.commit() # return redirect(url_for('.letschat')) # return render_template('letschat.html',messages = messages,form = form) # @main.route('/usage') # def usage(): # return render_template('usage.html')
def post(id): post = Post.query.get_or_404(id) comments = Comment.query.order_by(Comment.timestamp.desc()) if current_user.is_authenticated: form = CommentForm() author = current_user._get_current_object() else: form = VisitorCommentForm() author = User(username=form.name.data) if form.validate_on_submit(): comment = Comment(body=form.body.data, post=post, author=author) db.session.add(comment) db.session.commit() flash('??????!') return redirect(url_for('.post', id=post.id, page=-1)) if post is None: abort(404) else: post.view_count += 1 db.session.add(post) db.session.commit() page = request.args.get('page', 1, type=int) if page == -1: page = (post.comments.count() - 1) / current_app.config['COMMENT_PER_PAGE'] + 1 pagination = post.comments.order_by(Comment.timestamp.asc()).paginate(page, per_page=current_app.config['COMMENT_PER_PAGE'], error_out=False) comments=pagination.items return render_template('post.html', post=post, form=form, comments=comments, pagination=pagination) # ????
def user_profile(username): user = User.query.filter_by(username=username).first() if user is None: abort(403) posts = user.posts.order_by(Post.timestamp.desc()).all() return render_template('user.html', user=user, posts=posts) # ??????
def follow(username): user = User.query.filter_by(username=username).first() if user is None: flash('?????') return redirect(url_for('main.index')) if current_user.is_following(user): flash('????????') return redirect(url_for('.user', username=username)) current_user.follow(user) flash('????? %s.' % username) return redirect(url_for('main.user', username=username)) # ????
def user(username): user = User.query.filter_by(username=username).first() if user is None: abort(404) questions = user.questions.order_by(Question.timestamp.desc()).all() tags = {} for question in questions: lines = Category.query.join(Potoca, Potoca.question_id == question.id)\ .filter( Category.id == Potoca.category_id) ls = [] for line in lines: ls.append(line.name) tags[question.id] = ls return render_template('user.html',user=user,questions=questions,tags=tags)
def edit_profile(): form = EditProfileForm() if form.validate_on_submit(): current_user.name = form.name.data current_user.location = form.location.data current_user.about_me = form.about_me.data db.session.add(current_user) flash('Your profile has been updated.') return redirect(url_for('.user',username=current_user.username)) form.name.data = current_user.name form.location.data = current_user.location form.about_me.data = current_user.about_me return render_template('edit_profile.html',form=form)
def new_post(): form = PostForm() if form.validate_on_submit(): new_post = Post(form.title.data) new_post.text = form.text.data new_post.publish_date = datetime.datetime.now() new_post.user = User.query.filter_by( username=current_user.username ).one() db.session.add(new_post) db.session.commit() return render_template('new.html', form=form)
def user(username): user = User.query.filter_by(username=username).first_or_404() posts = user.posts.order_by(Post.publish_date.desc()).all() recent, top_tags = sidebar_data() return render_template( 'user.html', user=user, posts=posts, recent=recent, top_tags=top_tags )
def new_post(): form = PostForm() if form.validate_on_submit(): if form.type.data == "blog": new_post = BlogPost() new_post.text = form.text.data elif form.type.data == "image": new_post = ImagePost() new_post.image_url = form.image.data elif form.type.data == "video": new_post = VideoPost() new_post.video_object = form.video.data elif form.type.data == "quote": new_post = QuotePost() new_post.text = form.text.data new_post.author = form.author.data new_post.title = form.title.data new_post.user = User.objects( username=current_user.username ).one() new_post.save() return render_template('new.html', form=form)
def user(username): user = User.query.filter_by(username = username).first() if user is None: abort(404) posts = user.posts.order_by(Post.timestamp.desc()).all() return render_template('user.html', user = user, posts=posts)
def edit_profile(): form = EditProfileForm() if form.validate_on_submit(): current_user.name = form.name.data current_user.location = form.location.data current_user.about_me = form.about_me.data db.session.add(current_user) flash('Your profile has been updated.') return redirect(url_for('.user', username = current_user.username)) form.name.data = current_user.name form.location.data = current_user.location form.about_me.data = current_user.about_me return render_template('edit_profile.html', form = form)
def follow(username): user = User.query.filter_by(username = username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if current_user.is_following(user): flash('You are already following this user.') return redirect(url_for('.user', username = username)) current_user.follow(user) flash('You are now following %s.' % username) return redirect(url_for('.user', username = username))
def basic(): form = BasicForm() if form.validate_on_submit(): if not current_user.set_pathname and current_user.pathname!=form.pathname.data: # ???????????? if not validate_pathname(form): return render_template("setting/basic.html", form=form) current_user.pathname = form.pathname.data current_user.set_pathname = True flash("????????") current_user.username = form.username.data db.session.commit() return render_template("setting/basic.html", form=form) return render_template("setting/basic.html", form=form)
def user(username): user = User.query.filter_by(username=username).first_or_404() return render_template('user.html', user=user)
def user(username): user = User.query.filter_by(username=username).first_or_404() return render_template('user.html', user=user) # ????profile