Add token finds list as something the profiles app decides how to show.

This commit is contained in:
Víðir Valberg Guðmundsson 2019-03-26 13:39:09 +01:00
parent b3a7825b56
commit 50d40eb7df
7 changed files with 75 additions and 60 deletions

View file

@ -69,8 +69,9 @@
{% endif %} {% endif %}
<li><b>Misc.</b></li> <li><b>Misc.</b></li>
<li {% if view.active_menu == "tokens" %}class="active"{% endif %}> {% url 'profiles:tokenfind_list' as tokenfind_list_url %}
<a href="{% url 'tokens:tokenfind_list' %}"> <li {% if request.path == tokenfind_list_url %}class="active"{% endif %}>
<a href="{{ tokenfind_list_url }}">
Secret Tokens Secret Tokens
</a> </a>
</li> </li>

View file

@ -0,0 +1,55 @@
{% extends 'profile_base.html' %}
{% load static from staticfiles %}
{% load commonmark %}$
{% block title %}
Your Secret Tokens | {{ block.super }}
{% endblock %}
{% block profile_content %}
<div class="panel panel-default">
<div class="panel-heading">
<h4>Your Secret Tokens</h4>
</div>
<div class="panel-body">
<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>Category</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.category }}</td>
<td>{{ tokenfind.token.token }}</td>
<td>{{ tokenfind.token.description }}</td>
<td>{{ tokenfind.created }}</td>
</tr>
{% endfor %}
{% for unfound in unfound_list %}
<tr>
<td>{{ unfound.camp.title }}</td>
<td>{{ unfound.category }}</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if not unfound_list %}
<p class="lead">Congratulations! You've found all tokens we have created right now.</p>
{% endif %}
</div>
{% endblock %}

View file

@ -1,10 +1,14 @@
from django.urls import path from django.urls import path
from .views import ProfileDetail, ProfileUpdate from .views import ProfileDetail, ProfileUpdate, ProfileTokenFindsView
app_name = 'profiles' app_name = 'profiles'
urlpatterns = [ urlpatterns = [
path('', ProfileDetail.as_view(), name='detail'), path('', ProfileDetail.as_view(), name='detail'),
path('edit', ProfileUpdate.as_view(), name='update'), path('edit', ProfileUpdate.as_view(), name='update'),
path(
'tokens',
ProfileTokenFindsView.as_view(),
name='tokenfind_list'
),
] ]

View file

@ -3,6 +3,7 @@ from django.views.generic import DetailView, UpdateView
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.contrib import messages from django.contrib import messages
from tokens.views import TokenFindListBaseView
from . import models from . import models
@ -32,3 +33,6 @@ class ProfileUpdate(LoginRequiredMixin, UpdateView):
messages.success(self.request, 'Your profile has been updated.') messages.success(self.request, 'Your profile has been updated.')
return super().form_valid(form, **kwargs) return super().form_valid(form, **kwargs)
class ProfileTokenFindsView(TokenFindListBaseView):
template_name = "tokenfind_list.html"

View file

@ -1,47 +0,0 @@
{% extends 'base.html' %}
{% load static from staticfiles %}
{% load commonmark %}$
{% block title %}
Your Secret Tokens | {{ block.super }}
{% endblock %}
{% block content %}
<h3>Your Secret Tokens</h3>
<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>Category</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.category }}</td>
<td>{{ tokenfind.token.token }}</td>
<td>{{ tokenfind.token.description }}</td>
<td>{{ tokenfind.created }}</td>
</tr>
{% endfor %}
{% for unfound in unfound_list %}
<tr>
<td>{{ unfound.camp.title }}</td>
<td>{{ unfound.category }}</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if not unfound_list %}
<p class="lead">Congratulations! You've found all tokens we have created right now.</p>
{% endif %}
{% endblock %}

View file

@ -1,14 +1,9 @@
from django.urls import path, re_path, include from django.urls import re_path
from .views import TokenDetailView, TokenFindListView from .views import TokenDetailView
app_name = 'tokens' app_name = 'tokens'
urlpatterns = [ urlpatterns = [
path(
'',
TokenFindListView.as_view(),
name='tokenfind_list'
),
re_path( re_path(
'(?P<token>[0-9a-zA-Z\.@]+)/$', '(?P<token>[0-9a-zA-Z\.@]+)/$',
TokenDetailView.as_view(), TokenDetailView.as_view(),

View file

@ -3,6 +3,7 @@ from django.views.generic import ListView, DetailView
from .models import Token, TokenFind from .models import Token, TokenFind
class TokenDetailView(LoginRequiredMixin, DetailView): class TokenDetailView(LoginRequiredMixin, DetailView):
template_name = "token_detail.html" template_name = "token_detail.html"
model = Token model = Token
@ -18,8 +19,10 @@ class TokenDetailView(LoginRequiredMixin, DetailView):
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
class TokenFindListView(LoginRequiredMixin, ListView): class TokenFindListBaseView(LoginRequiredMixin, ListView):
template_name = "tokenfind_list.html" """
This class is meant to be extended in other apps like `profiles`.
"""
model = TokenFind model = TokenFind
def get_queryset(self): def get_queryset(self):