Ajout d'une page d'accueil listant la collection

This commit is contained in:
2017-08-31 15:20:08 +02:00
parent 5ba6193d4b
commit 5867d70111
7 changed files with 96 additions and 19 deletions

View File

@ -0,0 +1,23 @@
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<h1>{% trans "Games" %}</h1>
<h2>{% trans "Now playing" %}</h2>
{% if playing_games %}
<ul>
{% for playing in playing_games%}
<li>{{ playing.name }}</li>
{% endfor %}
</ul>
{% else %}
<p>{% trans "No playing game found." %}</p>
{% endif %}
<h2>{% trans "Complete list" %}</h2>
<ul>
{% for game in non_excluded_games %}
<li>{{ game.name }}</li>
{% endfor %}
</ul>
{% endblock %}

7
collection/games/urls.py Normal file
View File

@ -0,0 +1,7 @@
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'$', views.GameList.as_view()),
]

View File

@ -1,3 +1,21 @@
from django.shortcuts import render
from django.db.models import Q
from django.views.generic import ListView
from django.utils.translation import ugettext as _
# Create your views here.
from .models import Game
class GameList(ListView):
model = Game
context_object_name = 'non_excluded_games'
template_name = 'games/index.html'
queryset = Game.objects.filter(~Q(status=Game.EXCLUDED)).order_by('name')
def get_context_data(self, **kwargs):
"""
Add playing games list
"""
context = super(GameList, self).get_context_data(**kwargs)
context['playing_games'] = Game.objects.filter(
playing=True).order_by('name')
return context