- html.transform(book.xml_file.path, html_file)
- book.html_file.save('%s.html' % book.slug, File(html_file), save=False)
-
- # Extract fragments
- closed_fragments, open_fragments = html.extract_fragments(book.html_file.path)
- book_themes = []
- 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 = Fragment(text=text, short_text=short_text, anchor=fragment.id, book=book)
+ if html.transform(book.xml_file.path, html_file):
+ book.html_file.save('%s.html' % book.slug, File(html_file), save=False)
+
+ # Extract fragments
+ closed_fragments, open_fragments = html.extract_fragments(book.html_file.path)
+ book_themes = []
+ 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})