Example #1
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)
Example #2
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)    
Example #3
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)
Example #4
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)
Example #5
0
 def POST(self):
     forms = web.input()
     code = store.Code(id=store.nextid(),
                   parent=forms.get("pid"),
                   title = forms.get("title"),
                   author = forms.get("author"),
                   email = forms.get("email"),
                   tags = forms.get("tags"),
                   content = forms.get("content"),
                   authkey = forms.get("authkey"),
                   filename = forms.get("filename"),
                   lang=forms.get("lang"),
                   via=forms.get("via"),
                   create_time=store.currtime())
     try:
         code.save()
         store.Code.commit()
         return jsonResult(result="code publish success")
     except:
         return jsonResult(error="code publish fail")
Example #6
0
 def POST(self):
     post = store.Post(id=store.nextid())
     form = web.input()
     post.authkey = form.get("authkey")
     user = store.User.get(authkey=post.authkey)
     post.userid = user.id
     post.codeid = form.get("codeid")
     post.title = form.get("title")
     post.tags = form.get("tags")
     post.content = form.get("content")
     post.via = form.get("via")
     post.created = post.modified = store.currtime()
     if not post.title or not post.content:
         return jsonResult(error="title,content can not empty")
     try:
         post.save()
         store.Post.commit()
         return jsonResult(result="post success")
     except Exception, e:
         return jsonResult(error="post fail %s"%e)
Example #7
0
    def POST(self):
        form = web.input()
        authkey = form.get("authkey")
        user = store.User.get(authkey=authkey)
        userid = user.id      
        postid = form.get("postid")
        print userid,postid
        post = store.Post.get(id=postid,userid=userid)
        if not post :
            return jsonResult(error="you are not the post author")

        post.title = form.get("title")
        post.tags = form.get("tags",'other')
        post.content = form.get("content")
        post.modified = store.currtime()
        if not post.content:
            return jsonResult(error="content can not empty")
        try:
            post.save()
            store.Post.commit()
            return jsonResult(result="update post success")
        except Exception, e:
            return jsonResult(error="update post fail %s"%e)            
Example #8
0
 def GET(self):
     web.header("Content-Type","text/xml; charset=utf-8")
     tops = store.Code.where().order_by("create_time desc")[:100]
     return render("codefeed.html",tops = tops,lastBuildDate=store.currtime())            
Example #9
0
 def GET(self):
     web.header("Content-Type","text/xml; charset=utf-8")
     tops = store.Post.where(status=1).order_by("modified desc")[:50]
     return render("newsfeed.html",tops = tops,lastBuildDate=store.currtime())