import fixes
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Wed, 5 Oct 2011 09:32:47 +0000 (11:32 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Wed, 5 Oct 2011 09:32:47 +0000 (11:32 +0200)
apps/catalogue/management/commands/import_wl.py
apps/catalogue/models/book.py
apps/catalogue/models/chunk.py

index 4f15cef..5f60388 100755 (executable)
@@ -49,20 +49,6 @@ class Command(BaseCommand):
             else:
                 slugs[info.slug].append(b)
 
-        #~ conflicts = []
-        #~ for slug, book_list in slugs.items():
-            #~ if len(book_list) > 1:
-                #~ conflicts.append((slug, book_list))
-        #~ if conflicts:
-            #~ print self.style.ERROR("There is more than one book "
-                    #~ "with the same slug in dc:url. "
-                    #~ "Merge or hide them before proceeding.")
-            #~ for slug, book_list in sorted(conflicts):
-                #~ print slug
-                #~ print "\n".join(b.slug for b in book_list)
-                #~ print
-            #~ return
-
         book_count = 0
         commit_args = {
             "author_name": 'Platforma',
@@ -72,7 +58,7 @@ class Command(BaseCommand):
 
         if verbose:
             print 'Opening books list'
-        for book in json.load(urllib2.urlopen(WL_API))[:10]:
+        for book in json.load(urllib2.urlopen(WL_API)):
             book_detail = json.load(urllib2.urlopen(book['href']))
             xml_text = urllib2.urlopen(book_detail['xml']).read()
             info = BookInfo.from_string(xml_text)
@@ -87,8 +73,8 @@ class Command(BaseCommand):
                 previous_book = None
                 comm = '*'
             print book_count, info.slug , '-->', comm
-            Book.import_xml_text(xml_text, title=info.title,
-                slug=info.slug, previous_book=previous_book,
+            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
 
index 1b043a4..db52128 100755 (executable)
@@ -99,7 +99,7 @@ class Book(models.Model):
         # if there are more parts, set the rest to empty strings
         book_len = len(instance)
         for i in range(book_len - len(texts)):
-            texts.append(u'pusta część %d' % (i + 1), u'')
+            texts.append((u'pusta część %d' % (i + 1), u''))
 
         i = 0
         for i, (title, text) in enumerate(texts):
@@ -110,8 +110,8 @@ class Book(models.Model):
 
             if i < book_len:
                 chunk = instance[i]
-                chunk.slug = slug
-                chunk.title = title
+                chunk.slug = slug[:50]
+                chunk.title = title[:255]
                 chunk.save()
             else:
                 chunk = instance.add(slug, title, adjust_slug=True)
index e68b1c1..3ce2050 100755 (executable)
@@ -70,7 +70,7 @@ class Chunk(dvcs_models.Document):
             new_slug = self.book.make_chunk_slug(slug)
             try:
                 new_chunk = self.book.chunk_set.create(number=self.number+1,
-                    slug=new_slug, title=title, **kwargs)
+                    slug=new_slug[:50], title=title[:255], **kwargs)
             except IntegrityError:
                 pass
         return new_chunk