def post(cls): data = _user_parser.parse_args() if ArticleModel.find_by_topic(data['topic']): return {'message': "文章名称 '{}' 已存在。".format(data['topic'])}, 400 store = ArticleModel( data['topic'], data['picture_url'] if data['picture_url'] is not None else 'images/pic01.jpg', data['article_url'], data['introduce'], data['link_project'], data['weight']) try: store.save_to_db() except: return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500 return {"message": "新建文章纲要成功!"}, 201
def post(cls): '''上传md数据,并进行转档,转化为html''' data = _user_parser.parse_args() article = ArticleModel.find_by_id(data['id']) if article: if ContentModel.find_by_id(data['id']): return { 'message': "文章ID '{}' 详细资料已存在,如需更新请使用put请求。".format(data['id']) }, 400 else: my_content = ContentModel(data['id'], data['content_md'], '') main_parse.exe_mdToHTML(my_content) try: my_content.save_to_db(article) return { "my_content": my_content.json(), "message": "更新/新增项目状态成功!" }, 201 except: return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500 else: return { 'message': "文章ID '{}' 不存在,请优先新建文章。".format(data['id']) }, 400
def put(cls): '''更新或新增md数据并转化''' data = _user_parser.parse_args() article = ArticleModel.find_by_id(data['id']) if article: my_content = ContentModel.find_by_id(data['id']) if my_content: my_content.content_md = data['content_md'] else: my_content = ContentModel(data['id'], data['content_md'], '') main_parse.exe_mdToHTML(my_content) try: my_content.save_to_db(article) except: return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500 else: return { 'message': "文章ID '{}' 不存在,请优先新建文章。".format(data['id']) }, 400 return { "my_content": my_content.json(), "message": "更新/新增项目状态成功!" }, 201
def post(cls): data = _user_parser.parse_args() if ProjectModel.find_by_name(data['name']): return {'message': "项目名称 '{}' 已存在。".format(data['name'])}, 400 store = ProjectModel( data['name'], data['icon'] if data['icon'] is not None else 'fa-newspaper-o', data['introduce'], data['article_url'], data['weight']) try: store.save_to_db() ArticleModel.insert_link_article(store) except: return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500 return {"message": "新建项目成功!"}, 201
def index(): return render_template( 'index.html', now_time=main_parse.welcome_home(), projects=ProjectModel.get_all_projects_bydict(), articles=ArticleModel.get_all_acricles_bydict(), sidebar_project=ProjectModel.get_all_projects_bytree())
def put(cls): data = _user_parser.parse_args() store = ArticleModel.find_by_topic(data['topic']) if store: if store.link_project == data['link_project']: store.picture_url = data['picture_url'] if data[ 'picture_url'] is not None else 'images/pic01.jpg' store.introduce = data['introduce'] if data[ 'introduce'] is not None else store.introduce store.article_url = data['article_url'] if data[ 'article_url'] is not None else store.article_url store.weight = data['weight'] if data[ 'weight'] is not None else store.weight else: return {"message": "禁止修改对应的专题链接。"}, 400 else: store = ArticleModel( data['topic'], data['picture_url'] if data['picture_url'] is not None else 'images/pic01.jpg', data['article_url'], data['introduce'], data['link_project'], data['weight']) try: store.save_to_db() except: return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500 return {"store": store.json(), "message": "更新/新增项目状态成功!"}, 201
def query_item(whereitem, wherestr): sidebar_article = ArticleModel.get_all_acricles_bytree(whereitem, wherestr) sidebar_feature = FeatureModel.get_all_feature_bytree(whereitem, wherestr) count_article = sum(len(link['link_articles']) for link in sidebar_article) count_feature = sum(len(link['link_features']) for link in sidebar_feature) print(sidebar_article, sidebar_feature) return render_template( 'elements.html', whereitem=main_parse.querystr(whereitem, wherestr), sidebar_article=sidebar_article, sidebar_feature=sidebar_feature, count_article=count_article, count_feature=count_feature, sidebar_project=ProjectModel.get_all_projects_bytree())
def put(cls): data = _user_parser.parse_args() store = ProjectModel.find_by_name(data['name']) if store: store.icon = data['icon'] if data[ 'icon'] is not None else store.icon store.introduce = data['introduce'] if data[ 'introduce'] is not None else store.introduce store.article_url = data['article_url'] if data[ 'article_url'] is not None else store.article_url store.weight = data['weight'] if data[ 'weight'] is not None else store.weight else: store = ProjectModel( data['name'], data['icon'] if data['icon'] is not None else 'fa-newspaper-o', data['introduce'], data['article_url'], data['weight']) try: store.save_to_db() ArticleModel.insert_link_article(store) except: return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500 return {"store": store.json(), "message": "更新/新增项目状态成功!"}, 201
def articles(topic): article = ArticleModel.find_by_id(topic) if article: project = ProjectModel.find_by_id(article.link_project) articles_list = project.get_all_article(None) content = ContentModel.find_by_id(article.id) if content: article_content = content.content_HTML else: article_content = None else: abort(404) return render_template( 'generic.html', article_id=topic, articles={ "articles_len": len(articles_list['articles']), "articles": articles_list['articles'], "article_content": article_content, "article_name": article.topic }, sidebar_project=ProjectModel.get_all_projects_bytree())
def template_test(): article_objects = ArticleModel.retrieve() random.shuffle(article_objects) return render_template('template.html', objects=article_objects)
def template_pub(publisher): article_objects = ArticleModel.retrieve(pid=publisher) random.shuffle(article_objects) return render_template('template.html', objects=article_objects)