From 78740a1952feb33c18604bbb996d3b00dfdfbf76 Mon Sep 17 00:00:00 2001 From: goose-life <32566441+goose-life@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:53:58 +0200 Subject: [PATCH] update the matrix correctly when adjusting tables; add tests --- indigo_api/exporters.py | 12 +- .../pdf_fixtures/tables/bad_spans_in.xml | 509 +++++++++ .../pdf_fixtures/tables/bad_spans_out.xml | 509 +++++++++ indigo_api/tests/pdf_fixtures/tables_in.xml | 509 +++++++++ indigo_api/tests/pdf_fixtures/tables_out.xml | 976 ++++++++++++++++++ 5 files changed, 2510 insertions(+), 5 deletions(-) diff --git a/indigo_api/exporters.py b/indigo_api/exporters.py index 3a496b9f1..7ca74176c 100644 --- a/indigo_api/exporters.py +++ b/indigo_api/exporters.py @@ -403,18 +403,20 @@ def resize_tables(self, doc): for x in range(missing_cells): log.debug(f"Adding missing cell in table {table.get('eId')} on row {y+1}") row.append(doc.maker('td')) - # update the matrix - matrix[y][len(matrix[y])] = True + # update the matrix + for x in range(n_cols): + matrix[y][x] = True # add colgroup element with each column and its width column_widths = [0 for _ in range(n_cols)] # offset also needs to take rowspans into account: update the matrix to be False for co-ordinates where # a cell is not expected because of a rowspan on a previous cell for y, row in enumerate(table.xpath('a:tr', namespaces={'a': doc.namespace})): + offset = 0 for x, cell in enumerate(row.xpath('a:th|a:td', namespaces={'a': doc.namespace})): - offset = 0 - if not matrix[y][x]: - offset += 1 + # take colspan into account to set False on the correct cell in the matrix + colspan = int(cell.get('colspan', '1')) + offset += colspan - 1 rowspan = int(cell.get('rowspan', '1')) if rowspan > 1: for r in range(rowspan - 1): diff --git a/indigo_api/tests/pdf_fixtures/tables/bad_spans_in.xml b/indigo_api/tests/pdf_fixtures/tables/bad_spans_in.xml index 1919d42b2..a4bcc3cf3 100644 --- a/indigo_api/tests/pdf_fixtures/tables/bad_spans_in.xml +++ b/indigo_api/tests/pdf_fixtures/tables/bad_spans_in.xml @@ -38,6 +38,515 @@ +
+ Address of Department +(To be completed by an official) + |
+ + + | ++ + | +||||||
+ Reference number +(To be completed by an official) + |
+ + + | +|||||||
+ Complete this form by using BLOCK letters and by ticking the appropriate boxes. + |
+ ||||||||
+ Part A: Applications in terms of the Act + |
+ ||||||||
+ Land development +Section 53(2) of the Act and regulations 10(4) and 12) + |
+
+ Y + |
+
+ N + |
+
+ If yes, complete all parts, except part H, of this application form. + |
+ |||||
+ Amendment of land development approval +(Section 53(2) of the Act and regulations 10(5) and 12) + |
+
+ Y + |
+
+ N + |
+
+ If yes, complete all parts, except part H, of this application form. + |
+ |||||
+ Extension of validity period +(Section 57(2) of the Act and regulation 28) + |
+
+ Y + |
+
+ N + |
+
+ If yes, complete all parts, except part G, of this application form. + |
+ |||||
+ Part B: Applicant details + |
+ ||||||||
+ First name(s) + |
+ + + | +|||||||
+ Surname + |
+ + + | +|||||||
+ Company name (If applicable) + |
+ + + | +|||||||
+ Postal address + |
+ + + | +
+ Postal code + |
+ + + | +|||||
+ |
+ + + | +|||||||
+ Tel. + |
+
+ Fax + |
+ + + | +
+ Cell. + |
+ + + | +
+ Part C: Details of owner(s)(If different from applicant) + |
+ |||||||||||||||||
+ Full name(s) + |
+ + + | +||||||||||||||||
+ Physical address(es) + |
+ + + | ++ + | +|||||||||||||||
+ + | +
+ Postal code + |
+ + + | +|||||||||||||||
+ |
+ + + | +||||||||||||||||
+ Tel. + |
+ + + | +
+ Fax + |
+
+ Cell. + |
+ + + | +|||||||||||||
+ Part D: Property details (In accordance with title deed) + |
+ |||||||||||||||||
+ Property description (Number(s) of Erf/ Erven/Portion(s) or Farm(s)) + |
+ + + | +||||||||||||||||
+ Physical address + |
+ + + | +
+ Town/City + |
+ + + | +||||||||||||||
+ Current zoning + |
+ + + | +
+ Extent + |
+
+ m²/ ha + |
+
+ Are there existing buildings? + |
+
+ Y + |
+
+ N + |
+ |||||||||||
+ Current land use + |
+ + + | +||||||||||||||||
+ Title deed number and date + |
+
+ T + |
+ + + | +|||||||||||||||
+ Any restrictive conditions? + |
+
+ Y + |
+
+ N + |
+
+ If yes, list conditions + |
+ + + | +|||||||||||||
+ Is the property encumbered by a bond? + |
+
+ Y + |
+
+ N + |
+
+ If yes, list bondholder(s) + |
+ + + | +|||||||||||||
+ Part E: Pre-application consultation (regulation 11) + |
+ |||||||||||||||||
+ Has there been any pre-application consultation? + |
+
+ Y + |
+
+ N + |
+
+ If yes, complete the information below and attach the minutes of the pre-application consultation. + |
+ ||||||||||||||
+ Official’s name + |
+
+ Reference Number + |
+
+ Date of consultation + |
+
+ Address of Department +(To be completed by an official) + |
+ + + | +||||||||
+ Reference number +(To be completed by an official) + |
+ + + | +||||||||
+ Complete this form using BLOCK letters and ticking the appropriate boxes. + |
+ |||||||||
+ Note: +An appeal to the Provincial Minister must be submitted within 21 days of the date of notification of the decision. + |
+ |||||||||
+ Part A: Appeal + |
+ |||||||||
+ Are you appealing against the decision of the Head of Department? + |
+
+ Y + |
+
+ N + |
+ + + | +||||||
+ Are you appealing against a condition of approval imposed by the Head of Department? + |
+
+ Y + |
+
+ N + |
+
+ If yes, list condition(s) in Part F + |
+ ||||||
+ Are you are appealing because your rights have been affected by the failure of the Head of Department to decide on your application within the prescribed period? + |
+
+ Y + |
+
+ N + |
+ + + | +||||||
+ Date of decision + |
+
+ DD/MM/YYYY + |
+
+ Date of notification + |
+
+ DD/MM/YYYY + |
+ ||||||
+ Part B: Appellant's details + |
+ |||||||||
+ First name(s) + |
+ + + | +||||||||
+ Surname + |
+ + + | +||||||||
+ Company or legal person's name (If applicable) + |
+ + + | +||||||||
+ Physical address + |
+ + + | +||||||||
+ Postal address (If different from physical address) + |
+ + + | +
+ Postal code + |
+ + + | +||||||
+ |
+ + + | +||||||||
+ Tel. + |
+
+ Fax + |
+ + + | +
+ Cell. + |
+ + + | +