Segment tokens by camps.
This commit is contained in:
parent
96978f4223
commit
707eeb9190
|
@ -1,6 +1,7 @@
|
|||
{% extends 'profile_base.html' %}
|
||||
{% load static from staticfiles %}
|
||||
{% load commonmark %}$
|
||||
{% load token_tags %}
|
||||
|
||||
{% block title %}
|
||||
Your Secret Tokens | {{ block.super }}
|
||||
|
@ -12,44 +13,42 @@ Your Secret Tokens | {{ block.super }}
|
|||
<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>
|
||||
<tbody>
|
||||
{% for token in object_list %}
|
||||
{% ifchanged token.camp %}
|
||||
<tr>
|
||||
<td colspan="4"><h4>{{ token.camp.title }}</h4></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Camp</th>
|
||||
<th>Category</th>
|
||||
<th>Token</th>
|
||||
<th>Description</th>
|
||||
<th>Found</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for tokenfind in object_list %}
|
||||
{% endifchanged %}
|
||||
<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>{{ token.category }}</td>
|
||||
|
||||
{% with token|found_by_user:user as user_has_found_token %}
|
||||
{% if user_has_found_token %}
|
||||
<td>{{ token.token }}</td>
|
||||
<td>{{ token.description }}</td>
|
||||
<td>{{ user_has_found_token }}</td>
|
||||
{% else %}
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
</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 %}
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@ class Token(CampRelatedModel):
|
|||
def __str__(self):
|
||||
return '%s (%s)' % (self.description, self.camp)
|
||||
|
||||
class Meta:
|
||||
ordering = ["camp"]
|
||||
|
||||
|
||||
class TokenFind(CampRelatedModel):
|
||||
class Meta:
|
||||
|
|
0
src/tokens/templatetags/__init__.py
Normal file
0
src/tokens/templatetags/__init__.py
Normal file
15
src/tokens/templatetags/token_tags.py
Normal file
15
src/tokens/templatetags/token_tags.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from django import template
|
||||
|
||||
from tokens.models import TokenFind
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter
|
||||
def found_by_user(token, user):
|
||||
try:
|
||||
tokenfind = TokenFind.objects.get(token=token, user=user)
|
||||
return tokenfind.created
|
||||
except TokenFind.DoesNotExist:
|
||||
return False
|
||||
|
|
@ -20,18 +20,13 @@ class TokenDetailView(LoginRequiredMixin, DetailView):
|
|||
|
||||
|
||||
class TokenFindListView(LoginRequiredMixin, ListView):
|
||||
"""
|
||||
This class is meant to be extended in other apps like `profiles`.
|
||||
"""
|
||||
model = TokenFind
|
||||
model = Token
|
||||
template_name = "tokens/tokenfind_list.html"
|
||||
|
||||
def get_queryset(self):
|
||||
return TokenFind.objects.filter(user=self.request.user)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
# find the tokens the user still needs to find
|
||||
context['unfound_list'] = Token.objects.all().exclude(id__in=TokenFind.objects.filter(user=self.request.user).values_list('token__id', flat=True))
|
||||
tokenfinds = TokenFind.objects.filter(user=self.request.user).values_list('token__id', flat=True)
|
||||
context['unfound_list'] = Token.objects.all().exclude(id__in=tokenfinds)
|
||||
return context
|
||||
|
||||
|
|
Loading…
Reference in a new issue