Beispiel #1
0
    def POST(self):
        proj = store.Project(id=store.nextid())
        form = web.input()
        proj.image = form.get("image","/static/img/project.jpg")
        proj.name = form.get("title")
        proj.owner = form.get("owner")
        proj.license = form.get("license",'unknow')
        proj.homepage = form.get("homepage")
        proj.tags = form.get("tags",'other')[:255]
        proj.description = form.get("content")
        proj.lang = form.get("lang",'undefined')
        proj.created = store.currtime()

        if not proj.name  or not proj.description:
            return errorpage(u"标题和内容不能为空")

        if not proj.owner:
            return errorpage(u"所有者不能为空")   

        if not proj.homepage:
            return errorpage(u"项目主页不能为空")   

        try:
            proj.save()
            raise web.seeother("/open/",absolute=True)
        except Exception, e:
            return errorpage("add project error %s"%e)
Beispiel #2
0
 def POST(self):
     form = web.input()
     username = form.get("username")
     password = form.get("password")
     if not username or not password:
         return errorpage(u"用户名和密码不能为空") 
     try:
         user = store.login(username,password)
         usession = web.ctx.session
         usession["user"] = user 
         raise web.seeother("/")
     except Exception,e:
         return errorpage("login error %s"%e)
Beispiel #3
0
    def POST(self):
        try:
            comment = store.Comment()
            comment.id = store.nextid()
            user = web.ctx.session.get("user")
            comment.userid = user and user.id or ''  
            form = web.input()
            comment.author = user and user.username or form.get("author")[:64]
            comment.content = form.get("content")
            comment.postid = form.get("postid")
            comment.email = user and user.email or form.get("email")[:128]
            comment.url =  user and user.url or form.get("url")
            comment.ip = web.ctx.ip
            comment.agent =  web.ctx.env.get('HTTP_USER_AGENT')
            comment.status = comment.userid and 1 or 0
            comment.created = store.currtime()

            if not comment.content:
                raise Exception('content not empty')
            if not comment.userid:
                if not comment.author or not comment.email :
                    raise Exception('author email not empty') 
            comment.save()
            store.Comment.commit()
            raise web.seeother("/code/view/%s"%comment.postid,absolute=True)
        except Exception, e:
            import traceback
            traceback.print_exc()
            return errorpage("add comment error %s"%e)    
Beispiel #4
0
    def POST(self):
        user = web.ctx.session.get("user")
        author = user and user.author or 'Anonymous'
        email = user and user.email or '@'
        form = web.input()
        title = form.get("title")
        tags = form.get("tags",'other')
        lang = form.get("lang","undefined")
        content = form.get("content")

        if not title:
            raise 'title can not empty'

        if not content:
            raise 'content can not empty'

        try:
            if tags :tags = tags[:255]
            title = title[:255]
            code = store.Code(
                        id = store.nextid(),
                        title=title,
                        lang=lang,
                        author=author,
                        email=email,
                        tags=tags,
                        content=content,
                        create_time=store.currtime())
            code.save()
            raise web.seeother("/code/",absolute=True)
        except Exception, e:
            return errorpage("add code error %s"%e)
Beispiel #5
0
 def POST(self):
     post = store.Post(id=store.nextid())
     user = web.ctx.session.get("user")
     form = web.input()
     post.codeid = form.get("codeid")
     post.title = form.get("title")
     post.tags = form.get("tags","other")[:255]
     post.content = form.get("content")
     post.userid = user.id
     post.created = post.modified = store.currtime()
     post.status = 0
     if not post.title  or not post.content:
         return errorpage(u"请输入完整数据")
     try:
         post.save()
         raise web.seeother("/news/",absolute=True)
     except Exception, e:
         return errorpage("add post error %s"%e)
Beispiel #6
0
    def POST(self):
        form = web.input()
        username = form.get("username")
        password = form.get("password")
        password2 = form.get("password2")
        email = form.get("email")
        if not username or not password:
            return errorpage(u"用户名和密码不能为空") 
        if not password == password2:
            return errorpage(u"确认密码错误")
        if not email:
            return errorpage(u"电子邮件不能为空")

        try:
            user = store.register(username,password,email)
            usession = web.ctx.session
            usession["user"] = user 
            raise web.seeother("/")
        except Exception,e:
            return errorpage("register error %s"%e)
Beispiel #7
0
 def GET(self,uid):
     web.header("Content-Type","text/html; charset=utf-8")
     page = int(web.input().get("page",1)) 
     offset = (page-1)*pagesize
     try:
         proj = store.Project.get(uid)
         proj.hits += 1
         proj.save()
         comments = store.Comment.where(postid=uid).order_by("created desc")[offset:pagesize]
         return render("project_view.html",
             proj = proj,
             comments=comments,
             page=page)  
     except Exception, e:
         return errorpage("view project error %s"%e)
Beispiel #8
0
 def GET(self,uid):
     web.header("Content-Type","text/html; charset=utf-8")
     try:
         page = int(web.input().get("page",1)) 
         post = store.Post.get(uid)
         post.hits += 1
         post.save()
         tags = store.get_post_tags(30)
         codeid = post.codeid
         code = None
         if codeid:
             code = store.Code.get(codeid)
         comments = store.Comment.where(postid=uid).order_by("created desc")[(page-1)*pagesize:pagesize]
         return render("post_view.html",
             tags=tags,
             post=post,
             comments=comments,
             page=page,
             code=code,
             pagename=post.title)
     except Exception,e:
         return errorpage("error %s"%e)
Beispiel #9
0
 def GET(self,uid):
     try:
         store.Post.get(id=uid).update(status=2)
         raise web.seeother("/news/audit",absolute=True)
     except Exception, e:
         return errorpage("audit error %s"%e)