aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/views/staff/render.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-08-07 15:09:08 +0100
committerGravatar Gareth Coles <[email protected]>2018-08-07 15:09:16 +0100
commitaf54db6c136138c66cf5ca72419989525a0baa5c (patch)
tree8519aeab8d45277c51797c7dc23aacf3b56ed1bb /pysite/views/staff/render.py
parentA wizard is never late, nor is he early. (diff)
Initial project layout for django
Diffstat (limited to 'pysite/views/staff/render.py')
-rw-r--r--pysite/views/staff/render.py62
1 files changed, 0 insertions, 62 deletions
diff --git a/pysite/views/staff/render.py b/pysite/views/staff/render.py
deleted file mode 100644
index 0152e568..00000000
--- a/pysite/views/staff/render.py
+++ /dev/null
@@ -1,62 +0,0 @@
-import re
-
-from docutils.utils import SystemMessage
-from flask import jsonify
-from schema import Schema
-
-from pysite.base_route import APIView
-from pysite.constants import EDITOR_ROLES, ValidationTypes
-from pysite.decorators import api_params, csrf, require_roles
-from pysite.rst import render
-
-SCHEMA = Schema([{
- "data": str
-}])
-
-MESSAGE_REGEX = re.compile(r"<string>:(\d+): \([A-Z]+/\d\) (.*)")
-
-
-class RenderView(APIView):
- path = "/render" # "path" means that it accepts slashes
- name = "render"
-
- @csrf
- @require_roles(*EDITOR_ROLES)
- @api_params(schema=SCHEMA, validation_type=ValidationTypes.json)
- def post(self, data):
- if not len(data):
- return jsonify({"error": "No data!"})
-
- data = data[0]["data"]
- try:
- html = render(data, link_headers=False)["html"]
-
- return jsonify({"data": html})
- except SystemMessage as e:
- lines = str(e)
- data = {
- "error": lines,
- "error_lines": []
- }
-
- if "\n" in lines:
- lines = lines.split("\n")
- else:
- lines = [lines]
-
- for message in lines:
- match = MESSAGE_REGEX.match(message)
-
- if match:
- data["error_lines"].append(
- {
- "row": int(match.group(1)) - 3,
- "column": 0,
- "type": "error",
- "text": match.group(2)
- }
- )
-
- return jsonify(data)
- except Exception as e:
- return jsonify({"error": str(e)})