🏷️(backend) add body type on generate-document endpoint

We were converting from markdown to html, but the
frontend can provide the body in html format, so
wa can avoid the conversion.

Solution:
Add body type on generate-document endpoint
to allow to choose between markdown and html.
This commit is contained in:
Anthony LC
2024-04-16 10:30:10 +02:00
committed by Anthony LC
parent f9705c6ce9
commit 1df7c43dd3
4 changed files with 83 additions and 8 deletions

View File

@@ -153,4 +153,10 @@ class TemplateSerializer(BaseResourceSerializer):
class DocumentGenerationSerializer(serializers.Serializer):
"""Serializer to receive a request to generate a document on a template."""
body = serializers.CharField(label=_("Markdown Body"))
body = serializers.CharField(label=_("Body"))
body_type = serializers.ChoiceField(
choices=["html", "markdown"],
label=_("Body type"),
required=False,
default="html",
)

View File

@@ -372,9 +372,10 @@ class TemplateViewSet(
)
body = serializer.validated_data["body"]
body_type = serializer.validated_data["body_type"]
template = self.get_object()
pdf_content = template.generate_document(body)
pdf_content = template.generate_document(body, body_type)
response = FileResponse(BytesIO(pdf_content), content_type="application/pdf")
response["Content-Disposition"] = f"attachment; filename={template.title}.pdf"