def element_to_html(self, element): """ Render a child element of this document into HTML. """ from indigo_api.exporters import HTMLExporter exporter = HTMLExporter() exporter.media_url = reverse('document-detail', kwargs={'pk': self.id }) + '/' return exporter.render(self, element=element)
def post(self, request, document_id): serializer = RenderSerializer(instance=self.document, data=request.data) serializer.is_valid(raise_exception=True) document = DocumentSerializer().update_document( self.document, validated_data=serializer.validated_data['document']) if self.coverpage_only: renderer = HTMLExporter() renderer.media_url = reverse('document-detail', kwargs={'pk': document.id}) + '/' html = renderer.render_coverpage(document) return Response({'output': html}) else: return Response({'output': document.to_html()})
def post(self, request, format=None): serializer = RenderSerializer(data=request.data) serializer.is_valid(raise_exception=True) document = DocumentSerializer().update_document( Document(), validated_data=serializer.validated_data['document']) # the serializer ignores the id field, but we need it for rendering document.id = serializer.initial_data['document'].get('id') if self.coverpage_only: renderer = HTMLExporter() renderer.media_url = reverse('document-detail', kwargs={'pk': document.id}) + '/' html = renderer.render_coverpage(document) return Response({'output': html}) else: return Response({'output': document.to_html()})
def to_html(self, **kwargs): from indigo_api.exporters import HTMLExporter exporter = HTMLExporter() exporter.media_url = reverse('document-detail', kwargs={'pk': self.id }) + '/' return exporter.render(self, **kwargs)