Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 96 lines (76 sloc) 2.455 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
# -*- coding: utf-8 -*-

import web
from render import render

from forum.utils import GetSite
from forum.utils import CheckAuth

from forum import Post
from forum.utils.posts import GetPostById
from forum.utils.posts import SetPost
from forum.utils.posts import RemovePost
from forum.utils.posts import UpdatePostClickedTime

class NewPostHandler(object):
    def GET(self):
        site = GetSite()
        user = CheckAuth()
        if not user:
            return web.seeother("/signin")

        mode = 'new'
        post = Post()
        return render.edit_posts(locals())

    def POST(self):
        user = CheckAuth()
        if not user:
            return web.seeother("/signin")

        raw = web.input()
        raw.id = ""
        raw.author = user.Username
        post_id = SetPost(raw)

        return web.seeother("/t/" + str(post_id))

class EditPostHandler(object):
    def GET(self, post_id):
        #TODO 检查是否有权限
        site = GetSite()
        user = CheckAuth()
        if not user:
            return web.seeother("/signin")

        mode = 'edit'
        post = GetPostById(post_id)
        return render.edit_posts(locals())

    def POST(self, post_id):
        user = CheckAuth()
        if not user:
            return web.seeother("/signin")

        raw = web.input()
        raw.id = post_id
        raw.author = user.Username
        post_id = SetPost(raw)

        return web.seeother("/t/" + str(post_id))

class RemovePostHandler(object):
    def GET(self, post_id):
        user = CheckAuth()
        if not user:
            return web.seeother("/signin")
        
        post_id = int(post_id) # 默认是对能删除的post_id进行处理
        RemovePost(post_id)
        return web.seeother("/") #删除成功响应?

class ViewPostHandler(object):
    def GET(self, post_id):
        post_id = int(post_id)
        site = GetSite()

        post = GetPostById(post_id)
        if post:
            UpdatePostClickedTime(post_id)
            return render.posts(locals())
        else:
            raise web.notfound()

class ViewPlainTextPostHandler(object):
    def GET(self, post_id):
        #TODO 更好的模版
        post_id = int(post_id)

        post = GetPostById(post_id)
        if post:
            UpdatePostClickedTime(post_id)
            web.header("Content-Type", "text/plain;charset=utf-8")
            return post.Content
        else:
            raise web.notfound()
Something went wrong with that request. Please try again.