Renommage des consoles en plateformes

master
Olivier DOSSMANN 2017-09-16 17:42:04 +02:00
parent 0380bc9071
commit b0978034b5
15 changed files with 164 additions and 120 deletions

View File

@ -1,5 +1,6 @@
Current version (0.2) :
- Renommage des consoles en « plateformes »
- Activation des requêtes CORS pour permettre à une autre application d'accéder à l'API
- MàJ vers Django 1.11.5
- Activation d'une API (pour les consoles) accessible par l'administrateur (avec documentation)

View File

@ -77,7 +77,7 @@ docker run -it --rm -v /openbackloggery_db:/opt/apps/db openbackloggery:0.1 pyth
docker run -it --rm -v /openbackloggery_db:/opt/apps/db openbackloggery:0.1 python3 manage.py loaddata initial
```
*loaddata initial* permet de charger quelques données initiales comme une liste de consoles par exemple.
*loaddata initial* permet de charger quelques données initiales comme une liste de plateformes par exemple.
Adaptez la ligne en remplaçant **admin** par le nom d'utilisateur que vous voulez et **admin@domaine.tld** par l'adresse courriel de votre choix (qu'elle existe ou non importe peu pour l'instant car elle n'est pas utilisée).

1
TODO
View File

@ -1,6 +1,5 @@
# À faire
* Renommer "Console" en "Plateforme"
* Ajouter des help_text à tous les champs + classes enfants. Les traduire.
* étudier la possibilité à l'utilisateur, via des variables d'environnement, de configurer un email, une autre BDD, etc.

View File

@ -3,24 +3,24 @@
# This file is distributed under the same license as the openbackloggery package.
# Olivier DOSSMANN <git@dossmann.net>, 2017.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-08-31 14:49+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"POT-Creation-Date: 2017-09-16 15:15+0000\n"
"PO-Revision-Date: 2017-09-16 17:16+0200\n"
"Last-Translator: Olivier DOSSMANN <git@dossmann.net>\n"
"Language-Team: \n"
"Language: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.3\n"
#: collection/components/i18n.py:8
#: collection/collection/components/i18n.py:8
msgid "French"
msgstr "Français"
#: collection/components/i18n.py:9
#: collection/collection/components/i18n.py:9
msgid "English"
msgstr "Anglais"

View File

@ -16,7 +16,7 @@ Including another URLconf
from django.conf.urls import url, include
from django.contrib import admin
from collection import __version__ as app_version
from games.views import GameList, ConsoleViewSet
from games.views import GameList, PlatformViewSet
from rest_framework import routers
from rest_framework.documentation import include_docs_urls
@ -26,7 +26,7 @@ admin.site.site_header = '%s %s' % (admin.site.site_title, app_version)
# Django Rest Framework router
router = routers.DefaultRouter()
router.register(r'consoles', ConsoleViewSet)
router.register(r'platforms', PlatformViewSet)
urlpatterns = [
url(r'^$', GameList.as_view(), name='homepage'),

View File

@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-04 21:24+0000\n"
"PO-Revision-Date: 2017-09-04 23:27+0200\n"
"POT-Creation-Date: 2017-09-16 15:15+0000\n"
"PO-Revision-Date: 2017-09-16 17:17+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
@ -17,138 +17,144 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.3\n"
#: core/models.py:7 core/models.py:28
#: collection/core/models.py:7 collection/core/models.py:28
msgid "name"
msgstr "nom"
#: core/models.py:24
#: collection/core/models.py:24
msgid "New"
msgstr "Nouveau"
#: core/models.py:48 core/models.py:80
#: collection/core/models.py:48 collection/core/models.py:80
msgid "status"
msgstr "état"
#: core/models.py:65
#: collection/core/models.py:65
msgid "date"
msgstr "date"
#: games/admin.py:11
#: collection/games/admin.py:11
msgid "state"
msgstr "état"
#: games/admin.py:39
#: collection/games/admin.py:39
msgid "Game Information"
msgstr "Information du jeu"
#: games/admin.py:42
#: collection/games/admin.py:42
msgid "Progress"
msgstr "Progression"
#: games/models.py:15 games/models.py:29
msgid "console"
msgstr "console"
#: collection/games/models.py:15 collection/games/models.py:29
msgid "platform"
msgstr "plateforme"
#: games/models.py:16
msgid "consoles"
msgstr "consoles"
#: collection/games/models.py:16
msgid "platforms"
msgstr "plateformes"
#: games/models.py:20
msgid "Most used console name."
msgstr "Nom de console le plus utilisé."
#: collection/games/models.py:20
msgid "Most used platform name."
msgstr "Nom de plateforme le plus utilisé."
#: games/models.py:40
#: collection/games/models.py:40
msgid "Beaten"
msgstr "Terminé (quête principale)"
#: games/models.py:41
#: collection/games/models.py:41
msgid "Completed"
msgstr "Terminé complètement"
#: games/models.py:42
#: collection/games/models.py:42
msgid "Excluded"
msgstr "Exclu"
#: games/models.py:43
#: collection/games/models.py:43
msgid "Mastered"
msgstr "Usé / Épuisé"
#: games/models.py:44
#: collection/games/models.py:44
msgid "Unfinished"
msgstr "Inachevé"
#: games/models.py:53
#: collection/games/models.py:53
msgid "Progress note"
msgstr "Note de progression"
#: games/models.py:54
#: collection/games/models.py:54
msgid "Short note displayed to your followers."
msgstr "Courte note affichée à ceux qui vous suive"
msgstr "Courte note affichée à ceux qui vous suive."
#: games/models.py:59
#: collection/games/models.py:59
msgid "playing?"
msgstr "en train d'y jouer ?"
#: games/models.py:60
#: collection/games/models.py:60
msgid "You're currently playing this game."
msgstr "Vous jouez actuellement à ce jeu."
#: games/models.py:63
#: collection/games/models.py:63
msgid "unplayed?"
msgstr "jamais joué ?"
#: games/models.py:64
#: collection/games/models.py:64
msgid "You never played this game."
msgstr "Vous n'avez jamais joué à ce jeu."
#: games/models.py:67
#: collection/games/models.py:67
msgid "wish?"
msgstr "envie de l'avoir ?"
#: games/models.py:68
#: collection/games/models.py:68
msgid "You're waiting X-mas father offers you this game."
msgstr "Vous patientez que le père Noël vous offre ce jeu."
#: games/models.py:72
#: collection/games/models.py:72
msgid "game"
msgstr "jeu"
#: games/models.py:73
#: collection/games/models.py:73
msgid "games"
msgstr "jeux"
#: games/models.py:84
#: collection/games/models.py:84
msgid "Timeline"
msgstr "Chronologie"
#: games/models.py:85
#: collection/games/models.py:85
msgid "Timelines"
msgstr "Chronologies"
#: games/templates/games/index.html:5
#: collection/games/templates/games/index.html:5
msgid "Games"
msgstr "Jeux"
#: games/templates/games/index.html:6
#: collection/games/templates/games/index.html:6
msgid "Now playing"
msgstr "En train d'y jouer"
#: games/templates/games/index.html:15
#: collection/games/templates/games/index.html:15
msgid "No playing game found."
msgstr "Aucun jeu en cours."
#: games/templates/games/index.html:17
#: collection/games/templates/games/index.html:17
msgid "Complete list"
msgstr "Liste complète"
#: games/templates/games/index.html:25
#: collection/games/templates/games/index.html:25
msgid "No game found."
msgstr "Aucun jeu."
#: games/templates/games/index.html:27
#: collection/games/templates/games/index.html:27
msgid "Memory Card"
msgstr "Carte mémoire"
#: games/templates/games/index.html:43
#: collection/games/templates/games/index.html:43
msgid "Empty memory."
msgstr "Mémoire vide."
#~ msgid "console"
#~ msgstr "console"
#~ msgid "consoles"
#~ msgstr "consoles"

View File

@ -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)

View File

@ -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

View File

@ -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'),
),
]

View File

@ -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

View File

@ -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',)

View File

@ -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)

View File

@ -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)

View File

@ -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/'

View File

@ -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):