-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add convert html to judgment #2048
Conversation
Test Results50 tests +48 50 ✅ +48 11s ⏱️ +11s Results for commit babc4d3. ± Comparison against base commit 8506c15. This pull request removes 2 and adds 50 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
peachjam/models/judgment.py
Outdated
@@ -441,6 +445,22 @@ def pre_save(self): | |||
self.assign_title() | |||
super().pre_save() | |||
|
|||
def convert_html_to_pdf(self): | |||
with NamedTemporaryFile(suffix=".html") as html_file: | |||
html_file.write(self.content_html.encode("utf-8")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you do something like html_file.write(self.prepare_content_html_for_pdf())
so that subclasses can override the HTML that is used to generate the PDF, such as by adding a logo at the top.
Also, I think this can safely all be done on the CoreDocument object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, done
peachjam/tasks.py
Outdated
@@ -206,6 +206,19 @@ def convert_source_file_to_pdf(source_file_id): | |||
log.info("Conversion to PDF done") | |||
|
|||
|
|||
@background(queue="peachjam", remove_existing_tasks=True) | |||
def convert_html_to_pdf(judgment_id): | |||
from peachjam.models import Judgment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should work for any file, not just judgment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
This adds the convert html to pdf method to the judgment model