Page d'accueil des jeux vidéos : regroupement par date pour les timelines
Timelines : * regroupement par date sur la page d'accueil des jeux vidéos * ajout de 4 tests concernant cette page * changement du champ 'date' des Timeline par un 'DateField' (au lieu d'un DateTimeField)
This commit is contained in:
parent
88ceb57a09
commit
c3491b7975
@ -1,6 +1,6 @@
|
|||||||
Current version (0.2) :
|
Current version (0.2) :
|
||||||
|
|
||||||
- Ajout d'une page d'accueil listant les jeux vidéos en cours, la liste complète et les dernières activités sur ces derniers
|
- Ajout d'une page d'accueil listant les jeux vidéos en cours, la liste complète et les 5 dernières activités sur ces derniers triées par date
|
||||||
- Nouveau champ 'note' pour la progression dans le jeu
|
- Nouveau champ 'note' pour la progression dans le jeu
|
||||||
- Omission de l'état "Nouveau" pour les jeux
|
- Omission de l'état "Nouveau" pour les jeux
|
||||||
- Traduction de l'interface en Français
|
- Traduction de l'interface en Français
|
||||||
|
@ -62,7 +62,7 @@ class Timeline(models.Model):
|
|||||||
TARGET_VERBOSE_NAME = None
|
TARGET_VERBOSE_NAME = None
|
||||||
STATUS_CHOICES = Item.STATUS_CHOICES
|
STATUS_CHOICES = Item.STATUS_CHOICES
|
||||||
DEFAULT_CHOICE = Item.CREATED
|
DEFAULT_CHOICE = Item.CREATED
|
||||||
date = models.DateTimeField(default=datetime.now, verbose_name=_('date'))
|
date = models.DateField(default=datetime.now, verbose_name=_('date'))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def on_class_prepared(cls):
|
def on_class_prepared(cls):
|
||||||
|
21
collection/games/migrations/0006_auto_20170901_2041.py
Normal file
21
collection/games/migrations/0006_auto_20170901_2041.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.4 on 2017-09-01 20:41
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('games', '0005_auto_20170831_1211'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='timeline',
|
||||||
|
name='date',
|
||||||
|
field=models.DateField(default=datetime.datetime.now, verbose_name='date'),
|
||||||
|
),
|
||||||
|
]
|
@ -26,14 +26,19 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<h2>{% trans "Memory Card" %}</h2>
|
<h2>{% trans "Memory Card" %}</h2>
|
||||||
{% if last_timelines %}
|
{% if last_timelines %}
|
||||||
|
{% regroup last_timelines by date as dates %}
|
||||||
|
{% for date in dates %}
|
||||||
|
<p><u>{{ date.grouper }} : </u>
|
||||||
<ul>
|
<ul>
|
||||||
{% for timeline in last_timelines %}
|
{% for timeline in date.list|dictsortreversed:"id" %}
|
||||||
<li>{{ timeline.date|date:"SHORT_DATE_FORMAT" }} -
|
<li>
|
||||||
<strong>{{ timeline.get_status_display }} :</strong> {{ timeline.item.name }}
|
<strong>{{ timeline.get_status_display }} :</strong> {{ timeline.item.name }}
|
||||||
({{ timeline.item.collection.name }})
|
({{ timeline.item.collection.name }})
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>{% trans "Empty memory." %}</p>
|
<p>{% trans "Empty memory." %}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -10,11 +10,20 @@ class GameTest(TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.console = Console.objects.create(name='BestConsole4Ever')
|
self.console = Console.objects.create(name='BestConsole4Ever')
|
||||||
Game.objects.create(
|
Game.objects.create(
|
||||||
name='Deponia', playing=False, collection=self.console)
|
name='Deponia',
|
||||||
|
playing=True,
|
||||||
|
collection=self.console,
|
||||||
|
status=Game.EXCLUDED)
|
||||||
Game.objects.create(
|
Game.objects.create(
|
||||||
name='Aladdin', playing=True, collection=self.console)
|
name='Aladdin', playing=True, collection=self.console)
|
||||||
Game.objects.create(
|
Game.objects.create(
|
||||||
name='Persona 5', playing=True, collection=self.console)
|
name='Persona 5', playing=True, collection=self.console)
|
||||||
|
Game.objects.create(
|
||||||
|
name='The Witcher III',
|
||||||
|
playing=False,
|
||||||
|
collection=self.console,
|
||||||
|
wish=True)
|
||||||
|
self.index_url = '/games/'
|
||||||
|
|
||||||
|
|
||||||
def test_game_are_sorted_by_playing_and_name(self):
|
def test_game_are_sorted_by_playing_and_name(self):
|
||||||
@ -26,3 +35,48 @@ class GameTest(TestCase):
|
|||||||
sorted_games = list(Game.objects.all().order_by(
|
sorted_games = list(Game.objects.all().order_by(
|
||||||
'-playing', 'name').values_list('name', flat=True))
|
'-playing', 'name').values_list('name', flat=True))
|
||||||
self.assertEqual(games, sorted_games)
|
self.assertEqual(games, sorted_games)
|
||||||
|
|
||||||
|
def test_index(self):
|
||||||
|
"""
|
||||||
|
Context gives 'playing_games'.
|
||||||
|
Context gives 'last_timelines'.
|
||||||
|
"""
|
||||||
|
res = self.client.get(self.index_url)
|
||||||
|
self.assertEqual(res.status_code, 200)
|
||||||
|
self.assertTrue('playing_games' in res.context)
|
||||||
|
self.assertTrue('last_timelines' in res.context)
|
||||||
|
self.assertTrue('object_list' in res.context)
|
||||||
|
|
||||||
|
def test_index_queryset(self):
|
||||||
|
"""
|
||||||
|
Queryset excludes wishlist games.
|
||||||
|
Queryset excludes games that have status EXCLUDED.
|
||||||
|
Queryset is sorted by name.
|
||||||
|
"""
|
||||||
|
res = self.client.get(self.index_url)
|
||||||
|
games = res.context.get('object_list')
|
||||||
|
for game in games:
|
||||||
|
self.assertFalse(game.wish)
|
||||||
|
self.assertTrue(game.status != Game.EXCLUDED)
|
||||||
|
sorted_games = list(games.order_by('name'))
|
||||||
|
self.assertEqual([x.name for x in games], [s.name for s in sorted_games])
|
||||||
|
|
||||||
|
def test_index_playing_games(self):
|
||||||
|
"""
|
||||||
|
'playing_games' contains games that have playing=True.
|
||||||
|
"""
|
||||||
|
res = self.client.get(self.index_url)
|
||||||
|
playing_games = res.context.get('playing_games')
|
||||||
|
for game in playing_games:
|
||||||
|
self.assertTrue(game.playing)
|
||||||
|
|
||||||
|
def test_index_last_timelines(self):
|
||||||
|
"""
|
||||||
|
'last_timelines' only have 5 items.
|
||||||
|
'last_timelines' have NO games with status EXCLUDED.
|
||||||
|
"""
|
||||||
|
res = self.client.get(self.index_url)
|
||||||
|
games = res.context.get('last_timelines')
|
||||||
|
self.assertEqual(len(games), 5)
|
||||||
|
for game in games:
|
||||||
|
self.assertTrue(game.status != Game.EXCLUDED)
|
||||||
|
@ -20,6 +20,8 @@ class GameList(ListView):
|
|||||||
context = super(GameList, self).get_context_data(**kwargs)
|
context = super(GameList, self).get_context_data(**kwargs)
|
||||||
context['playing_games'] = Game.objects.filter(
|
context['playing_games'] = Game.objects.filter(
|
||||||
playing=True).order_by('name')
|
playing=True).order_by('name')
|
||||||
context['last_timelines'] = Timeline.objects.all().order_by(
|
context['last_timelines'] = Timeline.objects.filter(
|
||||||
|
~Q(item__status=Game.EXCLUDED)
|
||||||
|
).order_by(
|
||||||
'-date')[:5]
|
'-date')[:5]
|
||||||
return context
|
return context
|
Loading…
Reference in New Issue
Block a user