Django Form Wizard Not Executing done() Method Despite Valid Form Submission

Hello Django Community,
I’m currently working on a Django project where I’m using the SessionWizardView to implement a multi-step form process for signing documents. However, I’m encountering a perplexing issue: the done() method is not being executed, and as a result, no data is being saved to the database.

Project Setup:

Django Version: 5.0.6

Setup:

• The form process involves three steps:

  1. Step 1: User inputs personal details.

  2. Step 2: User reviews the document title and details.

  3. Step 3: User signs the document, and the signed document should be saved.

Problem:

• After submitting the final form (Step 3), the wizard redirects to the thank_you page as expected. However, none of the participant data, including the signed document, is saved to the database. Additionally, the done() method does not seem to be executed, as none of the print statements or debugging logs inside this method appear in the console.

Here is the current implementation of the SignMyselfWizard view:

class SignMyselfWizard(SessionWizardView):
    form_list = FORMS_MYSELF
    file_storage = file_storage

    def get_template_names(self):
        step = self.steps.current

        if step == 'user_details':
            return 'sign/user_details_form.html'
        elif step == 'review':
            return 'sign/review_document.html'
        elif step == 'sign_document':
            return 'sign/sign_myself_wizard.html'

        return 'sign/default.html'

    def get_context_data(self, form, **kwargs):
        context = super().get_context_data(form=form, **kwargs)
        if 'unique_link' in self.kwargs:
            document = get_object_or_404(
                Document, unique_link=self.kwargs['unique_link'])
            context.update({
                'document': document,
                'document_url': self.request.build_absolute_uri(document.docfile.url),
                'company': document.company,
            })

            if self.steps.current == 'sign_document':
                user_details = self.get_cleaned_data_for_step('user_details')
                if user_details:
                    context.update({
                        'first_name': user_details.get('first_name'),
                        'last_name': user_details.get('last_name'),
                        'email': user_details.get('email'),
                        'phone': user_details.get('phone'),
                        'dob': user_details.get('dob'),
                        'gender': user_details.get('gender'),
                    })
        return context

    def post(self, *args, **kwargs):
        print("POST method triggered with data:", self.request.POST)
        print("FILES data received:", self.request.FILES)

        management_form_keys = [
            key for key in self.request.POST.keys() if key.startswith('sign_myself_wizard')]
        print("ManagementForm fields in POST:", management_form_keys)

        return super().post(*args, **kwargs)

    def done(self, form_list, **kwargs):
        user_details = self.get_cleaned_data_for_step('user_details')
        print("Processing step: done")

        document = get_object_or_404(
            Document, unique_link=self.kwargs['unique_link'])

        participant = Participant.objects.create(
            first_name=user_details['first_name'],
            last_name=user_details['last_name'],
            dob=user_details['dob'],
            gender=user_details['gender'],
            email=user_details['email'],
            phone=user_details['phone'],
            document=document,
        )

        signed_document = self.request.FILES.get('signed_document')
        if signed_document:
            participant.signed_document.save(
                f"{participant.sign_number}.pdf", signed_document)
            print("Signed Document Saved:", participant.signed_document)
        else:
            print("No signed document found.")

        return redirect('sign:thank_you')

Debugging Steps Taken:

  1. Each form step is validated successfully, and I’ve confirmed that the forms are valid at each stage.
  2. The POST method logs confirm that the data, including FILES, is being received correctly. However, the done() method is never triggered, which is where the saving of data should occur.
  3. Despite reaching the final step and the POST data being intact, the wizard skips the done() method and directly redirects to the thank_you page.

Observed Behavior:

The signed document is temporarily saved in the file storage location but not permanently stored as the done() method is not executed.

The participant information and the signed document are not saved to the database.

Questions:

  1. What could be preventing the done() method from being executed?
  2. Why might the wizard be skipping the done() method and redirecting to the thank_you page without saving any data?
  3. Could there be an issue with the wizard’s internal flow or the template rendering that we might be missing?

Any insights or suggestions to troubleshoot this issue would be greatly appreciated!

Thank you in advance for your help!

hello @KenWhitesell