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 new method to get AT submission metadata #39

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions pyseed/seed_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,14 +1427,35 @@ def retrieve_at_building_and_update(self, audit_template_building_id: int, cycle

return response

def retrieve_at_submission_metadata(self, audit_template_submission_id: int) -> dict:
"""Connect to audit template and retrieve audit report json (metadata only) by submission ID

Args:
audit_template_submission_id (int): ID of the AT submission report (different than building ID)

Returns:
dict: Response from the SEED API
"""

# api/v3/audit_template/pk/get_submission
response = self.client.get(
None,
required_pk=False,
endpoint="audit_template_submission",
url_args={"PK": audit_template_submission_id},
report_format='json'
)

return response

def retrieve_at_submission_and_update(self, audit_template_submission_id: int, cycle_id: int, seed_id: int, report_format: str = 'pdf', filename: str = None) -> dict:
"""Connect to audit template and retrieve audit report by submission ID

Args:
audit_template_submission_id (int): ID of the AT submission report (different than building ID)
cycle_id (int): Cycle ID in SEED (needed for XML but not actually for PDF)
seed_id (int): PropertyView ID in SEED
file_format (str): pdf or xml report, defaults to pdf
file_format (str): pdf, or xml report, defaults to pdf
filename (str): filename to use to upload to SEED

Returns:
Expand All @@ -1443,7 +1464,7 @@ def retrieve_at_submission_and_update(self, audit_template_submission_id: int, c
"""

# api/v3/audit_template/pk/get_submission
# accepts pdf or xml
# accepts pdf, xml
response = self.client.get(
None,
required_pk=False,
Expand All @@ -1454,6 +1475,7 @@ def retrieve_at_submission_and_update(self, audit_template_submission_id: int, c

if response['status'] == 'success':
if report_format.lower() == 'pdf':
# for PDF, store pdf report as inventory document
pdf_file = response['content']
if not filename:
filename = 'at_submission_report_' + str(audit_template_submission_id) + '.pdf'
Expand All @@ -1470,7 +1492,7 @@ def retrieve_at_submission_and_update(self, audit_template_submission_id: int, c
)
response2['pdf_report'] = pdf_file
else:
# assume XML
# assume XML. for XML, update property with BuildingSync
# now post to api/v3/properties/PK/update_with_buildingsync
xml_file = response['content']
if not filename:
Expand Down