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:
parent
06f6f97449
commit
ae55e48df7
|
@ -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 %}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
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 utils.models import CampReadOnlyModeError
|
||||
|
||||
from .models import Token, TokenFind
|
||||
|
||||
|
@ -15,15 +16,15 @@ class TokenDetailView(LoginRequiredMixin, DetailView):
|
|||
|
||||
def get(self, request, *args, **kwargs):
|
||||
# register this tokenview if it isn't already
|
||||
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)
|
||||
if created:
|
||||
messages.success(
|
||||
self.request,
|
||||
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 redirect(reverse("tokens:tokenfind_list"))
|
||||
|
||||
|
||||
class TokenFindListView(LoginRequiredMixin, ListView):
|
||||
|
|
Loading…
Reference in a new issue