Esempio n. 1
0
    def post(self):
        title = self.get_request("post_title","untitled")
        t = self.get_request("post_content","")
        content = pyUtility.html_purify(t)
        t = self.get_request("post_status","public")
        post_status = getPostStatus(t)
        post_password = self.get_request("post_password","")
        permalink = self.get_request("post_permalink","")

        nextmove = self.get_request("nextmove","")
        if not pyUtility.isPermaLinkLegal(permalink) or permalink =="":
            dic=dict()
            dic['title'] = "Page Add"
            dic['error'] = "Permalink is not legal."
            dic['isAdd'] = True
            dic['data'] = None
            dic['nextmove'] = nextmove
            self.render("page/add_edit.html", **dic)
            return
        # check
        if not Post().isPageSlugUnique(permalink):
            dic=dict()
            dic['title'] = "Page Add"
            dic['error'] = "Permalink has been used."
            dic['isAdd'] = True
            dic['data'] = None
            dic['nextmove'] = nextmove
            self.render("page/add_edit.html", **dic)
            return
        ndata = Post()
        if post_status == 'protect':
            ndata.post_password = pyUtility.md5(post_password)
        ndata.post_title = title
        ndata.post_type = 'page'
        ndata.post_author = self.userID
        ndata.post_content = content
        ndata.permalink = permalink
        ndata.post_status = post_status
        ndata.comment_status = "close"
        if ndata.save()<=0:
            dic=dict()
            dic['title'] = "Page Add"
            dic['error'] = "Post Add Failed!!"
            dic['isAdd'] = True
            dic['data'] = None
            dic['nextmove'] = nextmove
            self.render("page/add_edit.html", **dic)
            return
        if nextmove:
            self.redirect(self.webroot_url(nextmove))
        else:
            self.redirect(self.webroot_url("page/"+permalink))
Esempio n. 2
0
    def post(self):
        title = self.get_request("post_title","untitled")
        content = self.get_request("post_content","")
        content = pyUtility.html_purify(content)
        post_status = self.get_request("post_status","public")
        post_status = getPostStatus(post_status)
        post_password = self.get_request("post_password","")
        post_tags = self.get_request("post-tags","")
        catgory_array = self.get_arguments("post-category","") # array
        comment_status = self.get_request("p_feedback","")
        nextmove = self.get_request("nextmove","")
        if comment_status !="open":
            comment_status ="close"


        ndata = Post()
        if post_status == 'protect':
            ndata.post_password = pyUtility.md5(post_password)
        ndata.post_title = title
        ndata.post_type = 'post'
        ndata.post_author = self.userID
        ndata.post_content = content
        ndata.post_status = post_status
        ndata.comment_status = comment_status
        newID = ndata.save()
        if newID <= 0:
            dic=dict()
            dic['title'] = "Post Add"
            dic['error'] = "Post Add Failed!!"
            dic['isAdd'] = False
            dic['data'] = None
            dic['nextmove'] = nextmove
            self.render("topic/add_edit.html", **dic)
            return

        # add tags and add relations
        tags = post_tags.split(',')
        tags_array=[]
        for tag in tags:
            tag = tag.strip()
            if tag == "":
                continue
            tags_array.append(tag)

        termsIDs = []
        if tags_array:
            TermTaxonomy().insertTags(tags_array)
            tagIDs = TermTaxonomy().getTagIDsByArray(tags_array)
            termsIDs = termsIDs + tagIDs
        if catgory_array:
            termsIDs = termsIDs + catgory_array
        termsIDs = list(set(termsIDs))
        if termsIDs:
            TermRelationships().removeAllByPostID(newID)
            TermRelationships().addPostTermRelations(newID,termsIDs)
            # ReCalculate Count
            TermTaxonomy().calculatePostCountByTermIDs(termsIDs)
        if nextmove:
            self.redirect(self.webroot_url(nextmove))
        else:
            self.redirect(self.webroot_url("topic/show/"+str(newID)))