Renommage des consoles en plateformes
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext as _
|
||||
from games.forms import GameForm
|
||||
from games.models import Console, Game, Timeline
|
||||
from games.models import Game, Platform, Timeline
|
||||
|
||||
|
||||
class StatusFilter(admin.SimpleListFilter):
|
||||
@ -56,6 +56,6 @@ class TimelineAdmin(admin.ModelAdmin):
|
||||
'date', 'status', 'item')
|
||||
|
||||
|
||||
admin.site.register(Console)
|
||||
admin.site.register(Platform)
|
||||
admin.site.register(Game, GameAdmin)
|
||||
admin.site.register(Timeline, TimelineAdmin)
|
||||
|
@ -1,44 +1,44 @@
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 1
|
||||
fields:
|
||||
name: Steam
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 2
|
||||
fields:
|
||||
name: Game Boy
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 3
|
||||
fields:
|
||||
name: Nintendo 3DS
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 4
|
||||
fields:
|
||||
name: Nintendo Switch
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 5
|
||||
fields:
|
||||
name: PC
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 6
|
||||
fields:
|
||||
name: Genesis / Mega Drive
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 7
|
||||
fields:
|
||||
name: Nintendo Entertainment System
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 8
|
||||
fields:
|
||||
name: PlayStation
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 9
|
||||
fields:
|
||||
name: PlayStation 3
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 10
|
||||
fields:
|
||||
name: PlayStation 4
|
||||
- model: games.console
|
||||
- model: games.platform
|
||||
pk: 11
|
||||
fields:
|
||||
name: Wii
|
||||
|
@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.5 on 2017-09-16 15:05
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('games', '0007_help_text_on_console_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name='Console',
|
||||
new_name='Platform',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='game',
|
||||
name='collection',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='games', to='games.Platform', verbose_name='platform'),
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='Platform',
|
||||
options={
|
||||
'verbose_name': 'platform',
|
||||
'verbose_name_plural': 'platforms',
|
||||
'ordering': ('name',),
|
||||
},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='platform',
|
||||
name='name',
|
||||
field=models.CharField(help_text='Most used platform name.', max_length=255, verbose_name='nom'),
|
||||
),
|
||||
]
|
@ -3,30 +3,30 @@ from django.db import models
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
class Console(Collection):
|
||||
class Platform(Collection):
|
||||
"""
|
||||
All console, system or box that can be used to play video games.
|
||||
All platform, system or box that can be used to play video games.
|
||||
"""
|
||||
def __str__(self):
|
||||
return '%s' % self.name
|
||||
|
||||
class Meta:
|
||||
ordering = ('name',)
|
||||
verbose_name = _('console')
|
||||
verbose_name_plural = _('consoles')
|
||||
verbose_name = _('platform')
|
||||
verbose_name_plural = _('platforms')
|
||||
|
||||
|
||||
# Redefine help_text (for documentation, API, etc.)
|
||||
Console._meta.get_field('name').help_text = _('Most used console name.')
|
||||
Platform._meta.get_field('name').help_text = _('Most used platform name.')
|
||||
|
||||
|
||||
class Game(Item):
|
||||
"""
|
||||
A video game you will use on a specific Console.
|
||||
A video game you will use on a specific Platform.
|
||||
"""
|
||||
# class config
|
||||
TARGET_MODEL = 'games.Console'
|
||||
TARGET_VERBOSE_NAME = _('console')
|
||||
TARGET_MODEL = 'games.Platform'
|
||||
TARGET_VERBOSE_NAME = _('platform')
|
||||
RELATED_TARGET_NAME = 'games'
|
||||
|
||||
# Status choices
|
||||
|
@ -1,8 +1,8 @@
|
||||
from games.models import Console
|
||||
from games.models import Platform
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class ConsoleSerializer(serializers.ModelSerializer):
|
||||
class PlatformSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Console
|
||||
model = Platform
|
||||
fields = ('name',)
|
||||
|
@ -1,12 +1,12 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
from games.models import Console
|
||||
from games.models import Platform
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase, force_authenticate
|
||||
import json
|
||||
|
||||
|
||||
class ConsoleTest(APITestCase):
|
||||
class PlatformTest(APITestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
@ -15,31 +15,31 @@ class ConsoleTest(APITestCase):
|
||||
'admin@localhost',
|
||||
'admin')
|
||||
|
||||
def test_create_console(self):
|
||||
def test_create_platform(self):
|
||||
"""
|
||||
Check we can create a console object.
|
||||
Check we can create a platform object.
|
||||
"""
|
||||
url = reverse('console-list')
|
||||
url = reverse('platform-list')
|
||||
data = {'name': 'GP2X'}
|
||||
self.client.force_authenticate(user=self.superuser)
|
||||
response = self.client.post(url, data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(Console.objects.count(), 1)
|
||||
self.assertEqual(Console.objects.get().name, 'GP2X')
|
||||
self.assertEqual(Platform.objects.count(), 1)
|
||||
self.assertEqual(Platform.objects.get().name, 'GP2X')
|
||||
|
||||
def test_sorted_console(self):
|
||||
def test_sorted_platform(self):
|
||||
"""
|
||||
Check that console list is sorted.
|
||||
Check that platform list is sorted.
|
||||
"""
|
||||
Console.objects.create(name='GP2X')
|
||||
Console.objects.create(name='3DS')
|
||||
Console.objects.create(name='Game Boy')
|
||||
Console.objects.create(name='Amiga')
|
||||
url = reverse('console-list')
|
||||
Platform.objects.create(name='GP2X')
|
||||
Platform.objects.create(name='3DS')
|
||||
Platform.objects.create(name='Game Boy')
|
||||
Platform.objects.create(name='Amiga')
|
||||
url = reverse('platform-list')
|
||||
self.client.force_authenticate(user=self.superuser)
|
||||
response = self.client.get(url, format='json')
|
||||
sorted_consoles = list(
|
||||
Console.objects.all().order_by('name').values_list(
|
||||
sorted_platforms = list(
|
||||
Platform.objects.all().order_by('name').values_list(
|
||||
'name', flat=True))
|
||||
consoles = [x.get('name') for x in json.loads(response.content)]
|
||||
self.assertEqual(consoles, sorted_consoles)
|
||||
platforms = [x.get('name') for x in json.loads(response.content)]
|
||||
self.assertEqual(platforms, sorted_platformss)
|
||||
|
@ -1,20 +1,20 @@
|
||||
from django.test import TestCase
|
||||
from games.models import Console
|
||||
from games.models import Platform
|
||||
|
||||
|
||||
class ConsoleTest(TestCase):
|
||||
class PlatformTest(TestCase):
|
||||
"""
|
||||
Console Model
|
||||
Platform Model
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
Console.objects.create(name='GP2X')
|
||||
Console.objects.create(name='3DS')
|
||||
Platform.objects.create(name='GP2X')
|
||||
Platform.objects.create(name='3DS')
|
||||
|
||||
|
||||
def test_console_are_sorted_by_name(self):
|
||||
consoles = list(Console.objects.all().values_list('name', flat=True))
|
||||
sorted_consoles = list(
|
||||
Console.objects.all().order_by('name').values_list(
|
||||
def test_platform_are_sorted_by_name(self):
|
||||
platforms = list(Platform.objects.all().values_list('name', flat=True))
|
||||
sorted_platforms = list(
|
||||
Platform.objects.all().order_by('name').values_list(
|
||||
'name', flat=True))
|
||||
self.assertEqual(consoles, sorted_consoles)
|
||||
self.assertEqual(platforms, sorted_platforms)
|
||||
|
@ -1,5 +1,5 @@
|
||||
from django.test import TestCase
|
||||
from games.models import Console, Game
|
||||
from games.models import Game, Platform
|
||||
|
||||
|
||||
class GameTest(TestCase):
|
||||
@ -8,20 +8,20 @@ class GameTest(TestCase):
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.console = Console.objects.create(name='BestConsole4Ever')
|
||||
self.platform = Platform.objects.create(name='BestPlatform4Ever')
|
||||
Game.objects.create(
|
||||
name='Deponia',
|
||||
playing=True,
|
||||
collection=self.console,
|
||||
collection=self.platform,
|
||||
status=Game.EXCLUDED)
|
||||
Game.objects.create(
|
||||
name='Aladdin', playing=True, collection=self.console)
|
||||
name='Aladdin', playing=True, collection=self.platform)
|
||||
Game.objects.create(
|
||||
name='Persona 5', playing=True, collection=self.console)
|
||||
name='Persona 5', playing=True, collection=self.platform)
|
||||
Game.objects.create(
|
||||
name='The Witcher III',
|
||||
playing=False,
|
||||
collection=self.console,
|
||||
collection=self.platform,
|
||||
wish=True)
|
||||
self.index_url = '/games/'
|
||||
|
||||
|
@ -1,25 +1,25 @@
|
||||
from django.db.models import Q
|
||||
from django.views.generic import ListView
|
||||
from rest_framework import viewsets
|
||||
from .serializers import ConsoleSerializer
|
||||
from .serializers import PlatformSerializer
|
||||
|
||||
from .models import Console, Game, Timeline
|
||||
from .models import Game, Platform, Timeline
|
||||
|
||||
class ConsoleViewSet(viewsets.ModelViewSet):
|
||||
class PlatformViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoints that allows consoles to be edited or viewed.
|
||||
API endpoints that allows platforms to be edited or viewed.
|
||||
|
||||
retrieve:
|
||||
Return the given console
|
||||
Return the given platform
|
||||
|
||||
list:
|
||||
Return a list of all existing consoles ordered by name.
|
||||
Return a list of all existing platforms ordered by name.
|
||||
|
||||
create:
|
||||
Create a new console instance.
|
||||
Create a new platform instance.
|
||||
"""
|
||||
queryset = Console.objects.all().order_by('name')
|
||||
serializer_class = ConsoleSerializer
|
||||
queryset = Platform.objects.all().order_by('name')
|
||||
serializer_class = PlatformSerializer
|
||||
|
||||
|
||||
class GameList(ListView):
|
||||
|
Reference in New Issue
Block a user