Skip to content

Commit

Permalink
Break out AuditInfoFormView into its own file (#2971)
Browse files Browse the repository at this point in the history
* Break out AuditInfoFormView into its own file.

* Minor corrections for moving AuditInfoFormView into its own file.
  • Loading branch information
tadhg-ohiggins authored Dec 18, 2023
1 parent 8334fb1 commit 8e3281d
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 127 deletions.
5 changes: 3 additions & 2 deletions backend/audit/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .audit_info_form_view import AuditInfoFormView
from .home import Home
from .manage_submission import ManageSubmissionView
from .manage_submission_access import (
Expand All @@ -21,7 +22,6 @@
from .views import (
AuditeeCertificationStep1View,
AuditeeCertificationStep2View,
AuditInfoFormView,
AuditorCertificationStep1View,
AuditorCertificationStep2View,
CertificationView,
Expand All @@ -35,7 +35,8 @@
)

# In case we want to iterate through all the views for some reason:
views = [
views_list = [
AuditInfoFormView,
AuditeeCertificationStep1View,
AuditeeCertificationStep2View,
AuditInfoFormView,
Expand Down
137 changes: 137 additions & 0 deletions backend/audit/views/audit_info_form_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import logging
from django.core.exceptions import BadRequest, PermissionDenied
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views import generic
from audit.forms import AuditInfoForm
from audit.mixins import SingleAuditChecklistAccessRequiredMixin
from audit.models import SingleAuditChecklist, SubmissionEvent
from audit.validators import validate_audit_information_json
from config.settings import (
AGENCY_NAMES,
GAAP_RESULTS,
SP_FRAMEWORK_BASIS,
SP_FRAMEWORK_OPINIONS,
)

logging.basicConfig(
format="%(asctime)s %(levelname)-8s %(module)s:%(lineno)d %(message)s"
)
logger = logging.getLogger(__name__)


class AuditInfoFormView(SingleAuditChecklistAccessRequiredMixin, generic.View):
def get(self, request, *args, **kwargs):
report_id = kwargs["report_id"]
try:
sac = SingleAuditChecklist.objects.get(report_id=report_id)
current_info = {}
if sac.audit_information:
current_info = {
"cleaned_data": {
"gaap_results": sac.audit_information.get("gaap_results"),
"sp_framework_basis": sac.audit_information.get(
"sp_framework_basis"
),
"is_sp_framework_required": sac.audit_information.get(
"is_sp_framework_required"
),
"sp_framework_opinions": sac.audit_information.get(
"sp_framework_opinions"
),
"is_going_concern_included": sac.audit_information.get(
"is_going_concern_included"
),
"is_internal_control_deficiency_disclosed": sac.audit_information.get(
"is_internal_control_deficiency_disclosed"
),
"is_internal_control_material_weakness_disclosed": sac.audit_information.get(
"is_internal_control_material_weakness_disclosed"
),
"is_material_noncompliance_disclosed": sac.audit_information.get(
"is_material_noncompliance_disclosed"
),
"is_aicpa_audit_guide_included": sac.audit_information.get(
"is_aicpa_audit_guide_included"
),
"dollar_threshold": sac.audit_information.get(
"dollar_threshold"
),
"is_low_risk_auditee": sac.audit_information.get(
"is_low_risk_auditee"
),
"agencies": sac.audit_information.get("agencies"),
}
}

context = self._get_context(sac, current_info)

return render(request, "audit/audit-info-form.html", context)
except SingleAuditChecklist.DoesNotExist:
raise PermissionDenied("You do not have access to this audit.")
except Exception as e:
logger.info("Unexpected error in AuditInfoFormView get.\n%s", e)
raise BadRequest()

def post(self, request, *args, **kwargs):
report_id = kwargs["report_id"]

try:
sac = SingleAuditChecklist.objects.get(report_id=report_id)
form = AuditInfoForm(request.POST)

if form.is_valid():
form.clean_booleans()
# List of keys to delete if "not_gaap" not in form.cleaned_data["gaap_results"]
keys_to_delete = [
"sp_framework_basis",
"is_sp_framework_required",
"sp_framework_opinions",
]

if "not_gaap" not in form.cleaned_data["gaap_results"]:
for key in keys_to_delete:
form.cleaned_data.pop(key, None)

validated = validate_audit_information_json(form.cleaned_data)

sac.audit_information = validated
sac.save(
event_user=request.user,
event_type=SubmissionEvent.EventType.AUDIT_INFORMATION_UPDATED,
)
return redirect(reverse("audit:SubmissionProgress", args=[report_id]))
else:
for field, errors in form.errors.items():
for error in errors:
logger.warn(f"ERROR in field {field} : {error}")

form.clean_booleans()
context = self._get_context(sac, form)
return render(request, "audit/audit-info-form.html", context)

except SingleAuditChecklist.DoesNotExist:
raise PermissionDenied("You do not have access to this audit.")
except Exception as e:
logger.info("Enexpected error in AuditInfoFormView post.\n%s", e)
raise BadRequest()

def _get_context(self, sac, form):
context = {
"auditee_name": sac.auditee_name,
"report_id": sac.report_id,
"auditee_uei": sac.auditee_uei,
"user_provided_organization_type": sac.user_provided_organization_type,
"agency_names": AGENCY_NAMES,
"gaap_results": GAAP_RESULTS,
"sp_framework_basis": SP_FRAMEWORK_BASIS,
"sp_framework_opinions": SP_FRAMEWORK_OPINIONS,
}
for field, value in context.items():
logger.warn(f"{field}:{value}")
context.update(
{
"form": form,
}
)
return context
125 changes: 0 additions & 125 deletions backend/audit/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
from django.utils.decorators import method_decorator
from django.http import JsonResponse

from config.settings import (
AGENCY_NAMES,
GAAP_RESULTS,
SP_FRAMEWORK_BASIS,
SP_FRAMEWORK_OPINIONS,
)
from audit.fixtures.excel import FORM_SECTIONS, UNKNOWN_WORKBOOK

from audit.intakelib import (
Expand All @@ -30,7 +24,6 @@
extract_notes_to_sefa,
)
from audit.forms import (
AuditInfoForm,
AuditorCertificationStep1Form,
AuditorCertificationStep2Form,
AuditeeCertificationStep1Form,
Expand All @@ -53,7 +46,6 @@
from audit.validators import (
validate_additional_ueis_json,
validate_additional_eins_json,
validate_audit_information_json,
validate_auditee_certification_json,
validate_auditor_certification_json,
validate_corrective_action_plan_json,
Expand Down Expand Up @@ -733,121 +725,4 @@ def post(self, request, *args, **kwargs):
raise PermissionDenied("You do not have access to this audit.")


class AuditInfoFormView(SingleAuditChecklistAccessRequiredMixin, generic.View):
def get(self, request, *args, **kwargs):
report_id = kwargs["report_id"]
try:
sac = SingleAuditChecklist.objects.get(report_id=report_id)
current_info = {}
if sac.audit_information:
current_info = {
"cleaned_data": {
"gaap_results": sac.audit_information.get("gaap_results"),
"sp_framework_basis": sac.audit_information.get(
"sp_framework_basis"
),
"is_sp_framework_required": sac.audit_information.get(
"is_sp_framework_required"
),
"sp_framework_opinions": sac.audit_information.get(
"sp_framework_opinions"
),
"is_going_concern_included": sac.audit_information.get(
"is_going_concern_included"
),
"is_internal_control_deficiency_disclosed": sac.audit_information.get(
"is_internal_control_deficiency_disclosed"
),
"is_internal_control_material_weakness_disclosed": sac.audit_information.get(
"is_internal_control_material_weakness_disclosed"
),
"is_material_noncompliance_disclosed": sac.audit_information.get(
"is_material_noncompliance_disclosed"
),
"is_aicpa_audit_guide_included": sac.audit_information.get(
"is_aicpa_audit_guide_included"
),
"dollar_threshold": sac.audit_information.get(
"dollar_threshold"
),
"is_low_risk_auditee": sac.audit_information.get(
"is_low_risk_auditee"
),
"agencies": sac.audit_information.get("agencies"),
}
}

context = self._get_context(sac, current_info)

return render(request, "audit/audit-info-form.html", context)
except SingleAuditChecklist.DoesNotExist:
raise PermissionDenied("You do not have access to this audit.")
except Exception as e:
logger.info("Enexpected error in AuditInfoFormView get.\n", e)
raise BadRequest()

def post(self, request, *args, **kwargs):
report_id = kwargs["report_id"]

try:
sac = SingleAuditChecklist.objects.get(report_id=report_id)
form = AuditInfoForm(request.POST)

if form.is_valid():
form.clean_booleans()
# List of keys to delete if "not_gaap" not in form.cleaned_data["gaap_results"]
keys_to_delete = [
"sp_framework_basis",
"is_sp_framework_required",
"sp_framework_opinions",
]

if "not_gaap" not in form.cleaned_data["gaap_results"]:
for key in keys_to_delete:
form.cleaned_data.pop(key, None)

validated = validate_audit_information_json(form.cleaned_data)

sac.audit_information = validated
sac.save(
event_user=request.user,
event_type=SubmissionEvent.EventType.AUDIT_INFORMATION_UPDATED,
)
return redirect(reverse("audit:SubmissionProgress", args=[report_id]))
else:
for field, errors in form.errors.items():
for error in errors:
logger.warn(f"ERROR in field {field} : {error}")

form.clean_booleans()
context = self._get_context(sac, form)
return render(request, "audit/audit-info-form.html", context)

except SingleAuditChecklist.DoesNotExist:
raise PermissionDenied("You do not have access to this audit.")
except Exception as e:
logger.info("Enexpected error in AuditInfoFormView post.\n", e)
raise BadRequest()

def _get_context(self, sac, form):
context = {
"auditee_name": sac.auditee_name,
"report_id": sac.report_id,
"auditee_uei": sac.auditee_uei,
"user_provided_organization_type": sac.user_provided_organization_type,
"agency_names": AGENCY_NAMES,
"gaap_results": GAAP_RESULTS,
"sp_framework_basis": SP_FRAMEWORK_BASIS,
"sp_framework_opinions": SP_FRAMEWORK_OPINIONS,
}
for field, value in context.items():
logger.warn(f"{field}:{value}")
context.update(
{
"form": form,
}
)
return context


# 2023-08-22 DO NOT ADD ANY FURTHER CODE TO THIS FILE; ADD IT IN viewlib AS WITH UploadReportView

0 comments on commit 8e3281d

Please sign in to comment.