Initial solution and loggers

This commit is contained in:
Rachid Mrad 2024-01-30 19:16:56 -05:00
parent a9f522d076
commit 211a4b52cf
No known key found for this signature in database
2 changed files with 91 additions and 1 deletions

View file

@ -224,8 +224,10 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
if request.path_info == self.NEW_URL_NAME: if request.path_info == self.NEW_URL_NAME:
return render(request, "application_intro.html") return render(request, "application_intro.html")
else: else:
logger.info('get calling self.steps.first')
return self.goto(self.steps.first) return self.goto(self.steps.first)
logger.info('get setting current step')
self.steps.current = current_url self.steps.current = current_url
context = self.get_context_data() context = self.get_context_data()
context["forms"] = self.get_forms() context["forms"] = self.get_forms()
@ -254,6 +256,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
All arguments (**kwargs) are passed directly to `get_forms`. All arguments (**kwargs) are passed directly to `get_forms`.
""" """
logger.info('get_all_forms gettig steps in self.steps')
nested = (self.get_forms(step=step, **kwargs) for step in self.steps) nested = (self.get_forms(step=step, **kwargs) for step in self.steps)
flattened = [form for lst in nested for form in lst] flattened = [form for lst in nested for form in lst]
return flattened return flattened
@ -269,6 +272,8 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
and from the database if `use_db` is True (provided that record exists). and from the database if `use_db` is True (provided that record exists).
An empty form will be provided if neither of those are true. An empty form will be provided if neither of those are true.
""" """
logger.info('get_forms setting prefix to self.steps.current')
kwargs = { kwargs = {
"files": files, "files": files,
"prefix": self.steps.current, "prefix": self.steps.current,
@ -328,6 +333,66 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
DomainApplication.ApplicationStatus.ACTION_NEEDED, DomainApplication.ApplicationStatus.ACTION_NEEDED,
] ]
return DomainApplication.objects.filter(creator=self.request.user, status__in=check_statuses) return DomainApplication.objects.filter(creator=self.request.user, status__in=check_statuses)
def db_check_for_unlocking_steps(self):
unlocked_steps = {}
if self.application.organization_type:
unlocked_steps["organization_type"] = True
if self.application.tribe_name:
unlocked_steps["tribal_government"] = True
if self.application.federal_agency:
unlocked_steps["organization_federal"] = True
if self.application.is_election_board:
unlocked_steps["organization_election"] = True
if (
self.application.organization_name
or self.application.address_line1
or self.application.city
or self.application.state_territory
or self.application.zipcode
or self.application.urbanization
):
unlocked_steps["organization_contact"] = True
if self.application.about_your_organization:
unlocked_steps["about_your_organization"] = True
if self.application.authorizing_official:
unlocked_steps["authorizing_official"] = True
# Since this field is optional, test to see if the next step has been touched
if self.application.current_websites.exists() or self.application.requested_domain:
unlocked_steps["current_sites"] = True
if self.application.requested_domain:
unlocked_steps["dotgov_domain"] = True
if self.application.purpose:
unlocked_steps["purpose"] = True
if self.application.submitter:
unlocked_steps["your_contact"] = True
if self.application.other_contacts.exists() or self.application.no_other_contacts_rationale:
unlocked_steps["other_contacts"] = True
# Since this field is optional, test to see if the next step has been touched
if self.application.anything_else or self.application.is_policy_acknowledged:
unlocked_steps["anything_else"] = True
if self.application.is_policy_acknowledged:
unlocked_steps["requirements"] = True
if self.application.submission_date:
unlocked_steps["review"] = True
return unlocked_steps
def get_context_data(self): def get_context_data(self):
"""Define context for access on all wizard pages.""" """Define context for access on all wizard pages."""
@ -338,11 +403,17 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
modal_heading = "You are about to submit a domain request for " + str(self.application.requested_domain) modal_heading = "You are about to submit a domain request for " + str(self.application.requested_domain)
else: else:
modal_heading = "You are about to submit an incomplete request" modal_heading = "You are about to submit an incomplete request"
logger.info(f'get_context_data returning value for cisited equals to: {self.storage.get("step_history", [])}')
unlocked_steps_list = list(self.db_check_for_unlocking_steps().keys())
return { return {
"form_titles": self.TITLES, "form_titles": self.TITLES,
"steps": self.steps, "steps": self.steps,
# Add information about which steps should be unlocked # Add information about which steps should be unlocked
"visited": self.storage.get("step_history", []), "visited": unlocked_steps_list,
"is_federal": self.application.is_federal(), "is_federal": self.application.is_federal(),
"modal_button": modal_button, "modal_button": modal_button,
"modal_heading": modal_heading, "modal_heading": modal_heading,
@ -360,6 +431,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
return step_list return step_list
def goto(self, step): def goto(self, step):
logger.info(f'goto sets self.steps.current to passed {step}')
self.steps.current = step self.steps.current = step
return redirect(reverse(f"{self.URL_NAMESPACE}:{step}")) return redirect(reverse(f"{self.URL_NAMESPACE}:{step}"))
@ -368,6 +440,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
next = self.steps.next next = self.steps.next
if next: if next:
self.steps.current = next self.steps.current = next
logger.info(f'goto sets self.goto_next_step.current to passed {self.steps.next}')
return self.goto(next) return self.goto(next)
else: else:
raise Http404() raise Http404()
@ -387,6 +460,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
if button == "intro_acknowledge": if button == "intro_acknowledge":
if request.path_info == self.NEW_URL_NAME: if request.path_info == self.NEW_URL_NAME:
del self.storage del self.storage
logger.info(f'post calling goto with {self.steps.first}')
return self.goto(self.steps.first) return self.goto(self.steps.first)
# if accessing this class directly, redirect to the first step # if accessing this class directly, redirect to the first step
@ -406,6 +480,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
# return them to the page they were already on # return them to the page they were already on
if button == "save": if button == "save":
messages.success(request, "Your progress has been saved!") messages.success(request, "Your progress has been saved!")
logger.info(f'post calling goto with {self.steps.current}')
return self.goto(self.steps.current) return self.goto(self.steps.current)
# if user opted to save progress and return, # if user opted to save progress and return,
# return them to the home page # return them to the home page

View file

@ -44,28 +44,35 @@ class StepsHelper:
""" """
def __init__(self, wizard): def __init__(self, wizard):
logger.info(f"steps_helper __init__")
self._wizard = wizard self._wizard = wizard
def __dir__(self): def __dir__(self):
logger.info(f"steps_helper __dir__ {self.all}")
return self.all return self.all
def __len__(self): def __len__(self):
logger.info(f"steps_helper __len__ {self.count}")
return self.count return self.count
def __repr__(self): def __repr__(self):
logger.info(f"steps_helper __repr__ {self._wizard} {self.all}")
return "<StepsHelper for %s (steps: %s)>" % (self._wizard, self.all) return "<StepsHelper for %s (steps: %s)>" % (self._wizard, self.all)
def __getitem__(self, step): def __getitem__(self, step):
logger.info(f"steps_helper __getitem__ {self.all[step]}")
return self.all[step] return self.all[step]
@property @property
def all(self): def all(self):
"""Returns the names of all steps.""" """Returns the names of all steps."""
logger.info(f"steps_helper all {self._wizard.get_step_list()}")
return self._wizard.get_step_list() return self._wizard.get_step_list()
@property @property
def count(self): def count(self):
"""Returns the total number of steps/forms in this the wizard.""" """Returns the total number of steps/forms in this the wizard."""
logger.info(f"steps_helper count {len(self.all)}")
return len(self.all) return len(self.all)
@property @property
@ -79,12 +86,14 @@ class StepsHelper:
current_url = resolve(self._wizard.request.path_info).url_name current_url = resolve(self._wizard.request.path_info).url_name
step = current_url if current_url in self.all else self.first step = current_url if current_url in self.all else self.first
self._wizard.storage["current_step"] = step self._wizard.storage["current_step"] = step
logger.info(f"steps_helper current getter {step}")
return step return step
@current.setter @current.setter
def current(self, step: str): def current(self, step: str):
"""Sets the current step. Updates step history.""" """Sets the current step. Updates step history."""
if step in self.all: if step in self.all:
logger.info(f"steps_helper current setter {step}")
self._wizard.storage["current_step"] = step self._wizard.storage["current_step"] = step
else: else:
logger.debug("Invalid step name %s given to StepHelper" % str(step)) logger.debug("Invalid step name %s given to StepHelper" % str(step))
@ -97,11 +106,13 @@ class StepsHelper:
@property @property
def first(self): def first(self):
"""Returns the name of the first step.""" """Returns the name of the first step."""
logger.info(f"steps_helper first {self.all[0]}")
return self.all[0] return self.all[0]
@property @property
def last(self): def last(self):
"""Returns the name of the last step.""" """Returns the name of the last step."""
logger.info(f"steps_helper last {self.all[-1]}")
return self.all[-1] return self.all[-1]
@property @property
@ -110,6 +121,7 @@ class StepsHelper:
steps = self.all steps = self.all
index = steps.index(self.current) + 1 index = steps.index(self.current) + 1
if index < self.count: if index < self.count:
logger.info(f"steps_helper next {steps[index]}")
return steps[index] return steps[index]
return None return None
@ -119,6 +131,7 @@ class StepsHelper:
steps = self.all steps = self.all
key = steps.index(self.current) - 1 key = steps.index(self.current) - 1
if key >= 0: if key >= 0:
logger.info(f"steps_helper prev {steps[key]}")
return steps[key] return steps[key]
return None return None
@ -127,10 +140,12 @@ class StepsHelper:
"""Returns the index for the current step.""" """Returns the index for the current step."""
steps = self.all steps = self.all
if self.current in steps: if self.current in steps:
logger.info(f"steps_helper index {steps.index(self)}")
return steps.index(self) return steps.index(self)
return None return None
@property @property
def history(self): def history(self):
"""Returns the list of already visited steps.""" """Returns the list of already visited steps."""
logger.info(f"steps_helper history {self._wizard.storage.setdefault('step_history', [])}")
return self._wizard.storage.setdefault("step_history", []) return self._wizard.storage.setdefault("step_history", [])