diff --git a/media/admin.py b/media/admin.py index 65f42c0..abe0f86 100644 --- a/media/admin.py +++ b/media/admin.py @@ -10,7 +10,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,\ - Roman, Vinyle + Revue, Roman, Vinyle class AuteurAdmin(VersionAdmin): @@ -88,6 +88,11 @@ class CDAdmin(VersionAdmin): authors_list.short_description = _('authors') +class RevueAdmin(VersionAdmin): + list_display = ('__str__', 'number', 'year', 'month', 'day', 'double',) + search_fields = ('title', 'number', 'year',) + + class EmpruntAdmin(VersionAdmin): list_display = ('media', 'user', 'date_emprunt', 'date_rendu', 'permanencier_emprunt', 'permanencier_rendu_custom') @@ -137,6 +142,7 @@ admin_site.register(Manga, MediaAdmin) admin_site.register(Roman, MediaAdmin) admin_site.register(CD, CDAdmin) admin_site.register(Vinyle, CDAdmin) +admin_site.register(Revue, RevueAdmin) admin_site.register(FutureMedia, FutureMediaAdmin) admin_site.register(Emprunt, EmpruntAdmin) admin_site.register(Jeu, JeuAdmin) diff --git a/media/management/commands/import_marvel.py b/media/management/commands/import_marvel.py new file mode 100644 index 0000000..69d5b1c --- /dev/null +++ b/media/management/commands/import_marvel.py @@ -0,0 +1,50 @@ +from argparse import FileType +from sys import stdin + +from django.core.management import BaseCommand +from media.models import Auteur, BD + + +class Command(BaseCommand): + def add_arguments(self, parser): + parser.add_argument('input', nargs='?', + type=FileType('r'), + default=stdin, + help="Marvel comic to be imported.") + + def handle(self, *args, **options): + file = options["input"] + revues = [] + for line in file: + revues.append(line[:-1].split('|', 2)) + + print("Registering", len(revues), "Marvel comics") + + imported = 0 + + for revue in revues: + if len(revue) != 3: + continue + + title = revue[0] + number = revue[1] + authors = [Auteur.objects.get_or_create(name=n)[0] + for n in revue[2].split('|')] + bd = BD.objects.create( + title=title, + subtitle=number, + side_identifier="{:.3} {:.3} {:0>2}" + .format(authors[0].name.upper(), + title.upper(), + number), + ) + + bd.authors.set(authors) + bd.save() + + self.stdout.write(self.style.SUCCESS( + "Comic imported")) + imported += 1 + + self.stdout.write(self.style.SUCCESS( + "{count} comics imported".format(count=imported))) diff --git a/media/management/commands/import_revues.py b/media/management/commands/import_revues.py new file mode 100644 index 0000000..6df08b3 --- /dev/null +++ b/media/management/commands/import_revues.py @@ -0,0 +1,58 @@ +from argparse import FileType +from sys import stdin + +from django.core.management import BaseCommand +from media.models import Revue + + +class Command(BaseCommand): + def add_arguments(self, parser): + parser.add_argument('input', nargs='?', + type=FileType('r'), + default=stdin, + help="Revues to be imported.") + + def handle(self, *args, **options): + file = options["input"] + revues = [] + for line in file: + revues.append(line[:-1].split('|')) + + print("Registering", len(revues), "revues") + + imported = 0 + + for revue in revues: + if len(revue) != 5: + continue + + title = revue[0] + number = revue[1] + day = revue[2] + if not day: + day = None + month = revue[3] + if not month: + month = None + year = revue[4] + if not year: + year = None + revue, created = Revue.objects.get_or_create( + title=title, + number=number.replace('*', ''), + year=year, + month=month, + day=day, + double=number.endswith('*'), + ) + + if not created: + self.stderr.write(self.style.WARNING( + "One revue was already imported. Skipping...")) + else: + self.stdout.write(self.style.SUCCESS( + "Revue imported")) + imported += 1 + + self.stdout.write(self.style.SUCCESS( + "{count} revues imported".format(count=imported))) diff --git a/media/migrations/0035_revue.py b/media/migrations/0035_revue.py new file mode 100644 index 0000000..0da2b3f --- /dev/null +++ b/media/migrations/0035_revue.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.10 on 2020-05-24 12:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0034_vinyle_rpm'), + ] + + operations = [ + migrations.CreateModel( + name='Revue', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255, verbose_name='title')), + ('number', models.PositiveIntegerField(verbose_name='number')), + ('year', models.PositiveIntegerField(verbose_name='year')), + ('month', models.PositiveIntegerField(blank=True, default=None, null=True, verbose_name='month')), + ('day', models.PositiveIntegerField(blank=True, default=None, null=True, verbose_name='day')), + ], + options={ + 'verbose_name': 'revue', + 'verbose_name_plural': 'revues', + 'ordering': ['title', 'number'], + }, + ), + ] diff --git a/media/migrations/0036_auto_20200524_1500.py b/media/migrations/0036_auto_20200524_1500.py new file mode 100644 index 0000000..064fa62 --- /dev/null +++ b/media/migrations/0036_auto_20200524_1500.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.10 on 2020-05-24 13:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0035_revue'), + ] + + operations = [ + migrations.AlterField( + model_name='revue', + name='year', + field=models.PositiveIntegerField(blank=True, default=None, null=True, verbose_name='year'), + ), + ] diff --git a/media/migrations/0037_revue_double.py b/media/migrations/0037_revue_double.py new file mode 100644 index 0000000..8c67fbc --- /dev/null +++ b/media/migrations/0037_revue_double.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.10 on 2020-05-24 13:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0036_auto_20200524_1500'), + ] + + operations = [ + migrations.AddField( + model_name='revue', + name='double', + field=models.BooleanField(default=False, verbose_name='double'), + ), + ] diff --git a/media/models.py b/media/models.py index 3517445..d6df7ba 100644 --- a/media/models.py +++ b/media/models.py @@ -265,6 +265,51 @@ class CD(models.Model): ordering = ['title'] +class Revue(models.Model): + title = models.CharField( + verbose_name=_('title'), + max_length=255, + ) + + number = models.PositiveIntegerField( + verbose_name=_('number'), + ) + + year = models.PositiveIntegerField( + verbose_name=_('year'), + null=True, + blank=True, + default=None, + ) + + month = models.PositiveIntegerField( + verbose_name=_('month'), + null=True, + blank=True, + default=None, + ) + + day = models.PositiveIntegerField( + verbose_name=_('day'), + null=True, + blank=True, + default=None, + ) + + double = models.BooleanField( + verbose_name=_('double'), + default=False, + ) + + def __str__(self): + return self.title + " n°" + str(self.number) + + class Meta: + verbose_name = _("revue") + verbose_name_plural = _("revues") + ordering = ['title', 'number'] + + class FutureMedia(models.Model): isbn = ISBNField( _('ISBN'),