+ save_form = forms.DocumentTextSaveForm(user=request.user, chunk=chunk, prefix="textsave")
+ try:
+ version = int(request.GET.get('version', ''))
+ except ValueError:
+ version = None
+ if version:
+ text = chunk.at_revision(version).materialize()
+ else:
+ text = chunk.materialize()
+ gallery_dir = os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, chunk.book.gallery)
+ materials = set(os.listdir(gallery_dir)) if os.path.isdir(gallery_dir) else set()
+ materials.update([n.rsplit('.', 1)[0] for n in materials])
+ return render(request, template_name, {
+ 'serialized_document_data': json.dumps({
+ 'document': text,
+ 'document_id': chunk.id,
+ 'title': chunk.book.title,
+ 'history': get_history(chunk),
+ 'version': version or chunk.revision(),
+ 'stage': chunk.stage.name if chunk.stage else None,
+ 'assignment': chunk.user.username if chunk.user else None
+ }),
+ 'serialized_templates': json.dumps([
+ {'id': t.id, 'name': t.name, 'content': t.content} for t in Template.objects.filter(is_partial=True)
+ ]),