Пример #1
0
def route_register_view(request):
    user = current_user(request)
    result = request.query.get('result', '')
    result = urllib.parse.unquote_plus(result)
    return html_response('register.html',
                         result=result,
                         username=user.username)
Пример #2
0
    def f(request):
        log('comment_or_weibo_owner_required')
        if request.method == 'GET':
            data = request.query
        elif request.method == 'POST':
            data = request.form()
        else:
            raise ValueError('不支持的方法', request.method)

        comment_key = 'comment_id'
        weibo_key = 'weibo_id'
        if comment_key in data:
            c = Comment.one(id=int(data[comment_key]))
            if c is None:
                return redirect('/weibo/index')
            else:
                user_id = c.user_id
        elif weibo_key in data:
            w = Weibo.one(id=int(data[weibo_key]))
            if w is None:
                return redirect('/weibo/index')
            else:
                user_id = w.user_id
        else:
            raise ValueError('不支持的参数', data)

        u = current_user(request)
        if user_id == u.id:
            log('不是评论或者微博的作者', user_id, u.id)
            return route_function(request)
        else:
            return redirect('/weibo/index')
Пример #3
0
def index(request):
    """
    todo 首页的路由函数
    """
    u = current_user(request)
    todos = Todo.all(user_id=u.id)
    return html_response('todo_index.html', todos=todos)
Пример #4
0
def add(request):
    """
    用于增加新 weibo 的路由函数
    """
    u = current_user(request)
    form = request.form()
    Weibo.add(form, u.id)
    # 浏览器发送数据过来被处理后, 重定向到首页
    # 浏览器在请求新首页的时候, 就能看到新增的数据了
    return redirect('/weibo/index')
Пример #5
0
def add(request):
    """
    用于增加新 todo 的路由函数
    """
    form = request.form()
    u = current_user(request)

    Todo.add(form, u.id)
    # 浏览器发送数据过来被处理后, 重定向到首页
    # 浏览器在请求新首页的时候, 就能看到新增的数据了
    return redirect('/todo/index')
Пример #6
0
def index(request):
    """
    weibo 首页的路由函数
    """
    if 'user_id' in request.query:
        user_id = int(request.query['user_id'])
    else:
        u = current_user(request)
        user_id = u.id
    weibos = Weibo.all(user_id=user_id)
    # 替换模板文件中的标记字符串
    return html_response('weibo_index.html', weibos=weibos)
Пример #7
0
def route_login_view(request):
    """
    登录页面视图
    """

    log('login, headers', request.headers)
    log('login, cookies', request.cookies)
    user = current_user(request)
    log('current user', user)

    result = request.query.get('result', '')
    result = urllib.parse.unquote_plus(result)

    return html_response('login.html', result=result, username=user.username)
Пример #8
0
    def f(request):
        log('comment_owner_required')
        u = current_user(request)
        id_key = 'comment_id'
        if id_key in request.query:
            comment_id = request.query[id_key]
        else:
            comment_id = request.form()[id_key]
        c = Comment.one(id=int(comment_id))

        if c.user_id == u.id:
            log('不是评论作者', c)
            return route_function(request)
        else:
            return redirect('/weibo/index')
Пример #9
0
    def f(request):
        log('weibo_owner_required')
        u = current_user(request)
        id_key = 'weibo_id'
        if id_key in request.query:
            weibo_id = request.query[id_key]
        else:
            weibo_id = request.form()[id_key]
        w = Weibo.one(id=int(weibo_id))

        if w.user_id == u.id:
            log('不是微博作者', w)
            return route_function(request)
        else:
            return redirect('/weibo/index')
Пример #10
0
    def f(request):
        log('same_user_required', route_function)
        u = current_user(request)
        log('same_user_required', request.method)
        if request.method == 'GET':
            todo_id = int(request.query['id'])
        elif request.method == 'POST':
            todo_id = int(request.form()['id'])
        else:
            raise ValueError('不支持的请求方法', request.method)

        t = Todo.one(id=todo_id)
        if t.user_id == u.id:
            return route_function(request)
        else:
            return redirect('/todo')
Пример #11
0
def route_login(request):
    """
    登录页面的路由函数
    """
    log('login, headers', request.headers)
    log('login, cookies', request.cookies)
    user_current = current_user(request)
    log('current user', user_current)

    form = request.form()
    user_login, result = User.login_user(form)
    result = urllib.parse.quote_plus(result)
    if user_login is not None:
        session_id = Session.add(user_login.id)
        headers = {'Set-Cookie': 'session_id={}'.format(session_id)}
    else:
        headers = {}

    # return redirect('/todo')
    return redirect('/login/view', result=result, headers=headers)
Пример #12
0
def comment_add(request):
    u = current_user(request)
    form = request.form()
    weibo_id = int(form['weibo_id'])
    Comment.add(form, u.id, weibo_id)
    return redirect('/weibo/index')
Пример #13
0
def route_index(request):
    """
    主页的处理函数, 返回主页的响应
    """
    u = current_user(request)
    return html_response('index.html', username=u.username)