+ if rev_pk is None:
+ if preview:
+ revision = doc.revision
+ else:
+ if published_revision is not None:
+ revision = published_revision
+ else:
+ # No published version, fallback to preview mode.
+ preview = True
+ revision = doc.revision
+ else:
+ revision = get_object_or_404(Revision, pk=rev_pk)
+
+ was_published = revision == published_revision or doc.publish_log.filter(revision=revision).exists()
+
+ sst = SST.from_string(revision.materialize())
+ html = HtmlFormat(sst).build(
+ files_path='http://%s/media/dynamic/uploads/%s/' % (request.get_host(), pk)).get_string()
+
+ # response = http.HttpResponse(html, content_type='text/html', mimetype='text/html')
+ # return response
+ # book_themes = {}
+ # for fragment in book.fragments.all().iterator():
+ # for theme in fragment.tags.filter(category='theme').iterator():
+ # book_themes.setdefault(theme, []).append(fragment)
+
+ # book_themes = book_themes.items()
+ # book_themes.sort(key=lambda s: s[0].sort_key)
+ return render(request, 'catalogue/book_text.html', {
+ 'doc': doc,
+ 'preview': preview,
+ 'revision': revision,
+ 'published_revision': published_revision,
+ 'specific': rev_pk is not None,
+ 'html': html,
+ 'can_edit': doc.can_edit(request.user) if doc else None,
+ 'was_published': was_published,