Ejemplo n.º 1
0
def new_post():
    data_from_client = request.json
    post = Post(title = data_from_client['title'],
                content = data_from_client['content'],
                emitDate = data_from_client['emitDate'],
                expireDate = data_from_client['expireDate'])
    post.save()
    
    return _jsonify(200, 'Postagem salva com sucesso!')
Ejemplo n.º 2
0
def add_post():
    print("addpost")
    text = request.form.get("post")
    lec = Lecture.objects.get(id=request.form.get("lec_id"))
    print lec
    p = Post()
    p.content = text
    p.save()
    lec.posts.append(p)
    lec.save()
    posts = lec.posts
    return render("post.html", lec=lec, posts=posts, isUser=True)
Ejemplo n.º 3
0
def post_form(post_id):
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data

        post = Post(user_id=current_user.id,title=title, content=content)
        post.save()
        return redirect(url_for('index'))
    else:
        post = Post.get_by_id(post_id)
        print(post)
        # form.content = post.content
    return render_template("admin/post_form.html", form=form)
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
def lecture(slg):
    lec = Lecture.objects.get(slug=slg)

    if request.args.get("addPost"):
        text = request.form.get("post")
        lec = Lecture.objects.get(id=request.form.get("lec_id"))
        u = User.objects.get(id=request.form.get("user_id"))
        p = Post()
        p.content = text
        print u == is_user()
        p.user = u
        p.save()
        lec.posts.append(p)
        lec.save()
        posts = lec.posts
        return redirect("/lecture/"+slg)

    if len(lec.posts) > 0:
        posts = lec.posts
    else:
        posts = 0
    print posts
    return render("post.html", lec=lec, posts=posts, isUser=True)
Ejemplo n.º 6
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)))