Ejemplo n.º 1
0
    def prepare_form(self, __):
        # init storage and step helper
        self.prefix = normalize_name(self.__class__.__name__)
        self.storage = get_storage(self.storage_name, self.prefix, self.request, getattr(self, "file_storage", None))
        self.steps = StepsHelper(self)
        self.wizard_goto_step = False

        if self.request.method == "GET":
            self.storage.reset()
            self.storage.current_step = self.steps.first

            self.admin_view.model_form = self.get_step_form()
        else:
            # Look for a wizard_goto_step element in the posted data which
            # contains a valid step name. If one was found, render the requested
            # form. (This makes stepping back a lot easier).
            wizard_goto_step = self.request.POST.get("wizard_goto_step", None)
            if wizard_goto_step and int(wizard_goto_step) < len(self.get_form_list()):
                self.storage.current_step = self.get_form_list().keys()[int(wizard_goto_step)]
                self.admin_view.model_form = self.get_step_form()
                self.wizard_goto_step = True
                return

            # Check if form was refreshed
            management_form = ManagementForm(self.request.POST, prefix=self.prefix)
            if not management_form.is_valid():
                raise ValidationError("ManagementForm data is missing or has been tampered.")

            form_current_step = management_form.cleaned_data["current_step"]
            if form_current_step != self.steps.current and self.storage.current_step is not None:
                # form refreshed, change current step
                self.storage.current_step = form_current_step

            # get the form for the current step
            self.admin_view.model_form = self.get_step_form()
Ejemplo n.º 2
0
    def post(self, *args, **kwargs):
        """
        This method handles POST requests.

        The wizard will render either the current step (if form validation
        wasn't successful), the next step (if the current step was stored
        successful) or the done view (if no more steps are available)
        """
        # Look for a wizard_goto_step element in the posted data which
        # contains a valid step name. If one was found, render the requested
        # form. (This makes stepping back a lot easier).
        wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
        self.process_wizard_goto_step(wizard_goto_step)

        # Check if form was refreshed
        management_form = ManagementForm(self.request.POST, prefix=self.prefix)
        if not management_form.is_valid():
            raise ValidationError(
                'ManagementForm data is missing or has been tampered.')

        form_current_step = management_form.cleaned_data['current_step']
        if (form_current_step != self.steps.current and
            self.storage.current_step is not None):
            # 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)

        self.pre_process(form)

        # 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))

            self.additional_file_processing()

            # Add ability to "save_only"
            if "save_only" in self.request.POST:
                self.post_save_only()
                return redirect(self.save_only_url)

            # check if the current step is the last step
            if self.steps.current == self.steps.last:
                # no more steps, render done view
                return self.render_done(form, **kwargs)
            else:
                # proceed to the next step
                return self.render_next_step(form)
        return self.render(form)
Ejemplo n.º 3
0
    def post(self, *args, **kwargs):
        """
        This method handles POST requests.

        The wizard will render either the current step (if form validation
        wasn't successful), the next step (if the current step was stored
        successful) or the done view (if no more steps are available)
        """
        # Look for a wizard_goto_step element in the posted data which
        # contains a valid step name. If one was found, render the requested
        # form. (This makes stepping back a lot easier).
        wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
        if wizard_goto_step and wizard_goto_step in self.get_form_list():
            self.storage.current_step = wizard_goto_step
            form = self.get_form(
                data=self.storage.get_step_data(self.steps.current),
                files=self.storage.get_step_files(self.steps.current))
            return self.render(form)

        # Check if form was refreshed
        management_form = ManagementForm(self.request.POST, prefix=self.prefix)
        if not management_form.is_valid():
            raise ValidationError(
                'ManagementForm data is missing or has been tampered.')

        form_current_step = management_form.cleaned_data['current_step']
        if (form_current_step != self.steps.current
                and self.storage.current_step is not None):
            # 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:
                # no more steps, render done view
                return self.render_done(form, **kwargs)
            else:
                # proceed to the next step
                return self.render_next_step(form)
        return self.render(form)
Ejemplo n.º 4
0
    def post(self, *args, **kwargs):
        """
        Check if the current step is still available. It might not be if
        conditions have changed.
        """
        if self.steps.current not in self.steps.all:
            logger.warning("Current step '%s' is no longer valid, returning "
                           "to last valid step in the wizard.",
                           self.steps.current)
            return self.render_goto_step(self.steps.all[-1])

        # -- Duplicated code from upstream
        # Look for a wizard_goto_step element in the posted data which
        # contains a valid step name. If one was found, render the requested
        # form. (This makes stepping back a lot easier).
        wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
        if wizard_goto_step and wizard_goto_step in self.get_form_list():
            return self.render_goto_step(wizard_goto_step)

        # Check if form was refreshed
        management_form = ManagementForm(self.request.POST, prefix=self.prefix)
        if not management_form.is_valid():
            raise ValidationError(
                _('ManagementForm data is missing or has been tampered.'),
                code='missing_management_form',
            )

        form_current_step = management_form.cleaned_data['current_step']
        if (form_current_step != self.steps.current and
                self.storage.current_step is not None):
            # form refreshed, change current step
            self.storage.current_step = form_current_step
        # -- End duplicated code from upstream

        # This is different from the first check, as this checks
        # if the new step is available. See issue #65.
        if self.steps.current not in self.steps.all:
            logger.warning("Requested step '%s' is no longer valid, returning "
                           "to last valid step in the wizard.",
                           self.steps.current)
            return self.render_goto_step(self.steps.all[-1])

        return super(IdempotentSessionWizardView, self).post(*args, **kwargs)
Ejemplo n.º 5
0
    def post(self, *args, **kwargs):
        """
        Check if the current step is still available. It might not be if
        conditions have changed.
        """
        if self.steps.current not in self.steps.all:
            logger.warning(
                "Current step '%s' is no longer valid, returning "
                "to last valid step in the wizard.", self.steps.current)
            return self.render_goto_step(self.steps.all[-1])

        # -- Duplicated code from upstream
        # Look for a wizard_goto_step element in the posted data which
        # contains a valid step name. If one was found, render the requested
        # form. (This makes stepping back a lot easier).
        wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
        if wizard_goto_step and wizard_goto_step in self.get_form_list():
            return self.render_goto_step(wizard_goto_step)

        # Check if form was refreshed
        management_form = ManagementForm(self.request.POST, prefix=self.prefix)
        if not management_form.is_valid():
            raise ValidationError(
                _('ManagementForm data is missing or has been tampered.'),
                code='missing_management_form',
            )

        form_current_step = management_form.cleaned_data['current_step']
        if (form_current_step != self.steps.current
                and self.storage.current_step is not None):
            # form refreshed, change current step
            self.storage.current_step = form_current_step
        # -- End duplicated code from upstream

        # This is different from the first check, as this checks
        # if the new step is available. See issue #65.
        if self.steps.current not in self.steps.all:
            logger.warning(
                "Requested step '%s' is no longer valid, returning "
                "to last valid step in the wizard.", self.steps.current)
            return self.render_goto_step(self.steps.all[-1])

        return super(IdempotentSessionWizardView, self).post(*args, **kwargs)
Ejemplo n.º 6
0
 def post(self, *args, **kwargs):
     wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
     if wizard_goto_step and wizard_goto_step in self.get_form_list():
         return self.render_goto_step(wizard_goto_step)
     management_form = ManagementForm(self.request.POST, prefix=self.prefix)
     if not management_form.is_valid():
         raise ValidationError(_('ManagementForm data is missing or has been tampered.'), code='missing_management_form',)
     form_current_step = management_form.cleaned_data['current_step']
     if (form_current_step != self.steps.current and self.storage.current_step is not None):
         self.storage.current_step = form_current_step
     form = self.get_form(data=self.request.POST)
     if 'request' == self.steps.current:
         if form.is_valid():
             try:
                 Institution.objects.get(institution_no=form.cleaned_data['institution_no'])
             except Institution.DoesNotExist:
                 form._errors['institution_no'] = ErrorList(['%s가 올바르지 않습니다.' % settings.INSTITUTION_VERBOSE_NAME])
     if 'confirm' == self.steps.current:
         if form.is_valid():
             today = date.today()
             identity_no = form.cleaned_data['identity_no']
             name = form.cleaned_data['name']
             try:
                 requested_identity = Identity.objects.get(identity_no=identity_no)
                 qualified_identity = Identity.objects.filter(personal_id=requested_identity.personal_id).order_by('-expired').order_by('-created').exclude(expired__lte=today).exclude(is_valid=False)
                 if not qualified_identity:
                     form._errors['identity_no'] = ErrorList(['%s가 유효하지 않습니다.' % settings.IDENTITY_VERBOSE_NAME])
                 if qualified_identity:
                     qualified_identity = qualified_identity[0]
                     if requested_identity != qualified_identity:
                         form._errors['identity_no'] = ErrorList(['%s가 유효하지 않습니다.' % settings.IDENTITY_VERBOSE_NAME])
             except Identity.DoesNotExist:
                 form._errors['identity_no'] = ErrorList(['%s가 유효하지 않습니다.' % settings.IDENTITY_VERBOSE_NAME])
         if form.is_valid():
             kwargs['institution'] = get_object_or_404(Institution, institution_no=self.get_cleaned_data_for_step('request').get('institution_no', ''))
             kwargs['identity'] = qualified_identity
     if form.is_valid():
         self.storage.set_step_data(self.steps.current, self.process_step(form))
         if self.steps.current == self.steps.last:
             return self.render_done(form, **kwargs)
         else:
             return self.render_next_step(form)
     return self.render(form)
Ejemplo n.º 7
0
    def prepare_form(self, __):
        # init storage and step helper
        self.prefix = normalize_name(self.__class__.__name__)
        self.storage = get_storage(self.storage_name, self.prefix,
                                   self.request,
                                   getattr(self, 'file_storage', None))
        self.steps = StepsHelper(self)
        self.wizard_goto_step = False

        if self.request.method == 'GET':
            self.storage.reset()
            self.storage.current_step = self.steps.first

            self.admin_view.model_form = self.get_step_form()
        else:
            # Look for a wizard_goto_step element in the posted data which
            # contains a valid step name. If one was found, render the requested
            # form. (This makes stepping back a lot easier).
            wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
            if wizard_goto_step and int(wizard_goto_step) < len(
                    self.get_form_list()):
                self.storage.current_step = self.get_form_list().keys()[int(
                    wizard_goto_step)]
                self.admin_view.model_form = self.get_step_form()
                self.wizard_goto_step = True
                return

            # Check if form was refreshed
            management_form = ManagementForm(self.request.POST,
                                             prefix=self.prefix)
            if not management_form.is_valid():
                raise ValidationError(
                    'ManagementForm data is missing or has been tampered.')

            form_current_step = management_form.cleaned_data['current_step']
            if (form_current_step != self.steps.current
                    and self.storage.current_step is not None):
                # form refreshed, change current step
                self.storage.current_step = form_current_step

            # get the form for the current step
            self.admin_view.model_form = self.get_step_form()
Ejemplo n.º 8
0
    def post(self, *args, **kwargs):
        """
        This method handles POST requests.

        The wizard will render either the current step (if form validation
        wasn't successful), the next step (if the current step was stored
        successful and the next step was requested) or the done view (if no 
        more steps are available or the entire wizard was submitted)
        """
        # Look for a wizard_goto_step element in the posted data which
        # contains a valid step name. If one was found, render the requested
        # form. (This makes stepping back a lot easier).
        wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
        wizard_finish = self.request.POST.get('wizard_finish', None)
        if wizard_goto_step and wizard_goto_step in self.get_form_list():
            self.storage.current_step = wizard_goto_step
            form = self.get_form(
                data=self.storage.get_step_data(self.steps.current),
                files=self.storage.get_step_files(self.steps.current))
            form.is_valid()
            return self.render(form)

        # Check if form was refreshed
        management_form = ManagementForm(self.request.POST, prefix=self.prefix)
        if not management_form.is_valid():
            raise ValidationError('ManagementForm data is missing or has been tampered.')

        form_current_step = management_form.cleaned_data['current_step']
        if (form_current_step != self.steps.current and
                self.storage.current_step is not None):
            # 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))
            
            if wizard_finish:
                # User tried to submit the entire form
                if self.is_valid():
                    return self.render_done(form, **kwargs)
                else:
                    for step in self.steps.all:
                        if not self.form_is_valid(step):
                            self.storage.current_step = step
                            form = self.get_form(step=step, data=self.storage.get_step_data(step),
                                                 files=self.storage.get_step_files(step))
                            form.is_valid()
                            return self.render(form)
                
            # check if the current step is the last step
            if self.steps.current == self.steps.last:
                # no more steps, render done view
                return self.render_done(form, **kwargs)
            else:
                # proceed to the next step
                return self.render_next_step(form)
        
        return self.render(form)