Pass xanadoc text to view template.

This commit is contained in:
Edward Betts 2018-06-05 12:05:35 +01:00
parent 2eabe72776
commit 85ae5e3be5

View file

@ -115,7 +115,7 @@ def reset_with_token(token):
ts = URLSafeTimedSerializer(current_app.config["SECRET_KEY"])
try:
user_id = ts.loads(token, salt='password-reset', max_age=86400)
except:
except Exception:
abort(404)
form = PasswordForm()
@ -192,6 +192,12 @@ def get_source_doc(username, hashid):
doc = None
return doc if doc else abort(404)
def get_xanadoc(username, hashid):
doc = Item.get_by_hashid(hashid)
if doc and doc.user.username != username:
doc = None
return doc if doc and doc.type == 'xanadoc' else abort(404)
def get_item(username, hashid):
doc = Item.get_by_hashid(hashid)
if doc and doc.user.username != username:
@ -200,9 +206,7 @@ def get_item(username, hashid):
@bp.route('/<username>/<hashid>/edl')
def view_edl(username, hashid):
item = get_item(username, hashid)
if item.type != 'xanadoc':
return abort(404)
item = get_xanadoc(username, hashid)
return render_template('view.html',
doc=item,
@ -211,9 +215,7 @@ def view_edl(username, hashid):
@bp.route('/<username>/<hashid>/realize')
def realize_edl(username, hashid):
item = get_item(username, hashid)
if item.type != 'xanadoc':
return abort(404)
item = get_xanadoc(username, hashid)
spans = list(fulfil_edl(item.text))
@ -231,9 +233,8 @@ def view_item_raw(username, hashid):
@bp.route('/<username>/<hashid>/fulfil')
def fulfil(username, hashid):
item = get_item(username, hashid)
if item.type != 'xanadoc':
return abort(404)
item = get_xanadoc(username, hashid)
return render_template('view/xanadoc.html',
item=item,
doc=fulfil_edl_with_sources(item.text))
@ -273,8 +274,15 @@ def view_item(username, hashid, raw=False):
version = None
text = item.text
if item.type == 'xanadoc':
spans = list(fulfil_edl(item.text))
doc_text = ''.join(span['text'] for span in spans)
else:
doc_text = None
return render_template('view.html',
doc=item,
doc_text=doc_text,
version=version,
text=text,
span_start=start,