jazzband / django-formtools

A set of high-level abstractions for Django forms
https://django-formtools.readthedocs.io
BSD 3-Clause "New" or "Revised" License
814 stars 136 forks source link

ManagementForm data is missing or has been tampered with #131

Closed robertomorati closed 6 years ago

robertomorati commented 6 years ago

Hi @jezdez

I have been facing the error: managementform data is missing or has been tampered with. Thus, if possible, I need some help to solve this issue :) thankfully

My Form:

class InscricaoGrupoFamiliarCandidatoForm(forms.Form):
    parentesco = forms.ModelChoiceField(label="Parentesco:", queryset=ParentescoNb.objects.all(), empty_label="Selecione o parentesco...", required=False)
    nome = forms.CharField(max_length=255, label="Nome Completo:", widget=forms.TextInput(attrs={'placeholder': 'insira o seu nome completo'}))
    renda = forms.DecimalField(max_digits=7, decimal_places=2, label="Renda:", widget=forms.TextInput(attrs={'placeholder': 'informe o valor da renda', 'class': 'vlr_renda'}))

class BaseInscricaoGrupoFamiliarCandidatoFormSet(BaseFormSet):

    def clean_nome(self):
        self.nome = HumanName(self.cleaned_data['nome'])
        self.nome.capitalize(force=True)
        if self.nome.middle == '' and self.nome.last == '':
            ValidationError
            raise ValidationError(_("Insira seu nome completo."))

InscricaoGrupoFamiliarCandidatoFormSet = formset_factory(form=InscricaoGrupoFamiliarCandidatoForm, formset=BaseInscricaoGrupoFamiliarCandidatoFormSet, extra=3, can_delete=False)

Main parts of HTML file:

    {{ wizard.management_form }}
     {% for form in wizard.form %}
          <div class="grupo-formset">
              {% bootstrap_form form  %}
     </div>
    <hr class="custom__hr"> 
     {% endfor %}

      {% buttons %}

     {% if wizard.steps.current == wizard.steps.last %}
         <button type="submit" class="btn btn-primary"  value="Update">
              {% bootstrap_icon "save" %} Finalizar Inscrição
         </button>

     {% else %}
     <button type="submit" class="btn btn-primary"  value="Update">
             {% bootstrap_icon "forward" %} Próximo
     </button>
     {% endif %}
       .......................
    <script>
        $('.grupo-formset').formset({
            addText: 'Adicionar membro do grupo familiar.',
            deleteText: 'Remover membro do grupo familiar.'
        });
    </script>

Views:

class InscricaoValidacaoWizard(SessionWizardView):
    file_storage = temp_storage

    def done(self, form_list, **kwargs):
        pass

Error:

/lib/python3.5/site-packages/formtools/wizard/views.py in post
            # form refreshed, change current step
            self.storage.current_step = form_current_step
        # get the form for the current step
        form = self.get_form(data=self.request.POST, files=self.request.FILES)
        # and try to validate
        if form.is_valid(): ...
            # if the form is valid, store the cleaned data and files.
            self.storage.set_step_data(self.steps.current, self.process_step(form))
            self.storage.set_step_files(self.steps.current, self.process_step_files(form))
            # check if the current step is the last step
            if self.steps.current == self.steps.last:

................................

args | (<WSGIRequest: POST '/inscricao/'>,)
form | <django.forms.formsets.InscricaoGrupoFamiliarCandidatoFormFormSet object at 0x7f3a8403ab38>
form_current_step | 'inscricaoGrupoFamiliarCandidatoFormSet'
kwargs | {}
management_form | <ManagementForm bound=True, valid=True, fields=(current_step)>
self | <InscricaoValidacaoWizard: forms: OrderedDict([('inscricaoGrupoFamiliarCandidatoFormSet', <class 'django.forms.formsets.InscricaoGrupoFamiliarCandidatoFormFormSet'>), ('inscricaoEnderecoCandidato', <class 'nossabolsa.inscricao.forms.InscricaoEnderecoCandidatoForm'>)])>
wizard_goto_step | None

I really apreciated, All the best,

robertomorati commented 6 years ago

@jezdez,

Can close the issue. I solve the problem. Its was my HTML file.

Follow the fragment:

           {{ wizard.management_form }}
          {% if wizard.form.forms %}
     {{ wizard.form.management_form }}
        {% for form in wizard.form.forms %}
           <div class="grupo-formset">
          {% bootstrap_form form  %}
        </div>
       {% endfor %}
     {% else %}
            {% bootstrap_form wizard.form  %}
     {% endif %}

Thanks, All the best,

claudep commented 6 years ago

Thanks for letting us know.