fnp
/
redakcja.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move to Django 1.5.
[redakcja.git]
/
apps
/
catalogue
/
management
/
commands
/
import_wl.py
diff --git
a/apps/catalogue/management/commands/import_wl.py
b/apps/catalogue/management/commands/import_wl.py
old mode 100755
(executable)
new mode 100644
(file)
index
6836d36
..
5f60388
--- a/
apps/catalogue/management/commands/import_wl.py
+++ b/
apps/catalogue/management/commands/import_wl.py
@@
-1,5
+1,6
@@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
+from collections import defaultdict
import json
from optparse import make_option
import urllib2
import json
from optparse import make_option
import urllib2
@@
-35,9
+36,9
@@
class Command(BaseCommand):
transaction.managed(True)
if verbose:
transaction.managed(True)
if verbose:
- print 'Reading currently managed files.'
- slugs =
{}
- for b in Book.objects.all():
+ print 'Reading currently managed files
(skipping hidden ones)
.'
+ slugs =
defaultdict(list)
+ for b in Book.objects.
exclude(slug__startswith='.').
all():
if verbose:
print b.slug
text = b.materialize().encode('utf-8')
if verbose:
print b.slug
text = b.materialize().encode('utf-8')
@@
-46,12
+47,13
@@
class Command(BaseCommand):
except (ParseError, ValidationError):
pass
else:
except (ParseError, ValidationError):
pass
else:
- slugs[info.slug]
= b
+ slugs[info.slug]
.append(b)
book_count = 0
commit_args = {
"author_name": 'Platforma',
book_count = 0
commit_args = {
"author_name": 'Platforma',
- "description": 'Import from WL',
+ "description": 'Automatycznie zaimportowane z Wolnych Lektur',
+ "publishable": True,
}
if verbose:
}
if verbose:
@@
-60,14
+62,20
@@
class Command(BaseCommand):
book_detail = json.load(urllib2.urlopen(book['href']))
xml_text = urllib2.urlopen(book_detail['xml']).read()
info = BookInfo.from_string(xml_text)
book_detail = json.load(urllib2.urlopen(book['href']))
xml_text = urllib2.urlopen(book_detail['xml']).read()
info = BookInfo.from_string(xml_text)
- previous_book = slugs.get(info.slug, None)
- if previous_book:
+ previous_books = slugs.get(info.slug)
+ if previous_books:
+ if len(previous_books) > 1:
+ print self.style.ERROR("There is more than one book "
+ "with slug %s:"),
+ previous_book = previous_books[0]
comm = previous_book.slug
else:
comm = previous_book.slug
else:
+ previous_book = None
comm = '*'
print book_count, info.slug , '-->', comm
comm = '*'
print book_count, info.slug , '-->', comm
- Book.import_xml_text(xml_text, title=info.title,
- slug=info.slug, previous_book=slugs.get(info.slug, None))
+ Book.import_xml_text(xml_text, title=info.title[:255],
+ slug=info.slug[:128], previous_book=previous_book,
+ commit_args=commit_args)
book_count += 1
# Print results
book_count += 1
# Print results