application logic updated with logs and working to get the right URL from the button

This commit is contained in:
Alysia Broddrick 2023-07-14 13:18:58 -07:00
parent 82b5d43572
commit d139c4caf9
No known key found for this signature in database
GPG key ID: 03917052CD0F06B7

View file

@ -67,7 +67,7 @@ class ApplicationWizard(TemplateView):
URL_NAMESPACE = "application"
# name for accessing /application/<id>/edit
EDIT_URL_NAME = "edit-application"
NEW_URL_NAME = "register"
# We need to pass our human-readable step titles as context to the templates.
TITLES = {
Step.ORGANIZATION_TYPE: _("Type of organization"),
@ -141,10 +141,13 @@ class ApplicationWizard(TemplateView):
except DomainApplication.DoesNotExist:
logger.debug("Application id %s did not have a DomainApplication" % id)
##not being called for the new application when one
self._application = DomainApplication.objects.create(
creator=self.request.user, # type: ignore
)
self.storage["application_id"] = self._application.id
logger.debug("applications id %s",str(self.storage["application_id"]))
return self._application
@property
@ -156,6 +159,7 @@ class ApplicationWizard(TemplateView):
@storage.setter
def storage(self, value):
logger.debug("requested session is %s", str(self.request.session))
self.request.session[self.prefix] = value
self.request.session.modified = True
@ -195,16 +199,18 @@ class ApplicationWizard(TemplateView):
def get(self, request, *args, **kwargs):
"""This method handles GET requests."""
logger.debug("IN GET application")
current_url = resolve(request.path_info).url_name
logger.debug("Current url is %s", current_url)
# if user visited via an "edit" url, associate the id of the
# application they are trying to edit to this wizard instance
# and remove any prior wizard data from their session
if current_url == self.EDIT_URL_NAME and "id" in kwargs:
logger.debug("Storage was %s", self.storage)
del self.storage
self.storage["application_id"] = kwargs["id"]
logger.debug("storage is now %s", str(self.storage))
logger.debug("id set to %s", kwargs["id"])
# if accessing this class directly, redirect to the first step
# in other words, if `ApplicationWizard` is called as view
# directly by some redirect or url handler, we'll send users
@ -213,12 +219,24 @@ class ApplicationWizard(TemplateView):
# send users "to the application wizard" without needing to
# know which view is first in the list of steps.
if self.__class__ == ApplicationWizard:
##hmmm could we use this to redirect users if they shouldn't view editable data?
## this is where it resets to send to first
#this is called when clicking an edit link AND when clicking new app
#not called when navigating between steps (such as clicking save and continue)
logger.debug("Current url is %s", current_url)
if current_url == self.NEW_URL_NAME:## find the right URL
logger.debug("In if check")
del self.storage
self.storage["application_id"] = None #reset the app
logger.debug("calling go to first step")
#del self.storage
return self.goto(self.steps.first)
self.steps.current = current_url
context = self.get_context_data()
context["forms"] = self.get_forms()
logger.debug("Context set to %s", str(context))
return render(request, self.template_name, context)
def get_all_forms(self, **kwargs) -> list:
@ -242,15 +260,15 @@ class ApplicationWizard(TemplateView):
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.
"""
##bug is here an empty form is not provided if these are false!!!
kwargs = {
"files": files,
"prefix": self.steps.current,
"application": self.application, # this is a property, not an object
}
}##application here causing the issue?
if step is None:
forms = self.forms
forms = self.forms ##what dis?
else:
url = reverse(f"{self.URL_NAMESPACE}:{step}")
forms = resolve(url).func.view_class.forms
@ -311,6 +329,7 @@ class ApplicationWizard(TemplateView):
"""This method handles POST requests."""
# if accessing this class directly, redirect to the first step
if self.__class__ == ApplicationWizard:
logger.debug("post redirect to first steps")
return self.goto(self.steps.first)
# which button did the user press?