From c6bf69730cc1acc71612197d25b21943e931fc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Tue, 13 Aug 2019 17:53:13 +0200 Subject: [PATCH] It's an old code, sir, but it checks out. --- src/bornhack/environment_settings.py.dist | 2 ++ src/tokens/templates/token_detail.html | 18 +++++++++++++----- src/tokens/views.py | 17 +++++++++++++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/bornhack/environment_settings.py.dist b/src/bornhack/environment_settings.py.dist index c62434b5..ffd1f715 100644 --- a/src/bornhack/environment_settings.py.dist +++ b/src/bornhack/environment_settings.py.dist @@ -94,3 +94,5 @@ ACCOUNTINGSYSTEM_EMAIL = "{{ django_accountingsystem_email }}" ECONOMYTEAM_EMAIL = "{{ django_economyteam_email }}" ECONOMYTEAM_NAME = "Economy" +BORNHACK_2019_OLD_TOKEN_TOKEN = "{{ bornhack_2019_old_token_token }}" + diff --git a/src/tokens/templates/token_detail.html b/src/tokens/templates/token_detail.html index e4614d1e..39851f0d 100644 --- a/src/tokens/templates/token_detail.html +++ b/src/tokens/templates/token_detail.html @@ -7,10 +7,18 @@ Secret Token Found! | {{ block.super }} {% endblock %} {% block content %} -

Secret Token Found!

-

You found a secret token:

-

{{ token.description }}

-

Your visit has been registered! Keep hunting, there might be more tokens out there.

-

List All Found Tokens

+ +{% if view.older_code %} +

It's an older code, sir, but it checks out!

+

You have tried to use an older token, so here have a token for your efforts!

+
{{ view.older_token_token }}
+{% else %} +

Secret Token Found!

+

You found a secret token:

+

{{ token.description }}

+

Your visit has been registered! Keep hunting, there might be more tokens out there.

+

List All Found Tokens

+{% endif %} + {% endblock %} diff --git a/src/tokens/views.py b/src/tokens/views.py index ea415454..f80da877 100644 --- a/src/tokens/views.py +++ b/src/tokens/views.py @@ -1,6 +1,9 @@ +from django.conf import settings from django.contrib.auth.mixins import LoginRequiredMixin +from django.core.exceptions import ValidationError from django.views.generic import ListView, DetailView +from utils.models import CampReadOnlyModeError from .models import Token, TokenFind @@ -9,13 +12,19 @@ class TokenDetailView(LoginRequiredMixin, DetailView): model = Token slug_field = "token" slug_url_kwarg = "token" + older_code = False 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 - ) - return super().get(request, *args, **kwargs) + try: + token, created = TokenFind.objects.get_or_create( + token=self.get_object(), user=request.user + ) + return super().get(request, *args, **kwargs) + except CampReadOnlyModeError: + self.older_code = True + self.older_token_token = settings.BORNHACK_2019_OLD_TOKEN_TOKEN + return super().get(request, *args, **kwargs) class TokenFindListView(LoginRequiredMixin, ListView):