fix: template defects
This commit is contained in:
@@ -69,9 +69,10 @@ def create_markdown():
|
||||
content = data.get('content')
|
||||
path_id = data.get('path_id')
|
||||
shortcut = data.get('shortcut', "")
|
||||
setting_id = data.get('setting_id', None)
|
||||
if not title or not content:
|
||||
return jsonify({"error": "missing required fields"}), 400
|
||||
new_markdown = Markdown(title=title, content=content, path_id=path_id, shortcut=shortcut)
|
||||
new_markdown = Markdown(title=title, content=content, path_id=path_id, shortcut=shortcut, setting_id=setting_id)
|
||||
with get_db() as session:
|
||||
try:
|
||||
if shortcut != "":
|
||||
@@ -110,6 +111,7 @@ def update_markdown(markdown_id):
|
||||
markdown.content = data.get('content')
|
||||
markdown.path_id = data.get('path_id')
|
||||
markdown.shortcut = data.get('shortcut', '')
|
||||
markdown.setting_id = data.get('setting_id', None)
|
||||
elif request.method == "PATCH":
|
||||
if 'title' in data:
|
||||
markdown.title = data.get('title')
|
||||
@@ -119,6 +121,8 @@ def update_markdown(markdown_id):
|
||||
markdown.path_id = data.get('path_id')
|
||||
if 'shortcut' in data:
|
||||
markdown.shortcut = data.get('shortcut')
|
||||
if 'setting_id' in data:
|
||||
markdown.setting_id = data.get('setting_id')
|
||||
session.commit()
|
||||
markdown_updated.send(None, payload=markdown.to_dict())
|
||||
return jsonify(markdown.to_dict()), 200
|
||||
|
||||
@@ -45,7 +45,7 @@ def update_markdown_setting(setting_id):
|
||||
setting.template_setting_id = template_setting_id
|
||||
session.commit()
|
||||
return jsonify(setting.to_dict()), 200
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
return jsonify({"error": "failed to update setting"}), 500
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ def create_template_setting():
|
||||
new_setting = MarkdownTemplateSetting(template_id=template_id)
|
||||
with get_db() as session:
|
||||
session.add(new_setting)
|
||||
session.commit()
|
||||
return jsonify(new_setting.to_dict()), 201
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import json
|
||||
from flask import jsonify, request
|
||||
from api import etag_response, require_auth
|
||||
from api.template import template_bp
|
||||
@@ -7,8 +6,7 @@ from db.models.MarkdownTemplate import MarkdownTemplate
|
||||
|
||||
cached_templates = {}
|
||||
def inflate_template(template):
|
||||
template.parameters = json.loads(template.parameters)
|
||||
for parameter in template.parameters:
|
||||
for parameter in template.get('parameters'):
|
||||
if parameter.get('type', {}).get('base_type') == 'template':
|
||||
sub_template_id = parameter.get('type', {}).get('definition', {}).get('template', {}).get('id', 0)
|
||||
if sub_template_id in cached_templates.keys():
|
||||
@@ -17,7 +15,7 @@ def inflate_template(template):
|
||||
with get_db() as session:
|
||||
sub_template = session.query(MarkdownTemplate).get(sub_template_id)
|
||||
parameter['type']['definition']['template'] = inflate_template(sub_template)
|
||||
cached_templates[template.id] = template
|
||||
cached_templates[template['id']] = template
|
||||
return template
|
||||
|
||||
|
||||
@@ -28,6 +26,7 @@ def get_markdown_template(template_id):
|
||||
template = session.query(MarkdownTemplate).get(template_id)
|
||||
if template is None:
|
||||
return jsonify({}), 204
|
||||
print(inflate_template(template.to_dict()))
|
||||
return jsonify(inflate_template(template.to_dict())), 200
|
||||
|
||||
@template_bp.route('/markdown/', methods=['GET'])
|
||||
@@ -52,7 +51,7 @@ def create_markdown_template():
|
||||
with get_db() as session:
|
||||
session.add(template)
|
||||
session.commit()
|
||||
return template.to_dict(), 200
|
||||
return jsonify(template.to_dict()), 200
|
||||
except Exception as e:
|
||||
return jsonify({"error": "failed to create markdown template"}), 400
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
from flask import jsonify
|
||||
|
||||
from api.template import template_bp
|
||||
|
||||
|
||||
@template_bp.route('/markdown/type/', methods=['GET'])
|
||||
def get_types():
|
||||
return jsonify(["template", "text", "string", "list", "enum"]), 200
|
||||
|
||||
Reference in New Issue
Block a user