def imageDelete(): if request.args.get('path',''): path=util.urlDirPathFormat(request.args.get('path','')) path=util.getAbsDataItemPath(path) if os.path.exists(path): os.remove(path) return jsonify({'status':'ok'})
def post_delete(path): isAdmin=util.checkAdmin() if isAdmin: post=Post.query.filter_by(location=path).first() else: post=Post.query.filter_by(location=path,userId=str(current_user.id)).first() path=util.urlDirPathFormat(path) abspath=util.getAbsPostPath(path) if post or os.path.exists(abspath): if post: log.debug(post.location+post.userId) db.session.delete(post) if os.path.exists(abspath): os.remove(abspath) term=dict(fieldName='location',text=path) try: searchutil.deleteDocument([term]) #db.session.commit() utilpost.delete_post_cache(abspath) flash("删除成功!", "success") except AttributeError as e: flash("发生内部错误 %s" % str(e),'danger') else: flash("文章不存在或无权限编辑!","warning") return render_template('hintInfo.html')
def post_edit(path): path = util.urlDirPathFormat(path) abspath = os.path.join(current_app.config['PAGE_DIR'], path.replace('/', os.sep)) + ".md" if not os.path.exists(abspath): flash("文章不存在", 'warning') return render_template('hintInfo.html') isAdmin = util.checkAdmin() post = Post.query.filter_by(location=path).first() if post and post.userId != str(current_user.id) and (not isAdmin): flash("您没有权限编辑此文章!", 'warning') return render_template('hintInfo.html') if utilpost.isPostLocked(path): flash("文章已被锁定,您暂时无权编辑") return render_template('hintInfo.html') utilpost.createPostLock(path) with open(abspath, encoding='UTF-8') as f: content = f.read() # print('fcontent'+fcontent) # form.content.data=fcontent meta = content.split('\n\n', 1)[0] meta = util.parsePostMeta(meta) # a dict content = content.split('\n\n', 1)[1] tags = '' location = path if post: tags = ','.join([t.name for t in post.tags]) location = post.location fileModifyAt = datetime.fromtimestamp( os.stat(abspath).st_mtime).strftime('%Y-%m-%d %H:%M:%S') form = PostForm(title=meta.get('title', ''), content=content, location=location, tags=tags, createAt=meta.get('createAt', ''), modifyAt=meta.get('modifyAt', ' '), fileModifyAt=fileModifyAt) return render_template('editor.html', isPost=True, action=url_for('.post_save'), form=form)