Skip to content

Commit

Permalink
πŸ§‘β€πŸ’»(backend) debug view for unicamp contract template
Browse files Browse the repository at this point in the history
To ease the life of our developers, we added a debug view to preview
the contract unicamp template through the browser. The previous url
is now used to preview the default contract template.
  • Loading branch information
jonathanreveille committed Dec 10, 2024
1 parent 444bad0 commit 53bd3f3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/backend/joanie/debug/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from joanie.debug.views import (
DebugCertificateTemplateView,
DebugContractTemplateView,
DebugContractUnicampTemplateView,
DebugDegreeTemplateView,
DebugInvoiceTemplateView,
DebugMailAllInstallmentPaidViewHtml,
Expand Down Expand Up @@ -44,6 +45,11 @@
DebugDegreeTemplateView.as_view(),
name="debug.certificate_definition.degree",
),
path(
"__debug__/pdf-templates/contract-unicamp",
DebugContractUnicampTemplateView.as_view(),
name="debug.contract_unicamp.definition",
),
path(
"__debug__/pdf-templates/contract",
DebugContractTemplateView.as_view(),
Expand Down
25 changes: 25 additions & 0 deletions src/backend/joanie/debug/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from joanie.core.enums import (
CERTIFICATE,
CONTRACT_DEFINITION_DEFAULT,
CONTRACT_DEFINITION_UNICAMP,
DEGREE,
ORDER_STATE_PENDING_PAYMENT,
PAYMENT_STATE_PAID,
Expand Down Expand Up @@ -349,6 +350,30 @@ def get_basic_document_context(self):
return context


class DebugContractUnicampTemplateView(DebugPdfTemplateView):
"""
Debug view to check the layout of "contract_definition_unicamp" template of a Contract.
"""

model = Contract
issuer_document = CONTRACT_DEFINITION_UNICAMP

def get_document_context(self, pk=None):
"""
Build a realistic context to have data similar to a real document generated.
If a primary key (pk) is provided, retrieve the corresponding Contract and its definition's
context. If the Contract does not exist, we will use a basic fallback for the document
context. Otherwise, if no primary key is provided, we return the basic fallback document
context.
"""
if not pk:
return contract_definition.generate_document_context()

contract = Contract.objects.get(pk=pk, definition__name=self.issuer_document)

return contract.context


class DebugContractTemplateView(DebugPdfTemplateView):
"""
Debug view to check the layout of "contract_definition_default" template of a Contract.
Expand Down

0 comments on commit 53bd3f3

Please sign in to comment.