Example #1
0
    def post(self, id):
        title = self.get_request("post_title","untitled")
        content = self.get_request("post_content","")
        post_status = self.get_request("post_status","public")
        post_status = getPostStatus(post_status)
        post_password = self.get_request("post_password","")
        post_delete = self.get_int_request("p_delete",0)
        content = pyUtility.html_purify(content)
        permalink = self.get_request("post_permalink","")

        nextmove = self.get_request("nextmove","")

        if not pyUtility.isPermaLinkLegal(permalink) or permalink =="":
            dic=dict()
            dic['title'] = "Page Edit"
            dic['error'] = "Permalink is not legal."
            dic['isAdd'] = False
            dic['data'] = None
            dic['nextmove'] = nextmove
            self.render("page/add_edit.html", **dic)
            return

        user = self.get_current_user()
        r = None
        dic = dict()
        if id !=0:
            if (user['role'] == pyEnum.AccountRole.Admin or user['role'] == pyEnum.AccountRole.Manager):
                r=Post().getByPageID(id, 0, True, False)
            else:
                r=Post().getByPostID(id, user['ID'], False)
        if r == None:
            dic['title'] = "Page Edit"
            dic['error'] = "The record can not be found or you don't have permission to edit it."
            dic['isAdd'] = False
            dic['data'] = None
            dic['nextmove'] = nextmove
            self.render("page/add_edit.html", **dic)
            return

        if post_status == 'protect':
            r.post_password = pyUtility.md5(post_password)

        r.post_title = title
        r.post_content = content
        r.post_status = post_status
        r.post_modified = str(datetime.datetime.now())
        r.deleted = post_delete
        r.permalink = permalink
        if not r.update():
            dic['error'] = "Page Edit Failed!!"
            dic['isAdd'] = False
            dic['data'] = None
            dic['nextmove'] = nextmove
            self.render("topic/add_edit.html", **dic)
            return
        if nextmove:
            self.redirect(self.webroot_url(nextmove))
        else:
            self.redirect(self.webroot_url("page/"+permalink))
Example #2
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))
Example #3
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)))