From 20cb710af5994191a1e67f213bb7f417bf816e0b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 22 May 2020 21:08:44 +0200 Subject: [PATCH] Romans were missing --- media/admin.py | 3 +- media/forms.py | 1 + media/migrations/0032_auto_20200522_2107.py | 38 ++++++++++++ media/models.py | 66 +++++++++++++++++++++ media/tests/test_templates.py | 26 ++++---- 5 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 media/migrations/0032_auto_20200522_2107.py diff --git a/media/admin.py b/media/admin.py index bd92c6b..71744fd 100644 --- a/media/admin.py +++ b/media/admin.py @@ -9,7 +9,7 @@ from reversion.admin import VersionAdmin from med.admin import admin_site from .forms import MediaAdminForm -from .models import Auteur, BD, CD, Emprunt, FutureMedia, Jeu, Manga, Vinyle +from .models import Auteur, BD, CD, Emprunt, FutureMedia, Jeu, Manga, Roman, Vinyle class AuteurAdmin(VersionAdmin): @@ -133,6 +133,7 @@ class JeuAdmin(VersionAdmin): admin_site.register(Auteur, AuteurAdmin) admin_site.register(BD, MediaAdmin) admin_site.register(Manga, MediaAdmin) +admin_site.register(Roman, MediaAdmin) admin_site.register(CD, CDAdmin) admin_site.register(Vinyle, CDAdmin) admin_site.register(FutureMedia, FutureMediaAdmin) diff --git a/media/forms.py b/media/forms.py index 48eff85..08e766c 100644 --- a/media/forms.py +++ b/media/forms.py @@ -166,6 +166,7 @@ class MediaAdminForm(ModelForm): if "_isbn_addanother" in self.data: self.data = self.data.copy() self.data['_addanother'] = 42 + self.request.POST = self.data if isbn: # ISBN is present, try with bedeteque scrap_result = self.download_data_bedeteque(isbn) diff --git a/media/migrations/0032_auto_20200522_2107.py b/media/migrations/0032_auto_20200522_2107.py new file mode 100644 index 0000000..30073a0 --- /dev/null +++ b/media/migrations/0032_auto_20200522_2107.py @@ -0,0 +1,38 @@ +# Generated by Django 2.2.10 on 2020-05-22 19:07 + +from django.db import migrations, models +import media.fields +import media.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0031_auto_20200522_1758'), + ] + + operations = [ + migrations.AlterModelOptions( + name='manga', + options={'ordering': ['title'], 'verbose_name': 'manga', 'verbose_name_plural': 'mangas'}, + ), + migrations.CreateModel( + name='Roman', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('isbn', media.fields.ISBNField(blank=True, help_text='You may be able to scan it from a bar code.', max_length=28, null=True, unique=True, validators=[media.validators.isbn_validator], verbose_name='ISBN')), + ('title', models.CharField(max_length=255, verbose_name='title')), + ('subtitle', models.CharField(blank=True, max_length=255, null=True, verbose_name='subtitle')), + ('external_url', models.URLField(blank=True, null=True, verbose_name='external URL')), + ('side_identifier', models.CharField(max_length=255, verbose_name='side identifier')), + ('number_of_pages', models.PositiveIntegerField(blank=True, null=True, verbose_name='number of pages')), + ('publish_date', models.DateField(blank=True, null=True, verbose_name='publish date')), + ('authors', models.ManyToManyField(to='media.Auteur', verbose_name='authors')), + ], + options={ + 'verbose_name': 'roman', + 'verbose_name_plural': 'romans', + 'ordering': ['title', 'subtitle'], + }, + ), + ] diff --git a/media/models.py b/media/models.py index c7b830a..ade119c 100644 --- a/media/models.py +++ b/media/models.py @@ -140,6 +140,72 @@ class Manga(models.Model): null=True, ) + def __str__(self): + return self.title + + class Meta: + verbose_name = _("manga") + verbose_name_plural = _("mangas") + ordering = ['title'] + + +class Roman(models.Model): + isbn = ISBNField( + _('ISBN'), + help_text=_('You may be able to scan it from a bar code.'), + unique=True, + blank=True, + null=True, + ) + + title = models.CharField( + verbose_name=_('title'), + max_length=255, + ) + + subtitle = models.CharField( + verbose_name=_('subtitle'), + max_length=255, + blank=True, + null=True, + ) + + external_url = models.URLField( + verbose_name=_('external URL'), + blank=True, + null=True, + ) + + side_identifier = models.CharField( + verbose_name=_('side identifier'), + max_length=255, + ) + + authors = models.ManyToManyField( + 'Auteur', + verbose_name=_('authors'), + ) + + number_of_pages = models.PositiveIntegerField( + verbose_name=_('number of pages'), + blank=True, + null=True, + ) + + publish_date = models.DateField( + verbose_name=_('publish date'), + blank=True, + null=True, + ) + + def __str__(self): + return self.title + + class Meta: + verbose_name = _("roman") + verbose_name_plural = _("romans") + ordering = ['title', 'subtitle'] + class Vinyle(models.Model): title = models.CharField( diff --git a/media/tests/test_templates.py b/media/tests/test_templates.py index 4c2ffbd..c103359 100644 --- a/media/tests/test_templates.py +++ b/media/tests/test_templates.py @@ -25,41 +25,41 @@ class TemplateTests(TestCase): self.dummy_author = Auteur.objects.create(name="Test author") # Create media - self.dummy_media1 = BD.objects.create( + self.dummy_bd1 = BD.objects.create( title="Test media", side_identifier="T M", ) - self.dummy_media1.authors.add(self.dummy_author) - self.dummy_media2 = BD.objects.create( + self.dummy_bd1.authors.add(self.dummy_author) + self.dummy_bd2 = BD.objects.create( title="Test media bis", side_identifier="T M 2", external_url="https://example.com/", ) - self.dummy_media2.authors.add(self.dummy_author) + self.dummy_bd2.authors.add(self.dummy_author) - def test_media_media_changelist(self): - response = self.client.get(reverse('admin:media_media_changelist')) + def test_bd_bd_changelist(self): + response = self.client.get(reverse('admin:media_bd_changelist')) self.assertEqual(response.status_code, 200) - def test_media_media_add(self): - response = self.client.get(reverse('admin:media_media_add')) + def test_bd_bd_add(self): + response = self.client.get(reverse('admin:media_bd_add')) self.assertEqual(response.status_code, 200) - def test_media_isbn_download(self): + def test_bd_isbn_download(self): data = { '_isbn': True, 'isbn': "0316358525", } response = self.client.post(reverse( - 'admin:media_media_change', - args=[self.dummy_media1.id], + 'admin:media_bd_change', + args=[self.dummy_bd1.id], ), data=data) self.assertEqual(response.status_code, 302) - def test_media_emprunt_changelist(self): + def test_bd_emprunt_changelist(self): response = self.client.get(reverse('admin:media_emprunt_changelist')) self.assertEqual(response.status_code, 200) - def test_media_emprunt_add(self): + def test_bd_emprunt_add(self): response = self.client.get(reverse('admin:media_emprunt_add')) self.assertEqual(response.status_code, 200)