It's an old code, sir, but it checks out.
This commit is contained in:
parent
1b56280b12
commit
7e0c87957f
|
@ -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 }}"
|
||||
|
||||
|
|
|
@ -7,10 +7,18 @@ Secret Token Found! | {{ block.super }}
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<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>
|
||||
|
||||
{% 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,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):
|
||||
|
|
|
@ -47,6 +47,10 @@ class CreatedUpdatedModel(CleanedModel):
|
|||
updated = models.DateTimeField(auto_now=True)
|
||||
|
||||
|
||||
class CampReadOnlyModeError(ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
class CampRelatedModel(CreatedUpdatedModel):
|
||||
|
||||
camp_filter = "camp"
|
||||
|
@ -58,7 +62,7 @@ class CampRelatedModel(CreatedUpdatedModel):
|
|||
if self.camp.read_only:
|
||||
if hasattr(self, "request"):
|
||||
messages.error(self.request, "Camp is in read only mode.")
|
||||
raise ValidationError("This camp is in read only mode.")
|
||||
raise CampReadOnlyModeError("This camp is in read only mode.")
|
||||
|
||||
super().save(**kwargs)
|
||||
|
||||
|
@ -66,7 +70,7 @@ class CampRelatedModel(CreatedUpdatedModel):
|
|||
if self.camp.read_only:
|
||||
if hasattr(self, "request"):
|
||||
messages.error(self.request, "Camp is in read only mode.")
|
||||
raise ValidationError("This camp is in read only mode.")
|
||||
raise CampReadOnlyModeError("This camp is in read only mode.")
|
||||
|
||||
super().delete(**kwargs)
|
||||
|
||||
|
|
Loading…
Reference in a new issue