def addArticle(): if not request.json: resultDict = returnNoneMsg("failed!") return jsonify(resultDict) jsonData = request.get_data() dataDict = json.loads(jsonData) article = Article() article.title = dataDict.get('title', None) article.author = dataDict.get('author', None) article.content = dataDict.get('content', None) article.category = dataDict.get('category', None) article.point_num = dataDict.get('point_num', None) article.commont_num = dataDict.get('commont_num', None) article.fav_num = dataDict.get('fav_num', None) article.add_ip = request.remote_addr article.published = True res = article.save() if res: returnId = { 'id': article.meta.id, } resultDict = returnMsg(returnId) return jsonify(resultDict) else: resultDict = returnNoneMsg("add failed!") return jsonify(resultDict)
def articleUploadDo(): id = session.get("id") title = request.form["title"] content = request.form["content"] img = re.compile(pattn).search(content) if img != None: img = img.group(1) if img != None: img_url = img else: img_url = '/static/upload/new.jpg' tag = classify(content) detail_source = session.get('username') time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') art = Article(title=title, content=content, detail_source=detail_source, img_url=img_url, tag=tag, time=time) art.save() return render_template("article_upload_success.html")