コード例 #1
0
ファイル: codeapp.py プロジェクト: jamiesun/talkincode
    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)
コード例 #2
0
ファイル: codeapp.py プロジェクト: jamiesun/talkincode
    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)    
コード例 #3
0
ファイル: opensapp.py プロジェクト: jamiesun/talkincode
    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)
コード例 #4
0
ファイル: newsapp.py プロジェクト: jamiesun/talkincode
 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)
コード例 #5
0
ファイル: apiapp.py プロジェクト: jamiesun/talkincode
 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")
コード例 #6
0
ファイル: apiapp.py プロジェクト: jamiesun/talkincode
 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)
コード例 #7
0
ファイル: apiapp.py プロジェクト: jamiesun/talkincode
 def POST(self):
     try:
         comment = store.Comment(id=store.nextid())
         form = web.input()
         authkey = form.get("authkey")
         user = store.User.get(authkey=authkey)
         comment.userid = user.id
         comment.author = user.username
         comment.content = form.get("content")
         comment.postid = form.get("postid")
         comment.via=form.get("via")
         comment.email = user.email
         comment.url = user.url
         comment.ip = web.ctx.ip
         comment.agent =  web.ctx.env.get('HTTP_USER_AGENT')
         comment.status = 1
         if not comment.content:
             return jsonResult(error="content can not empty")
         comment.save()
         store.Comment.commit()
         return jsonResult(result="post comment success")
     except Exception, e:
         return jsonResult(error="add comment error %s"%e)