Skip to content

Commit

Permalink
ensure title block fits on both a3 and a4 layouts. simplify code slig…
Browse files Browse the repository at this point in the history
…htly. rerun tests
  • Loading branch information
jgunstone committed Jul 24, 2024
1 parent 2e28cca commit 167f6ba
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 69 deletions.
110 changes: 49 additions & 61 deletions packages/document-issue-io/src/document_issue_io/title_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,100 +69,88 @@ def construct_title_block_data(
fpth_img=fpth_img, scale_height=scale_height, scale_width=scale_width
)
issue_date = document_issue.current_issue.date.strftime("%d/%m/%Y")
document_description = "\n".join(wrap(document_issue.document_description, 45))

wrap_len = 70 if is_a3 else 40
document_description = "\n".join(
wrap(document_issue.document_description, wrap_len)
)
name_nomenclature = document_issue.name_nomenclature.replace("-", " - ")
document_code = document_issue.document_code.replace("-", " - ")
status_description = document_issue.current_issue.status_description.replace(
"Suitable for ", ""
).replace("Issued for ", "")
# ^ TODO: Need to deal with length of status codes more robustly
(
project_name,
project_number,
director_in_charge,
status_code,
revision,
client_name,
) = (
document_issue.project_name,
document_issue.project_number,
document_issue.director_in_charge,
document_issue.current_issue.status_code,
document_issue.current_issue.revision,
document_issue.client_name,
)

data = [
[image, "", "project", "", "", "", "", "document description", "", "", "", ""],
[image, "project", "", "", "client", "document description"],
[
"",
"",
document_issue.project_name,
"",
"",
project_name,
"",
"",
client_name,
document_description,
],
["", "revision", "status code", "status description", "", ""],
[
"",
"",
revision,
status_code,
status_description,
"",
"",
],
[
"",
"",
"project number",
"director",
"issue date",
"",
"",
"",
"",
"",
"",
"",
],
[
"",
"",
document_issue.project_number,
document_issue.director_in_charge,
issue_date,
"",
"",
"",
"",
"",
"",
"",
],
[
"",
"",
"status code",
"revision",
"status description",
"",
"",
name_nomenclature,
"",
"",
"",
"",
],
[
"",
"",
document_issue.current_issue.status_code,
document_issue.current_issue.revision,
document_issue.current_issue.status_description.replace(
"Suitable for ", ""
).replace(
"Issued for ", ""
), # TODO: Need to deal with length of status codes more robustly
"",
project_number,
director_in_charge,
issue_date,
"",
document_code,
"",
"",
"",
"",
],
]
if is_a3:
data[0][4] = "client"
data[1][4] = document_issue.client_name
# data = [d[0:-3] for d in data]
# data = [d[0:5] + d[7:] for d in data]
for n, d in enumerate(data):
data[n] = [d[0]] + [""] + d[1:] # add empty cell for styling
data[n] = data[n] + [""] # must be 8 cols for styling to work...
assert len(data[n]) == 8

if not is_a3: # remove client name as it doesn't fit on A4
data[0][5] = ""
data[1][5] = ""

return data


def create_title_block_table(data: list, is_a3=False) -> Table:
"""Create the ReportLab table and set the styling."""
if is_a3:
table = Table(data, colWidths=[180] + ["*"] * 5)
table = Table(data, colWidths=[280] + [0] + [50] * 2 + [120] + ["*"])
else:
table = Table(data, colWidths="*")
table = Table(data, colWidths=[95] + [0] + [50] * 3 + ["*"])

styling = create_styling(len(data))
table.setStyle(TableStyle(styling))
return table
Expand Down
20 changes: 12 additions & 8 deletions packages/document-issue-io/tests/test_title_block.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from polyfactory.factories.pydantic_factory import ModelFactory

from document_issue.document_issue import DocumentIssue, DocumentRole, RoleEnum
from document_issue.document_issue import DocumentIssue, DocumentRole, RoleEnum, Issue
from document_issue.enums import StatusRevisionEnum
from document_issue_io.title_block import (
title_block_a4,
title_block_a3,
Expand All @@ -20,21 +20,25 @@ class DocumentIssueFactory(ModelFactory[DocumentIssue]):


def create_document_issue():
issue = Issue(status_revision=StatusRevisionEnum.A4_C)
document_issue = DocumentIssueFactory.build(
document_role=[DocumentRole(**{"role_name": RoleEnum.director, "name": "DR"})]
document_role=[DocumentRole(**{"role_name": RoleEnum.director, "name": "DR"})],
issue_history=[issue],
)
document_issue.project_name = (
"A Max Fordham Project:\nRotunda Refurbishment part 1 million"
)
document_issue.project_name = "A Max Fordham Project"
document_issue.client_name = "Max Fordham LLP Partnership"
document_issue.project_number = "J4321"
document_issue.document_role[0].initials = "OH"
document_issue.document_role[0].role_name = "Director in Charge"
document_issue.document_code = "06667-MXF-XX-XX-SH-M-20003"
document_issue.document_description = "A description of a Max Fordham Project"
document_issue.document_description = (
"A description of a Max Fordham Project can split lines but no more than two"
)
document_issue.name_nomenclature = (
"project-originator-volume-level-type-role-number"
)
document_issue.issue_history[0].revision = "P01"
document_issue.issue_history[0].status_code = "S2"
document_issue.issue_history[0].status_description = "Suitable for information"
return document_issue


Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified packages/document-issue-io/tests/testoutput/title-block-a3.pdf
Binary file not shown.
Binary file not shown.
Binary file modified packages/document-issue-io/tests/testoutput/title-block.pdf
Binary file not shown.
Binary file modified packages/document-issue-io/tests/testoutput/title-page.pdf
Binary file not shown.

0 comments on commit 167f6ba

Please sign in to comment.