X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ea8925059c81175c3a432a006779764d65308ad8..90a3704b70f16b87bc17b3a1f2c6d497316c9019:/apps/catalogue/models.py?ds=sidebyside diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index a7e04f1a2..922828440 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -403,25 +403,30 @@ class Book(models.Model): # Extract fragments closed_fragments, open_fragments = html.extract_fragments(book.html_file.path) for fragment in closed_fragments.values(): - text = fragment.to_string() - short_text = '' - if (len(MarkupString(text)) > 240): - short_text = unicode(MarkupString(text)[:160]) - 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(',')] except AttributeError: continue themes = [] for theme_name in theme_names: + if not theme_name: + continue tag, created = Tag.objects.get_or_create(slug=slughifi(theme_name), category='theme') if created: tag.name = theme_name tag.sort_key = slughifi(theme_name) tag.save() themes.append(tag) + if not themes: + continue + + text = fragment.to_string() + short_text = '' + if (len(MarkupString(text)) > 240): + short_text = unicode(MarkupString(text)[:160]) + new_fragment, created = Fragment.objects.get_or_create(anchor=fragment.id, book=book, + defaults={'text': text, 'short_text': short_text}) + new_fragment.save() new_fragment.tags = set(book_tags + themes + [book_tag])