Now importing a book that already exists in our database doesn't duplicate it's fragm...
authorMarek Stępniowski <marek@stepniowski.com>
Mon, 22 Sep 2008 15:46:49 +0000 (17:46 +0200)
committerMarek Stępniowski <marek@stepniowski.com>
Mon, 22 Sep 2008 15:46:49 +0000 (17:46 +0200)
apps/catalogue/models.py
wolnelektury/settings.py

index b658676..133440b 100644 (file)
@@ -202,7 +202,8 @@ class Book(models.Model):
                 short_text = ''
                 if (len(MarkupString(text)) > 240):
                     short_text = unicode(MarkupString(text)[:160])
                 short_text = ''
                 if (len(MarkupString(text)) > 240):
                     short_text = unicode(MarkupString(text)[:160])
-                new_fragment = Fragment(text=text, short_text=short_text, anchor=fragment.id, book=book)
+                new_fragment, created = Fragment.objects.get_or_create(anchor=fragment.id, book=book, 
+                    defaults={'text': text, 'short_text': short_text})
                 
                 try:
                     theme_names = [s.strip() for s in fragment.themes.split(',')]
                 
                 try:
                     theme_names = [s.strip() for s in fragment.themes.split(',')]
index 3afa9dd..ab9a40f 100644 (file)
@@ -77,8 +77,8 @@ MIDDLEWARE_CLASSES = [
 ]
 
 # If DEBUG is enabled add query log to bottom of every template
 ]
 
 # If DEBUG is enabled add query log to bottom of every template
-if DEBUG:
-    MIDDLEWARE_CLASSES.append('middleware.ProfileMiddleware')
+if DEBUG:
+    MIDDLEWARE_CLASSES.append('middleware.ProfileMiddleware')
 
 ROOT_URLCONF = 'urls'
 
 
 ROOT_URLCONF = 'urls'