def index(request): """ todo 首页的路由函数 """ u = current_user(request) key = 'completed' if key in request.query: # 只能手动判断,因为 bool(str(False)) == True if request.query[key] == 'true': index_completed = True else: index_completed = False todos = Todo.all(user_id=u.id, completed=index_completed) if index_completed: active_index = 'completed' else: active_index = 'uncompleted' else: todos = Todo.all(user_id=u.id) active_index = 'index' log('todo index', active_index) uncompleted = len(Todo.all(completed=False)) return html_response('todo_index.html', todos=todos, active_index=active_index, uncompleted=uncompleted)
def route_register_view(request): user = current_user(request) result = request.query.get('result', '') result = unquote_plus(result) return html_response('register.html', result=result, username=user.username)
def add(request): """ 用于增加新 todo 的路由函数 """ form = request.form() u = current_user(request) Todo.add(form, u.id) return redirect('/todo')
def comment_add(request): """ 用于增加新 todo 的路由函数 """ form = request.form() u = current_user(request) Comment.add(u.id, form) return redirect('/weibo')
def follow(request): followed_id = int(request.query['user_id']) follower_id = current_user(request).id form = dict( follower_id=follower_id, followed_id=followed_id, ) Follow.new(form) return redirect('/weibo')
def route_login_view(request): """ 登录页面的路由函数 """ user_current = current_user(request) result = request.query.get('result', '') result = unquote_plus(result) return html_response('login.html', result=result, username=user_current.username)
def f(request): u = current_user(request) if request.method == 'GET': comment_id = int(request.query.get('comment_id')) else: comment_id = int(request.form['comment_id']) comment = Comment.one(id=comment_id) if u.id == comment.user_id: return route_function(request) else: return redirect('/weibo')
def index(request): """ todo 首页的路由函数 """ if 'user_id' in request.query: user_id = int(request.query['user_id']) user = User.one(id=user_id) else: user = current_user(request) weibos = Weibo.all(user_id=user.id) return html_response('weibo_index.html', weibos=weibos, user=user)
def f(request): u = current_user(request) if request.method == 'GET': weibo_id = int(request.query.get('weibo_id')) else: weibo_id = int(request.form['weibo_id']) weibo = Weibo.one(id=weibo_id) if u.id == weibo.user_id: return route_function(request) else: return redirect('/weibo')
def f(request): u = current_user(request) if request.method == 'GET': user_id = u.id comment_id = int(request.query.get('comment_id', '')) else: user_id = u.id comment_id = int(request.form.get('comment_id', '')) comment = Comment.one(id=comment_id) weibo = Weibo.one(id=comment.weibo_id) if comment.user_id == user_id or weibo.user_id == u.id: return route_function(request) else: return redirect('/weibo')
def ajax_all(request): u = current_user(request) todos = Todo.all(user_id=u.id) todos = [t.__dict__ for t in todos] return json_response(todos)
def feed(request): user = current_user(request) weibos = Weibo.feed(user) return html_response('weibo_feed.html', weibos=weibos, user=user)