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