sphinx-web/src/web/admin/admin_document.py

42 lines
1.3 KiB
Python

import os
from flask import Blueprint, render_template, redirect, url_for, request, session
from web_utils.get_arg import get_arg
from data.document import Document
bp = Blueprint('admin_document', __name__, url_prefix='/admin/doc')
@bp.route('/new', methods=['GET', 'POST'])
def new():
if request.method == 'POST':
repo = request.form.get('repo')
doc_name = request.form.get('doc')
branch = request.form.get('branch')
source_dir = request.form.get('source')
if doc_name == "":
doc_name = os.path.splitext(os.path.basename(repo))[0]
output = Document.clone(repo, branch, doc_name, source_dir)
return render_template("admin/command_output.html", output = output, next = url_for('admin_document.manage', doc_name = doc_name, branch = branch))
else:
return render_template("admin/document/new.html")
@bp.route('/manage/<doc_name>/<branch>')
def manage(doc_name, branch):
return render_template("admin/document/manage.html", doc=Document(doc_name, branch))
@bp.route('/delete/<doc_name>/<branch>')
def delete(doc_name, branch):
doc = Document(doc_name, branch)
doc.delete()
return redirect(url_for('admin.index'), code=302)
@bp.route('/delete_invalid/<doc_name>/<branch>')
def delete_invalid(doc_name, branch):
doc = Document(doc_name, branch, allow_invalid = True)
doc.delete_folder()
return redirect(url_for('admin.index'), code=302)