From ee2d30239640fef34a9222d8502900a5a66fc3c0 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 9 Apr 2017 14:15:35 +0100 Subject: [PATCH] fix up version numbers --- sourcing/model.py | 2 +- sourcing/templates/history.html | 2 +- sourcing/view.py | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/sourcing/model.py b/sourcing/model.py index 0a3cb35..8ff3ec4 100644 --- a/sourcing/model.py +++ b/sourcing/model.py @@ -162,7 +162,7 @@ class Item(TimeStampedModel): return url_for('.view_item', username=self.user.username, hashid=self.hashid, - v=version.transaction_id) + v=version) @property def history_url(self): diff --git a/sourcing/templates/history.html b/sourcing/templates/history.html index b4cfe05..3e5bf75 100644 --- a/sourcing/templates/history.html +++ b/sourcing/templates/history.html @@ -28,7 +28,7 @@ diff --git a/sourcing/view.py b/sourcing/view.py index 5d25746..1b16e79 100644 --- a/sourcing/view.py +++ b/sourcing/view.py @@ -213,11 +213,14 @@ def view_item(username, hashid, raw=False): if raw: return Response(item.text, mimetype='text/plain') - if 'v' in request.args and request.args['v'].isdigit(): - ItemVersion = version_class(Item) - version = (session.query(ItemVersion) - .filter_by(transaction_id=int(request.args['v'])) - .first()) + v = request.args.get('v') + if v: + if not v.isdigit(): + abort(404) + try: + version = item.versions[int(v) - 1] + except IndexError: + abort(404) text = version.text else: version = None