Add a stable URL for a patch that redirects to latest cf
authorJelte Fennema-Nio <github-tech@jeltef.nl>
Mon, 24 Jun 2024 20:33:42 +0000 (22:33 +0200)
committerMagnus Hagander <magnus@hagander.net>
Fri, 2 Aug 2024 11:46:01 +0000 (13:46 +0200)
Links to patches get outdated ever time we move it to new commitfest.

pgcommitfest/commitfest/views.py
pgcommitfest/urls.py

index 40ae3c544aba34f6f45991b412014e2d52729f67..0dcdb886d7bedda44d866d90e2d2adb62c18a7cb 100644 (file)
@@ -258,6 +258,12 @@ def global_search(request):
         'title': 'Patch search results',
     })
 
+def patch_redirect(request, patchid):
+    last_commitfest = PatchOnCommitFest.objects.select_related('commitfest').filter(patch_id=patchid).order_by('-commitfest__startdate').first()
+    if not last_commitfest:
+        raise Http404("Patch not found")
+    return HttpResponseRedirect(f'/{last_commitfest.commitfest_id}/{patchid}/')
+
 
 def patch(request, cfid, patchid):
     cf = get_object_or_404(CommitFest, pk=cfid)
index 4f6e9d2bc754a3228b7f772a746ba218e4e97448..53fce1c1a7be640a861818080a4506cf1670948a 100644 (file)
@@ -19,6 +19,7 @@ urlpatterns = [
     re_path(r'^(\d+)/$', views.commitfest),
     re_path(r'^(open|inprogress|current)/(.*)$', views.redir),
     re_path(r'^(?P<cfid>\d+)/activity(?P<rss>\.rss)?/$', views.activity),
+    re_path(r'^patch/(\d+)/$', views.patch_redirect),
     re_path(r'^(\d+)/(\d+)/$', views.patch),
     re_path(r'^(\d+)/(\d+)/edit/$', views.patchform),
     re_path(r'^(\d+)/new/$', views.newpatch),