-
Notifications
You must be signed in to change notification settings - Fork 54
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
Audit Template Report Submission Endpoint #4411
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
178f9b2
endpoint for AT submission pdf report download
kflemin cd4c1fb
fix upload at submission endpoint
kflemin 1111f3e
add test
kflemin 8358584
update swagger to support downloading AT pdf or xml.
nllong 6b55ce9
fix typing
nllong 0143645
Merge branch 'develop' into 179d_at_submissions
nllong 8880b02
spelling
nllong 457eb7d
Merge branch '179d_at_submissions' of github.com:SEED-platform/seed i…
nllong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,7 +133,7 @@ def health_check(request): | |
celery_status = False | ||
|
||
try: | ||
redis_status = not cache.has_key('redis-ping') | ||
redis_status = 'redis-ping' not in cache | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
except Exception: | ||
redis_status = False | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,57 @@ | |
|
||
|
||
class AuditTemplateViewSet(viewsets.ViewSet, OrgMixin): | ||
@swagger_auto_schema(manual_parameters=[ | ||
AutoSchemaHelper.query_org_id_field(), | ||
AutoSchemaHelper.base_field( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my few updates to have swagger expose the correct info. |
||
name='id', | ||
location_attr='IN_PATH', | ||
type='TYPE_INTEGER', | ||
required=True, | ||
description='Audit Template Submission ID.'), | ||
AutoSchemaHelper.query_string_field('report_format', False, 'Report format Valid values are: xml, pdf. Defaults to pdf.') | ||
]) | ||
@has_perm_class('can_view_data') | ||
@action(detail=True, methods=['GET']) | ||
def get_submission(self, request, pk): | ||
""" | ||
Fetches a Report Submission (XML or PDF) from Audit Template (only) | ||
""" | ||
# get report format or default to pdf | ||
default_report_format = 'pdf' | ||
report_format = request.query_params.get('report_format', default_report_format) | ||
|
||
valid_file_formats = ['xml', 'pdf'] | ||
if report_format.lower() not in valid_file_formats: | ||
message = f"The report_format specified is invalid. Must be one of: {valid_file_formats}." | ||
return JsonResponse({ | ||
'success': False, | ||
'message': message | ||
}, status=400) | ||
|
||
# retrieve report | ||
at = AuditTemplate(self.get_organization(self.request)) | ||
response, message = at.get_submission(pk, report_format) | ||
|
||
if response is None: | ||
return JsonResponse({ | ||
'success': False, | ||
'message': message | ||
}, status=400) | ||
if report_format.lower() == 'xml': | ||
return HttpResponse(response.text) | ||
else: | ||
response2 = HttpResponse(response.content) | ||
response2.headers["Content-Type"] = 'application/pdf' | ||
response2.headers["Content-Disposition"] = f'attachment; filename="at_submission_{pk}.pdf"' | ||
return response2 | ||
|
||
@swagger_auto_schema(manual_parameters=[AutoSchemaHelper.query_org_id_field()]) | ||
@has_perm_class('can_view_data') | ||
@action(detail=True, methods=['GET']) | ||
def get_building_xml(self, request, pk): | ||
""" | ||
Fetches a Building XML for an Audit Template property and updates the corresponding PropertyView | ||
Fetches a Building XML for an Audit Template property (only) | ||
""" | ||
at = AuditTemplate(self.get_organization(self.request)) | ||
response, message = at.get_building(pk) | ||
|
@@ -145,7 +189,7 @@ def get_buildings(self, request): | |
at = AuditTemplate(org) | ||
result = at.get_buildings(cycle_id) | ||
|
||
if type(result) is tuple: | ||
if isinstance(result, tuple): | ||
return JsonResponse({ | ||
'success': False, | ||
'message': result[1] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
silly python thing...