Renommage des consoles en plateformes

This commit is contained in:
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) : Current version (0.2) :
- Renommage des consoles en « plateformes »
- Activation des requêtes CORS pour permettre à une autre application d'accéder à l'API - Activation des requêtes CORS pour permettre à une autre application d'accéder à l'API
- MàJ vers Django 1.11.5 - MàJ vers Django 1.11.5
- Activation d'une API (pour les consoles) accessible par l'administrateur (avec documentation) - 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 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). 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 # À faire
* Renommer "Console" en "Plateforme"
* Ajouter des help_text à tous les champs + classes enfants. Les traduire. * 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. * é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. # This file is distributed under the same license as the openbackloggery package.
# Olivier DOSSMANN <git@dossmann.net>, 2017. # Olivier DOSSMANN <git@dossmann.net>, 2017.
# #
#, fuzzy
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 0.1\n" "Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-08-31 14:49+0000\n" "POT-Creation-Date: 2017-09-16 15:15+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: 2017-09-16 17:16+0200\n"
"Last-Translator: Olivier DOSSMANN <git@dossmann.net>\n" "Last-Translator: Olivier DOSSMANN <git@dossmann.net>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: \n" "Language: fr\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\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" msgid "French"
msgstr "Français" msgstr "Français"
#: collection/components/i18n.py:9 #: collection/collection/components/i18n.py:9
msgid "English" msgid "English"
msgstr "Anglais" msgstr "Anglais"

View File

@ -16,7 +16,7 @@ Including another URLconf
from django.conf.urls import url, include from django.conf.urls import url, include
from django.contrib import admin from django.contrib import admin
from collection import __version__ as app_version 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 import routers
from rest_framework.documentation import include_docs_urls 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 # Django Rest Framework router
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'consoles', ConsoleViewSet) router.register(r'platforms', PlatformViewSet)
urlpatterns = [ urlpatterns = [
url(r'^$', GameList.as_view(), name='homepage'), url(r'^$', GameList.as_view(), name='homepage'),

View File

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

View File

@ -1,44 +1,44 @@
- model: games.console - model: games.platform
pk: 1 pk: 1
fields: fields:
name: Steam name: Steam
- model: games.console - model: games.platform
pk: 2 pk: 2
fields: fields:
name: Game Boy name: Game Boy
- model: games.console - model: games.platform
pk: 3 pk: 3
fields: fields:
name: Nintendo 3DS name: Nintendo 3DS
- model: games.console - model: games.platform
pk: 4 pk: 4
fields: fields:
name: Nintendo Switch name: Nintendo Switch
- model: games.console - model: games.platform
pk: 5 pk: 5
fields: fields:
name: PC name: PC
- model: games.console - model: games.platform
pk: 6 pk: 6
fields: fields:
name: Genesis / Mega Drive name: Genesis / Mega Drive
- model: games.console - model: games.platform
pk: 7 pk: 7
fields: fields:
name: Nintendo Entertainment System name: Nintendo Entertainment System
- model: games.console - model: games.platform
pk: 8 pk: 8
fields: fields:
name: PlayStation name: PlayStation
- model: games.console - model: games.platform
pk: 9 pk: 9
fields: fields:
name: PlayStation 3 name: PlayStation 3
- model: games.console - model: games.platform
pk: 10 pk: 10
fields: fields:
name: PlayStation 4 name: PlayStation 4
- model: games.console - model: games.platform
pk: 11 pk: 11
fields: fields:
name: Wii 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 _ 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): def __str__(self):
return '%s' % self.name return '%s' % self.name
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
verbose_name = _('console') verbose_name = _('platform')
verbose_name_plural = _('consoles') verbose_name_plural = _('platforms')
# Redefine help_text (for documentation, API, etc.) # 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): 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 # class config
TARGET_MODEL = 'games.Console' TARGET_MODEL = 'games.Platform'
TARGET_VERBOSE_NAME = _('console') TARGET_VERBOSE_NAME = _('platform')
RELATED_TARGET_NAME = 'games' RELATED_TARGET_NAME = 'games'
# Status choices # Status choices

View File

@ -1,8 +1,8 @@
from games.models import Console from games.models import Platform
from rest_framework import serializers from rest_framework import serializers
class ConsoleSerializer(serializers.ModelSerializer): class PlatformSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Console model = Platform
fields = ('name',) fields = ('name',)

View File

@ -1,12 +1,12 @@
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.urls import reverse from django.urls import reverse
from games.models import Console from games.models import Platform
from rest_framework import status from rest_framework import status
from rest_framework.test import APITestCase, force_authenticate from rest_framework.test import APITestCase, force_authenticate
import json import json
class ConsoleTest(APITestCase): class PlatformTest(APITestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
@ -15,31 +15,31 @@ class ConsoleTest(APITestCase):
'admin@localhost', 'admin@localhost',
'admin') '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'} data = {'name': 'GP2X'}
self.client.force_authenticate(user=self.superuser) self.client.force_authenticate(user=self.superuser)
response = self.client.post(url, data, format='json') response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(Console.objects.count(), 1) self.assertEqual(Platform.objects.count(), 1)
self.assertEqual(Console.objects.get().name, 'GP2X') 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') Platform.objects.create(name='GP2X')
Console.objects.create(name='3DS') Platform.objects.create(name='3DS')
Console.objects.create(name='Game Boy') Platform.objects.create(name='Game Boy')
Console.objects.create(name='Amiga') Platform.objects.create(name='Amiga')
url = reverse('console-list') url = reverse('platform-list')
self.client.force_authenticate(user=self.superuser) self.client.force_authenticate(user=self.superuser)
response = self.client.get(url, format='json') response = self.client.get(url, format='json')
sorted_consoles = list( sorted_platforms = list(
Console.objects.all().order_by('name').values_list( Platform.objects.all().order_by('name').values_list(
'name', flat=True)) 'name', flat=True))
consoles = [x.get('name') for x in json.loads(response.content)] platforms = [x.get('name') for x in json.loads(response.content)]
self.assertEqual(consoles, sorted_consoles) self.assertEqual(platforms, sorted_platformss)

View File

@ -1,20 +1,20 @@
from django.test import TestCase 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): def setUp(self):
Console.objects.create(name='GP2X') Platform.objects.create(name='GP2X')
Console.objects.create(name='3DS') Platform.objects.create(name='3DS')
def test_console_are_sorted_by_name(self): def test_platform_are_sorted_by_name(self):
consoles = list(Console.objects.all().values_list('name', flat=True)) platforms = list(Platform.objects.all().values_list('name', flat=True))
sorted_consoles = list( sorted_platforms = list(
Console.objects.all().order_by('name').values_list( Platform.objects.all().order_by('name').values_list(
'name', flat=True)) '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 django.test import TestCase
from games.models import Console, Game from games.models import Game, Platform
class GameTest(TestCase): class GameTest(TestCase):
@ -8,20 +8,20 @@ class GameTest(TestCase):
""" """
def setUp(self): def setUp(self):
self.console = Console.objects.create(name='BestConsole4Ever') self.platform = Platform.objects.create(name='BestPlatform4Ever')
Game.objects.create( Game.objects.create(
name='Deponia', name='Deponia',
playing=True, playing=True,
collection=self.console, collection=self.platform,
status=Game.EXCLUDED) status=Game.EXCLUDED)
Game.objects.create( Game.objects.create(
name='Aladdin', playing=True, collection=self.console) name='Aladdin', playing=True, collection=self.platform)
Game.objects.create( Game.objects.create(
name='Persona 5', playing=True, collection=self.console) name='Persona 5', playing=True, collection=self.platform)
Game.objects.create( Game.objects.create(
name='The Witcher III', name='The Witcher III',
playing=False, playing=False,
collection=self.console, collection=self.platform,
wish=True) wish=True)
self.index_url = '/games/' self.index_url = '/games/'

View File

@ -1,25 +1,25 @@
from django.db.models import Q from django.db.models import Q
from django.views.generic import ListView from django.views.generic import ListView
from rest_framework import viewsets 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: retrieve:
Return the given console Return the given platform
list: list:
Return a list of all existing consoles ordered by name. Return a list of all existing platforms ordered by name.
create: create:
Create a new console instance. Create a new platform instance.
""" """
queryset = Console.objects.all().order_by('name') queryset = Platform.objects.all().order_by('name')
serializer_class = ConsoleSerializer serializer_class = PlatformSerializer
class GameList(ListView): class GameList(ListView):