From 9e576b9f499706e3218e53686edce5b8a2e801c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Thu, 19 Aug 2021 10:21:38 +0200 Subject: [PATCH] Return 404 for old tokens. --- src/tokens/views.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/tokens/views.py b/src/tokens/views.py index 113f5d21..8a176959 100644 --- a/src/tokens/views.py +++ b/src/tokens/views.py @@ -1,9 +1,11 @@ from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin +from django.http import Http404 from django.shortcuts import redirect from django.urls import reverse from django.views.generic import DetailView, ListView +from ..utils.models import CampReadOnlyModeError from .models import Token, TokenFind @@ -13,10 +15,14 @@ class TokenFindView(LoginRequiredMixin, DetailView): slug_url_kwarg = "token" def get(self, request, *args, **kwargs): - # register this tokenview if it isn't already - token, created = TokenFind.objects.get_or_create( - token=self.get_object(), user=request.user - ) + # register this token find if it isn't already + try: + token, created = TokenFind.objects.get_or_create( + token=self.get_object(), user=request.user + ) + except CampReadOnlyModeError: + raise Http404 + if created: messages.success( self.request,