Skip to content
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

Merged
merged 3 commits into from
Sep 25, 2024
Merged

Add convert html to judgment #2048

merged 3 commits into from
Sep 25, 2024

Conversation

actlikewill
Copy link
Contributor

This adds the convert html to pdf method to the judgment model

Copy link

github-actions bot commented Sep 20, 2024

Test Results

50 tests  +48   50 ✅ +48   11s ⏱️ +11s
13 suites +12    0 💤 ± 0 
13 files   +12    0 ❌ ± 0 

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.
liiweb.tests.test_mnc_matcher.MncMatcherTest ‑ test_html_matches
liiweb.tests.test_mnc_matcher.MncMatcherTest ‑ test_za_provincial_matches
peachjam.tests.test_admin.TestJudgmentAdmin ‑ test_add_judgment_docx_swap_pdf
peachjam.tests.test_admin.TestJudgmentAdmin ‑ test_add_judgment_pdf_swap_docx
peachjam.tests.test_bulk_import.JudgmentBulkImportTestCase ‑ test_case_number_import_without_matter_type
peachjam.tests.test_bulk_import.JudgmentBulkImportTestCase ‑ test_case_numbers_with_matter_type
peachjam.tests.test_bulk_import.JudgmentBulkImportTestCase ‑ test_import_with_taxonomy
peachjam.tests.test_bulk_import.JudgmentBulkImportTestCase ‑ test_judgment_bulk_import
peachjam.tests.test_bulk_import.JudgmentBulkImportTestCase ‑ test_source_file_prefers_docx_over_pdf
peachjam.tests.test_citations.CitationAnalyserTestCase ‑ test_delete_citations
peachjam.tests.test_citations.CitationAnalyserTestCase ‑ test_delete_citations_should_not_change_akn
peachjam.tests.test_citations.CitationAnalyserTestCase ‑ test_pdf_extractions
…

♻️ This comment has been updated with latest results.

@actlikewill actlikewill marked this pull request as ready for review September 20, 2024 10:41
@@ -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"))
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@actlikewill actlikewill merged commit 264aa13 into main Sep 25, 2024
9 checks passed
@actlikewill actlikewill deleted the convert-html branch September 25, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants