From c3491b79751cb37e5d665f6fde1f913f90b6ee6b Mon Sep 17 00:00:00 2001
From: Olivier DOSSMANN {{ date.grouper }} :
+ {% trans "Memory Card" %}
{% if last_timelines %}
-
- {% for timeline in last_timelines %}
-
+
+ {% for timeline in date.list|dictsortreversed:"id" %}
+
{% endfor %}
-
{% trans "Empty memory." %}
{% endif %} diff --git a/collection/games/tests/test_game.py b/collection/games/tests/test_game.py index 7ff186b..b966fae 100644 --- a/collection/games/tests/test_game.py +++ b/collection/games/tests/test_game.py @@ -10,11 +10,20 @@ class GameTest(TestCase): def setUp(self): self.console = Console.objects.create(name='BestConsole4Ever') Game.objects.create( - name='Deponia', playing=False, collection=self.console) + name='Deponia', + playing=True, + collection=self.console, + status=Game.EXCLUDED) Game.objects.create( name='Aladdin', playing=True, collection=self.console) Game.objects.create( 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): @@ -26,3 +35,48 @@ class GameTest(TestCase): sorted_games = list(Game.objects.all().order_by( '-playing', 'name').values_list('name', flat=True)) 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) diff --git a/collection/games/views.py b/collection/games/views.py index f273bef..742b985 100644 --- a/collection/games/views.py +++ b/collection/games/views.py @@ -20,6 +20,8 @@ class GameList(ListView): context = super(GameList, self).get_context_data(**kwargs) context['playing_games'] = Game.objects.filter( 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] - return context \ No newline at end of file + return context