From cdf7839b638f11e89fdaf9d0797e40723f594a49 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Mon, 22 Sep 2008 17:46:49 +0200 Subject: [PATCH] Now importing a book that already exists in our database doesn't duplicate it's fragments. --- apps/catalogue/models.py | 3 ++- wolnelektury/settings.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index b6586763b..133440b3b 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -202,7 +202,8 @@ class Book(models.Model): 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(',')] diff --git a/wolnelektury/settings.py b/wolnelektury/settings.py index 3afa9dd68..ab9a40ff5 100644 --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@ -77,8 +77,8 @@ MIDDLEWARE_CLASSES = [ ] # 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' -- 2.20.1