Fix needing a url change when id is changed
This commit is contained in:
parent
2605aa05a1
commit
e5ea4f871c
@ -85,19 +85,23 @@ def edit(document_id):
|
||||
|
||||
doc_path = safe_join(current_app.config['root'], f'{document_id}.json')
|
||||
|
||||
# Load the document to edit
|
||||
if not os.path.isfile(doc_path):
|
||||
return abort(404)
|
||||
with open(doc_path) as f:
|
||||
doc: Document = load(f)
|
||||
|
||||
# Check for content updates
|
||||
if request.method == 'POST':
|
||||
sent_json = request.json
|
||||
new_doc: Document = parse_document_from_json(sent_json)
|
||||
with open(doc_path, 'w') as f:
|
||||
dump(new_doc, f)
|
||||
return {}
|
||||
|
||||
# Load the document to edit
|
||||
if not os.path.isfile(doc_path):
|
||||
return abort(404)
|
||||
with open(doc_path) as f:
|
||||
doc: Document = load(f)
|
||||
new_id = new_doc.get_tag_value('id')
|
||||
if document_id != new_id:
|
||||
new_path = safe_join(current_app.config['root'], f'{new_id}.json')
|
||||
os.rename(doc_path, new_path)
|
||||
return { 'href': url_for('edit', document_id=new_id) }
|
||||
|
||||
# Check for structural updates
|
||||
if add := request.args.get('add'):
|
||||
|
@ -121,7 +121,7 @@ function save() {
|
||||
req.responseType = "json";
|
||||
req.onreadystatechange = function () {
|
||||
if (req.readyState == 4 && req.status == 200) {
|
||||
window.location.reload();
|
||||
window.location.href = req.response.href;
|
||||
}
|
||||
};
|
||||
req.send(JSON.stringify(doc));
|
||||
|
Loading…
Reference in New Issue
Block a user