🏷️(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

@@ -361,17 +361,21 @@ class Template(BaseModel):
"retrieve": can_get,
}
def generate_document(self, body):
def generate_document(self, body, body_type):
"""
Generate and return a PDF document for this template around the
markdown body passed as argument.
body passed as argument.
"""
document = frontmatter.loads(body)
metadata = document.metadata
markdown_body = document.content.strip()
body_html = (
markdown.markdown(textwrap.dedent(markdown_body)) if markdown_body else ""
)
strip_body = document.content.strip()
if body_type == "html":
body_html = strip_body
else:
body_html = (
markdown.markdown(textwrap.dedent(strip_body)) if strip_body else ""
)
document_html = HTML(
string=DjangoTemplate(self.code).render(