From 3669857f3d8c9a4221f56630130567c66618a0a2 Mon Sep 17 00:00:00 2001 From: Shgck Date: Sat, 2 May 2015 14:34:53 +0200 Subject: [PATCH] Links to releases now with "idreXXX" tag and not internal ID --- label/templates/label/releases.html | 4 ++-- label/tools.py | 8 +++++++- label/views.py | 9 ++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/label/templates/label/releases.html b/label/templates/label/releases.html index 08e9d1c..e20c8df 100644 --- a/label/templates/label/releases.html +++ b/label/templates/label/releases.html @@ -14,7 +14,7 @@ {% for release in releases %} - {{ release.ident }} + {{ release.tag }} @@ -24,7 +24,7 @@ - {{ release.title }} + {{ release.title }} {% if release.release_type == 1 %}(EP){% endif %} {% if release.release_type == 2 %}(Split){% endif %} {% if release.release_type == 3 %}(Demo){% endif %} diff --git a/label/tools.py b/label/tools.py index 0444773..40a90b8 100644 --- a/label/tools.py +++ b/label/tools.py @@ -1,6 +1,12 @@ -def get_catalog_tag(ident): +def get_catalog_tag_from_id(ident): return "IDRE{:0>3d}".format(ident) +def get_id_from_catalog_tag(tag): + try: + return int(tag[4:]) + except ValueError: + return -1 + def get_contribs(contributors): contrib_list = [] diff --git a/label/views.py b/label/views.py index bdea82e..6a3328a 100644 --- a/label/views.py +++ b/label/views.py @@ -27,10 +27,12 @@ def releases(request): releases_and_infos = [] for release in releases: + release_tag = tools.get_catalog_tag_from_id(release.ident) releases_and_infos.append({ "id": release.id, "release_type": release.release_type, - "ident": tools.get_catalog_tag(release.ident), + "tag": release_tag, + "tag_lower": release_tag.lower(), "title": release.title, "contribs": tools.get_contribs(release.contributors.all()), "year": release.year @@ -40,8 +42,9 @@ def releases(request): return render(request, "label/releases.html", context) -def release(request, rid): - release = Release.objects.get(id = rid) +def release(request, tag): + ident = tools.get_id_from_catalog_tag(tag) + release = get_object_or_404(Release, ident = ident) contribs = tools.get_contribs(release.contributors.all()) context = { "release": release, "contribs": contribs } return render(request, "label/release.html", context)