Unbreak token submission (breakage caused by adding get_absolute_url to Token model), change it so we show a message and redirect back when a token is first found. Remove old token stuff.

This commit is contained in:
Thomas Steen Rasmussen 2020-08-17 17:02:18 +02:00
parent 06f6f97449
commit ae55e48df7
2 changed files with 11 additions and 34 deletions

View file

@ -1,24 +0,0 @@
{% extends 'base.html' %}
{% load static %}
{% load commonmark %}$
{% block title %}
Secret Token Found! | {{ block.super }}
{% endblock %}
{% block content %}
{% if view.older_code %}
<h3 class="text-center">It's an older code, sir, but it checks out!</h3>
<p class="lead text-center">You have tried to use an older token, so here have a token for your efforts!</p>
<pre class="lead text-center">{{ view.older_token_token }}</pre>
{% else %}
<h3 class="text-center">Secret Token Found!</h3>
<p class="lead text-center">You found a secret token:</p>
<p class="lead text-center"><span class="badge">{{ token.description }}</span></p>
<p class="lead text-center">Your visit has been registered! Keep hunting, there might be more tokens out there.</p>
<p class="lead text-center"><a href="{% url 'tokens:tokenfind_list' %}">List All Found Tokens</a></p>
{% endif %}
{% endblock %}

View file

@ -1,7 +1,8 @@
from django.conf import settings from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
from utils.models import CampReadOnlyModeError
from .models import Token, TokenFind from .models import Token, TokenFind
@ -15,15 +16,15 @@ class TokenDetailView(LoginRequiredMixin, DetailView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
# register this tokenview if it isn't already # register this tokenview if it isn't already
try:
token, created = TokenFind.objects.get_or_create( token, created = TokenFind.objects.get_or_create(
token=self.get_object(), user=request.user token=self.get_object(), user=request.user
) )
return super().get(request, *args, **kwargs) if created:
except CampReadOnlyModeError: messages.success(
self.older_code = True self.request,
self.older_token_token = settings.BORNHACK_2019_OLD_TOKEN_TOKEN f"You found a secret token: {self.get_object().description} - Your visit has been registered! Keep hunting, there might be more tokens out there.",
return super().get(request, *args, **kwargs) )
return redirect(reverse("tokens:tokenfind_list"))
class TokenFindListView(LoginRequiredMixin, ListView): class TokenFindListView(LoginRequiredMixin, ListView):