From 85ae5e3be5609448663f6247371df71716f05244 Mon Sep 17 00:00:00 2001 From: Edward Betts <edward@4angle.com> Date: Tue, 5 Jun 2018 12:05:35 +0100 Subject: [PATCH] Pass xanadoc text to view template. --- sourcing/view.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/sourcing/view.py b/sourcing/view.py index b152562..f69b767 100644 --- a/sourcing/view.py +++ b/sourcing/view.py @@ -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,