X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/8559c95597de98e8f6c580e97224ed3ecc9dc5c0..3199cbfa76c763b4082b5a8d8f971d74f67e27c0:/catalogue/management/commands/importbooks.py diff --git a/catalogue/management/commands/importbooks.py b/catalogue/management/commands/importbooks.py index 24908fe44..22dd237f7 100644 --- a/catalogue/management/commands/importbooks.py +++ b/catalogue/management/commands/importbooks.py @@ -1,12 +1,10 @@ -from django.core.management.base import BaseCommand, CommandError +import os + +from django.core.management.base import BaseCommand from django.core.management.color import color_style from optparse import make_option -import sys -import os -from catalogue.lib.dcparser import parse -from catalogue.lib.slughifi import slughifi -from catalogue.models import Book, Tag +from catalogue.models import Book class Command(BaseCommand): @@ -40,26 +38,10 @@ class Command(BaseCommand): if not os.path.splitext(file_name)[1] == '.xml': print self.style.NOTICE("Skipping '%s': not an XML file." % file_path) continue - if verbosity > 1: + if verbosity > 0: print "Parsing '%s'" % file_path - - book_info = parse(file_path) - book = Book(title=book_info.title, slug=slughifi(book_info.title)) - book.save() - book_tags = [] - for category in ('kind', 'genre', 'author', 'epoch'): - tag_name = getattr(book_info, category) - tag_sort_key = tag_name - if category == 'author': - tag_sort_key = tag_name.last_name - tag_name = ' '.join(tag_name.first_names) + ' ' + tag_name.last_name - tag, created = Tag.objects.get_or_create(name=tag_name, - slug=slughifi(tag_name), sort_key=slughifi(tag_sort_key), category=category) - tag.save() - book_tags.append(tag) - book.tags = book_tags - + Book.from_xml_file(file_path) transaction.commit() transaction.leave_transaction_management()