def unfollow(username): user = User.query.filter_by(username=username).first_or_404() if not current_user.is_following(user): flash('没有关注的人.', 'info') return redirect(url_for('user.index', username=username)) current_user.unfollow(user) flash('成功取消关注.', 'info') return redirect_back()
def block_user(user_id): user = User.query.get_or_404(user_id) if user.role.name in ['Admin']: flash('不能封禁管理员.', 'warning') else: user.block() flash('账号已封禁.', 'info') return redirect_back()
def follow(username): user = User.query.filter_by(username=username).first_or_404() if current_user.is_following(user): flash('已经关注过.', 'info') return redirect(url_for('user.index', username=username)) current_user.follow(user) flash('恭喜,关注成功.', 'success') push_follow_notification(current_user, user) return redirect_back()
def search(): q = request.args.get('q', '').strip() if q == '': flash('请输入搜索关键字.', 'warning') return redirect_back() sort = request.args.get('sort', 'post') page = request.args.get('page', 1, type=int) per_page = current_app.config['CSDN_SEARCH_PER_PAGE'] if sort == 'user': pagination = User.query.whooshee_search(q).paginate(page, per_page) else: pagination = Post.query.whooshee_search(q).paginate(page, per_page) results = pagination.items return render_template('main/search.html', q=q, pagination=pagination, results=results, sort=sort)
def edit_profile_admin(user_id): user = User.query.get_or_404(user_id) form = EditProfileAdminForm(user=user) if form.validate_on_submit(): with db.auto_commit(): role = Role.query.get(form.role.data) if role.name == 'Locked': user.lock() user.role = role user.username = form.username.data user.name = form.name.data user.bio = form.bio.data user.website = form.website.data user.location = form.location.data flash('Profile updated.', 'success') return redirect_back() form.username.data = user.username form.role.data = user.role_id form.name.data = user.name form.bio.data = user.bio form.website.data = user.website form.location.data = user.location return render_template('admin/edit_profile.html', user=user, form=form)
def unblock_user(user_id): user = User.query.get_or_404(user_id) user.unblock() flash('已经取消用户封禁.', 'info') return redirect_back()
def unlock_user(user_id): user = User.query.get_or_404(user_id) user.unlock() flash('取消锁定.', 'info') return redirect_back()