def detail(id): m = Topic.get(id) # 当存在时返回页面,不存在返回主页 if m: # 传递 topic 的所有 reply 到 页面中 return render_template("topic/detail.html", topic=m, user=current_user(), hots=Topic.hots()) else: return redirect(url_for('.index'))
def user_profile(username): # u = User.find_by(username=username) u = User.one(username=username) if u is None: abort(404) else: # topics = Topic.find_all(user_id=u.id) topics = Topic.all(user_id=u.id) reply_topic = Topic.user_participated(u) return render_template('user.html', user=u, reply_topic=reply_topic, topics=topics, hots=Topic.hots(), u=current_user())
def index(): board_id = int(request.args.get('board_id', -1)) hots = Topic.hots() if board_id == -1: ms = Topic.all(deleted=0) else: # ms = Topic.find_all(board_id=board_id) ms = Topic.all(board_id=board_id, deleted=0) token = new_csrf_token() bs = Board.all() user = current_user() return render_template("topic/index.html", ms=ms, token=token, bs=bs, bid=board_id, user=user, hots=hots)
def new(): board_id = int(request.args.get('board_id', -1)) bs = Board.all() # return render_template("topic/new.html", bs=bs, bid=board_id) token = new_csrf_token() return render_template("topic/new.html", bs=bs, token=token, bid=board_id, hots=Topic.hots(), user=current_user())
def index(): u = current_user() sent_mail = Mail.all(sender_id=u.id) received_mail = Mail.all(receiver_id=u.id) t = render_template('mail/index.html', send=sent_mail, received=received_mail, hots=Topic.hots(), user=current_user()) return t
def topics(count=50): fake = Faker() user_count = User.query.count() board_count = Board.query.count() for i in range(count): u = User.query.offset(randint(0, user_count - 1)).first() b = Board.query.offset(randint(0, board_count - 1)).first() p = Topic.new(views=randint(0, 1000), title=fake.text(10), content=fake.text(), board_id=b.id, user_id=u.id) Topic.session.add(p) Topic.session.commit()
def add(): form = request.form.to_dict() u = current_user() form['user_id'] = u.id Topic.new(**form) return redirect(url_for('.index'))
def delete(): id = int(request.args.get('id')) u = current_user() print('删除 topic 用户是', u, id) Topic.delete(id) return redirect(url_for('.index'))