Compare commits

..

2 Commits

Author SHA1 Message Date
Yohann D'ANELLO 44abcaf202 Import romans without any ISBN 2020-05-24 16:01:05 +02:00
Yohann D'ANELLO 963ff25506 Add revues 2020-05-24 15:37:57 +02:00
8 changed files with 290 additions and 1 deletions

View File

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

View File

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

View File

@ -0,0 +1,65 @@
import re
import unicodedata
from argparse import FileType
from sys import stdin
from django.core.management import BaseCommand
from media.models import Auteur, Roman
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"]
romans = []
for line in file:
romans.append(line[:-1].split('|'))
print("Registering", len(romans), "romans")
imported = 0
for book in romans:
if len(book) != 2:
continue
title = book[1]
title_normalized = title.upper()
title_normalized = title_normalized.replace('', '\'')
title_normalized = ''.join(
char
for char in unicodedata.normalize(
'NFKD', title_normalized.casefold())
if all(not unicodedata.category(char).startswith(cat)
for cat in {'M', 'P', 'Z', 'C'}) or char == ' '
).casefold().upper()
title_normalized = re.sub(r'^LE ', '', title_normalized)
title_normalized = re.sub(r'^LA ', '', title_normalized)
title_normalized = re.sub(r'^LES ', '', title_normalized)
title_normalized = re.sub(r'^L\'', '', title_normalized)
title_normalized = re.sub(r'^THE ', '', title_normalized)
title_normalized = re.sub(r'Œ', 'OE', title_normalized)
title_normalized = title_normalized.replace(' ', '')
authors = [Auteur.objects.get_or_create(name=n)[0]
for n in book[0].split(';')]
side_identifier = "{:.3} {:.3}" \
.format(authors[0].name.upper(), title_normalized, )
roman = Roman.objects.create(
title=title,
side_identifier=side_identifier,
)
roman.authors.set(authors)
roman.save()
self.stdout.write(self.style.SUCCESS(
"Roman imported"))
imported += 1
self.stdout.write(self.style.SUCCESS(
"{count} romans imported".format(count=imported)))

View File

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

View File

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

View File

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

View File

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

View File

@ -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 + "" + str(self.number)
class Meta:
verbose_name = _("revue")
verbose_name_plural = _("revues")
ordering = ['title', 'number']
class FutureMedia(models.Model):
isbn = ISBNField(
_('ISBN'),