add secret token game code
This commit is contained in:
parent
eb20b69c0a
commit
016bfdc1a1
|
@ -47,6 +47,7 @@ INSTALLED_APPS = [
|
|||
'backoffice',
|
||||
'events',
|
||||
'rideshare',
|
||||
'tokens',
|
||||
|
||||
'allauth',
|
||||
'allauth.account',
|
||||
|
|
|
@ -70,6 +70,11 @@ urlpatterns = [
|
|||
name='camp_list'
|
||||
),
|
||||
|
||||
path(
|
||||
'token/',
|
||||
include('tokens.urls', namespace='tokens'),
|
||||
),
|
||||
|
||||
# camp redirect views here
|
||||
|
||||
path(
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<a href="{% url 'account_email' %}" class="btn btn-black">
|
||||
Manage emails
|
||||
</a>
|
||||
{% if user.is_authenticated and user.orders.exists %}
|
||||
{% if user.orders.exists %}
|
||||
<a href="{% url 'shop:order_list' %}" class="btn btn-black">
|
||||
Orders
|
||||
</a>
|
||||
|
@ -20,6 +20,9 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<a href="{% url 'tokens:tokenfind_list' %}" class="btn btn-black">
|
||||
Secret Tokens
|
||||
</a>
|
||||
<a href="{% url 'account_logout' %}" class="btn btn-black">
|
||||
Logout
|
||||
</a>
|
||||
|
|
0
src/tokens/__init__.py
Normal file
0
src/tokens/__init__.py
Normal file
16
src/tokens/admin.py
Normal file
16
src/tokens/admin.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from django.contrib import admin
|
||||
from .models import Token, TokenFind
|
||||
|
||||
@admin.register(Token)
|
||||
class InfoCategorydmin(admin.ModelAdmin):
|
||||
list_filter = ['camp',]
|
||||
list_display = ['token', 'description', 'camp']
|
||||
search_fields = ['token', 'description']
|
||||
|
||||
|
||||
@admin.register(TokenFind)
|
||||
class InfoCategorydmin(admin.ModelAdmin):
|
||||
list_filter = ['token__camp', 'user']
|
||||
list_display = ['token', 'user', 'created']
|
||||
search_fields = ['user', 'token']
|
||||
|
5
src/tokens/apps.py
Normal file
5
src/tokens/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class TokensConfig(AppConfig):
|
||||
name = 'tokens'
|
30
src/tokens/migrations/0001_initial.py
Normal file
30
src/tokens/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Generated by Django 2.0.4 on 2018-08-17 16:18
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('camps', '0029_auto_20180815_2018'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Token',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('updated', models.DateTimeField(auto_now=True)),
|
||||
('token', models.CharField(help_text='The secret token', max_length=32)),
|
||||
('description', models.TextField(help_text='The description of the token')),
|
||||
('camp', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='camps.Camp')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
29
src/tokens/migrations/0002_tokenfind.py
Normal file
29
src/tokens/migrations/0002_tokenfind.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Generated by Django 2.0.4 on 2018-08-18 12:51
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('tokens', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='TokenFind',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('updated', models.DateTimeField(auto_now=True)),
|
||||
('token', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='tokens.Token')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
0
src/tokens/migrations/__init__.py
Normal file
0
src/tokens/migrations/__init__.py
Normal file
45
src/tokens/models.py
Normal file
45
src/tokens/models.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
from django.db import models
|
||||
from utils.models import CampRelatedModel
|
||||
|
||||
|
||||
class Token(CampRelatedModel):
|
||||
camp = models.ForeignKey(
|
||||
'camps.Camp',
|
||||
on_delete=models.PROTECT
|
||||
)
|
||||
|
||||
token = models.CharField(
|
||||
max_length=32,
|
||||
help_text="The secret token"
|
||||
)
|
||||
|
||||
description = models.TextField(
|
||||
help_text="The description of the token"
|
||||
)
|
||||
|
||||
camp_filter = 'camp'
|
||||
|
||||
def __str__(self):
|
||||
return '%s (%s)' % (self.description, self.camp)
|
||||
|
||||
|
||||
class TokenFind(CampRelatedModel):
|
||||
token = models.ForeignKey(
|
||||
'tokens.Token',
|
||||
on_delete=models.PROTECT
|
||||
)
|
||||
|
||||
user = models.ForeignKey(
|
||||
'auth.User',
|
||||
on_delete=models.PROTECT,
|
||||
)
|
||||
|
||||
camp_filter = 'token__camp'
|
||||
|
||||
def __str__(self):
|
||||
return '%s found by %s' % (self.token, self.user)
|
||||
|
||||
@property
|
||||
def camp(self):
|
||||
return self.token.camp
|
||||
|
16
src/tokens/templates/token_detail.html
Normal file
16
src/tokens/templates/token_detail.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load static from staticfiles %}
|
||||
{% load commonmark %}$
|
||||
|
||||
{% block title %}
|
||||
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 Tokens</a></p>
|
||||
{% endblock %}
|
||||
|
37
src/tokens/templates/tokenfind_list.html
Normal file
37
src/tokens/templates/tokenfind_list.html
Normal file
|
@ -0,0 +1,37 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load static from staticfiles %}
|
||||
{% load commonmark %}$
|
||||
|
||||
{% block title %}
|
||||
Your Secret Tokens | {{ block.super }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Your Secret Tokens</h3>
|
||||
{% if object_list %}
|
||||
<p class="lead">You have found the following secret tokens in the BornHack Secret Token Game:</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Camp</th>
|
||||
<th>Token</th>
|
||||
<th>Description</th>
|
||||
<th>Found</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for tokenfind in object_list %}
|
||||
<tr>
|
||||
<td>{{ tokenfind.token.camp.title }}</td>
|
||||
<td>{{ tokenfind.token.token }}</td>
|
||||
<td>{{ tokenfind.token.description }}</td>
|
||||
<td>{{ tokenfind.created }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="lead">You haven't found any secret tokens yet. Happy hunting!</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
18
src/tokens/urls.py
Normal file
18
src/tokens/urls.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.urls import path, re_path, include
|
||||
from .views import TokenDetailView, TokenFindListView
|
||||
|
||||
app_name = 'tokens'
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
'',
|
||||
TokenFindListView.as_view(),
|
||||
name='tokenfind_list'
|
||||
),
|
||||
re_path(
|
||||
'(?P<token>[0-9a-zA-Z\.@]+)/$',
|
||||
TokenDetailView.as_view(),
|
||||
name='details'
|
||||
),
|
||||
]
|
||||
|
27
src/tokens/views.py
Normal file
27
src/tokens/views.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import ListView, DetailView
|
||||
|
||||
from .models import Token, TokenFind
|
||||
|
||||
class TokenDetailView(LoginRequiredMixin, DetailView):
|
||||
template_name = "token_detail.html"
|
||||
model = Token
|
||||
slug_field = 'token'
|
||||
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
|
||||
)
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class TokenFindListView(LoginRequiredMixin, ListView):
|
||||
template_name = "tokenfind_list.html"
|
||||
model = TokenFind
|
||||
|
||||
def get_queryset(self):
|
||||
return TokenFind.objects.filter(user=self.request.user)
|
||||
|
Loading…
Reference in a new issue