Exemple #1
0
def article_editor(uuid):
    if request.args.get("logout") == "true":
        logout_user()
        return redirect(url_for("scc.scc_article", uuid=uuid))

    article_by_uuid = Article.get_article_by_uuid(uuid=uuid, abort=False)
    if request.method == 'POST':
        # update article then redirect to the article url
        # if need to re-edit, just push the back to history button at browser
        db.session.query(Article).filter(Article.uuid == uuid).update({
            "title":
            request.form.get("title"),
            "content":
            request.form.get("content"),
            "edit_date":
            datetime.now(),
            "tags":
            ",".join(request.form.getlist("tag[]"))
        })
        db.session.commit()

        if article_by_uuid.status == "PUBLISHED":
            return redirect(url_for("scc.scc_article", uuid=uuid))
        else:
            return redirect(url_for("main.main_edit"))
    return render_template('ArticleTemplate.html',
                           article_by_uuid=article_by_uuid,
                           scripts=True)
Exemple #2
0
    def put(self, uuid):
        """
        配合ArticleEditor.html页面的ajax PUT请求,进行更新动作。
        若没有uuid,则会进行插入动作,适合页面新增的需求
        若查询到uuid,可以进行部分字段的更新,
        :param uuid: 来自html页面不同需求场景下的值
        :return: {动作信息: http返回代码}
        """
        form = {k: None if v == '' else v for k, v in request.form.items()}
        # receive tags list, transfer list to string
        tags = request.form.getlist("tag[]")
        if tags:
            tags = ','.join(tags)
            form.update({"tags": tags})

        if Article.get_article_by_uuid(uuid=form.get('uuid'), abort=False):
            # article update logical here
            # check the form
            if Article.update_article(form):
                return {'message': 'update success'}, 200
            else:
                return {'message': 'update failed'}, 500
        else:
            try:
                # add new record
                db.session.add(Article(form))
                db.session.commit()
                return {'message': 'add success'}
            except IntegrityError:
                db.session.rollback()
                return {'message': 'add failed'}, 500
Exemple #3
0
def scc_article(uuid):
    if request.args.get('edit') == 'true':
        return redirect(url_for("scc.article_editor", uuid=uuid))
    if request.args.get("logout") == "true":
        logout_user()

    if request.method == "POST":
        db.session.add(
            Comment(uid=uuid,
                    rdr_name=request.form.get("nickname"),
                    rdr_mail=request.form.get("mail-address"),
                    rdr_message=request.form.get("comment-content"),
                    reply_to_id=request.form.get("reply_to_id")))
        db.session.commit()
        return redirect(url_for("scc.scc_article", uuid=uuid))
    article_by_uuid = Article.get_article_by_uuid(uuid=uuid)
    return render_template('ArticleTemplate.html',
                           article_by_uuid=article_by_uuid)
Exemple #4
0
def cxw_article(uuid):
    article = Article.get_article_by_uuid(uuid=uuid)

    if request.args.get("edit") == "true":
        return redirect(url_for("cxw.cxw_article_editor", uuid=uuid))
    if request.args.get("logout") == "true":
        logout_user()
        return redirect(url_for("cxw.cxw_article", uuid=uuid))

    if request.method == "POST":
        db.session.add(
            Comment(uid=uuid,
                    rdr_name=request.form.get("nickname"),
                    rdr_mail=request.form.get("mail-address"),
                    rdr_message=request.form.get("comment-content"),
                    reply_to_id=request.form.get("reply_to_id")))
        db.session.commit()
        return redirect(url_for("cxw.cxw_article", uuid=uuid))
    return render_template("ArticleTemplateTheme_1.html", article=article)
Exemple #5
0
def cxw_article_editor(uuid):
    article = Article.get_article_by_uuid(uuid=uuid, abort=False)

    if request.method == "POST":
        db.session.query(Article).filter(Article.uuid == uuid).update({
            "title":
            request.form.get("title"),
            "content":
            request.form.get("ckeditor"),
            "edit_date":
            datetime.now(),
            "tags":
            ",".join(request.form.getlist("tag[]"))
        })
        db.session.commit()

        if article.status == "PUBLISHED":
            return redirect(url_for("cxw.cxw_article", uuid=uuid))
        else:
            return redirect(url_for("main.main_edit"))
    return render_template("ArticleTemplateTheme_1.html",
                           article=article,
                           edit=True)