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
def tag_archive(tag_filter="all"): archive = Article.archive_statistic(author="cxw") published_article = Article.tag(tag_filter=tag_filter, author="cxw") tags = Article.tag_statistic(author="cxw") return render_template("CxwBlog.html", published_article=published_article, archive=archive, tags=tags)
def cxw_blog(): if request.args.get("article", ""): return redirect( url_for("cxw.cxw_article", uuid=request.args.get("article"))) archive = Article.archive_statistic(author="cxw") tags = Article.tag_statistic(author="cxw") published_article = Article.get_published_article(usr='******') return render_template("CxwBlog.html", published_article=published_article, archive=archive, tags=tags)
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)
def main_edit(): article_for_administration = Article.administration_article(user=current_user.user) if request.args.get("logout") == "True": # Logs a user out. (You do not need to pass the actual user.) # This will also clean up the remember me # bug:AttributeError: 'AnonymousUserMixin' object has no attribute 'user' # By default, when a user is not actually logged in, # current_user is set to an AnonymousUserMixin object. logout_user() return redirect(url_for("main.main_login")) return render_template('ArticleEditor.html', article_for_administration=article_for_administration)
def post(self, uuid): """ :param demands:不用需求场景的代码 :param uuid: 识别文章的唯一代码 :return: """ uuid = request.form.get("uuid", '') demands = request.form.get("demands", '') if demands == "1": # make it JSON serializable rv = list(Article.status_ordered_list(uuid=uuid)) return {"list": rv}, 200
def main_temp_4(): # render template for static file management rv = [] path = ProductionConfig.upload_path() for pic in os.listdir(path): if pic.split('.')[-1] in ProductionConfig.PIC_ALLOW_POSTFIX_WITHOUT_DOT: temp = Article.search_pic_use(t=pic) url = '/'.join([main.static_url_path, "upload", pic]) if temp: rv.append({"No": pic, "url": url, "content": temp}) else: rv.append({"No": pic, "url": url, "content": None}) return render_template("uploaded_files_management_temp.html", rv=rv)
def scc_root(page=1): recent_articles = Article.recent_articles(author='scc') recent_comments = Comment.recent_comments(author='scc') archive = Article.archive_statistic(author="scc") tags = Article.tag_statistic(author="scc") if request.args.get("article", ""): # redirect to article URL if get the ?article=uuid return redirect( url_for("scc.scc_article", uuid=request.args.get("article"))) pagination = Article.pagination(page=int(request.args.get('page', page)), author='scc') latest_10 = Article.latest_article(page=int(request.args.get('page', page)), author='scc') return render_template('SccBlog.html', latest_10=latest_10, pagination=pagination, recent_articles=recent_articles, recent_comments=recent_comments, archive=archive, tags=tags)
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)
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)
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)
def get(self, uuid): rv = Article.article_by_uuid_api(uuid=uuid) return rv
def main_temp_5(): dash = Article.dashboard(author=current_user.user) return render_template("dash_info_temp.html", dash_d=dumps(dash), dash=dash)
def main_temp_1(): # render article information by user article_for_administration = Article.administration_article(user=current_user.user) return render_template("article_info_temp.html", article_for_administration=article_for_administration)
def tag_archive(tag_filter="all"): published_article = Article.tag(tag_filter=tag_filter, author="scc") return render_template("AllArticle.html", archive=published_article)
def archive_all(date_filter): archive = Article.archive(date_filter=date_filter, author="scc") return render_template("AllArticle.html", archive=archive)