3 from django.core.management import BaseCommand
4 from slugify import slugify
6 from catalogue.models import Book, Author
10 name_pieces = name.rsplit(' ', 1)
11 if len(name_pieces) == 1:
12 return name_pieces[0], ''
18 class Command(BaseCommand):
19 def add_arguments(self, parser):
20 parser.add_argument('path')
22 def handle(self, path, **kwargs):
26 if item['model'] == 'pdcounter.bookstub':
28 slug = item['fields']['slug']
29 book, created = Book.objects.get_or_create(slug=slug)
30 if item['fields']['translator'] and not book.translators.exists():
31 notes.append('tłum.: ' + item['fields']['translator'])
32 book.title = book.title or item['fields']['title']
33 book.pd_year = book.pd_year or item['fields']['pd']
34 notes = '\n'.join(notes)
35 if notes and notes not in book.notes:
36 book.notes = '\n'.join([notes, book.notes])
39 if not book.authors.exists():
40 first_name, last_name = parse_name(item['fields']['author'])
41 author, created = Author.objects.get_or_create(first_name=first_name, last_name=last_name)
43 author.slug = slugify(author_name)
45 book.authors.set([author])
46 elif item['model'] == 'pdcounter.author':
47 slug = item['fields']['slug']
48 author, created = Author.objects.get_or_create(slug=slug)
49 if not author.first_name and not author.last_name:
50 author.first_name, author.last_name = parse_name(item['fields']['name'])
51 author.year_of_death = author.year_of_death or item['fields']['death']
52 author.notes = author.notes or item['fields']['description']
53 author.gazeta_link = author.gazeta_link or item['fields']['gazeta_link']
55 wiki_link = item['fields']['wiki_link']
56 assert not wiki_link # Welp