Example #1
0
 def test_missing_storage(self):
     with self.assertRaises(MissingStorage):
         get_storage(
             'formtools.wizard.storage.idontexist.IDontExistStorage',
             'wizard1')
     with self.assertRaises(MissingStorage):
         get_storage('formtools.wizard.storage.base.IDontExistStorage',
                     'wizard1')
Example #2
0
    def dispatch(self, request, *args, **kwargs):
        """Dispatch.

        This method gets called by the routing engine. The first argument is
        `request` which contains a `HttpRequest` instance.
        The request is stored in `self.request` for later use. The storage
        instance is stored in `self.storage`.

        After processing the request using the `dispatch` method, the
        response gets updated by the storage engine (for example add cookies).
        """
        # add the storage engine to the current wizardview instance
        self.prefix = self.get_prefix(request, *args, **kwargs)
        self.storage = get_storage(self.storage_name, self.prefix, request,
                                   getattr(self, 'file_storage', None))
        self._form_list = []

        initial_wizard_data = self.get_initial_wizard_data(
            request, *args, **kwargs)
        for key, value in initial_wizard_data.items():
            setattr(self, key, value)

        self.steps = StepsHelper(self)
        response = super(DynamicWizardView,
                         self).dispatch(request, *args, **kwargs)

        # update the response (e.g. adding cookies)
        self.storage.update_response(response)
        return response
Example #3
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()
Example #4
0
    def dispatch(self, request, *args, **kwargs):
        """Dispatch.

        This method gets called by the routing engine. The first argument is
        `request` which contains a `HttpRequest` instance.
        The request is stored in `self.request` for later use. The storage
        instance is stored in `self.storage`.

        After processing the request using the `dispatch` method, the
        response gets updated by the storage engine (for example add cookies).
        """
        # add the storage engine to the current wizardview instance
        self.prefix = self.get_prefix(request, *args, **kwargs)
        self.storage = get_storage(
            self.storage_name,
            self.prefix,
            request,
            getattr(self, 'file_storage', None)
        )
        self._form_list = []

        initial_wizard_data = self.get_initial_wizard_data(
            request, *args, **kwargs
        )
        for key, value in initial_wizard_data.items():
            setattr(self, key, value)

        self.steps = StepsHelper(self)
        response = super(DynamicWizardView, self).dispatch(
            request, *args, **kwargs
        )

        # update the response (e.g. adding cookies)
        self.storage.update_response(response)
        return response
Example #5
0
    def dispatch(self, request, *args, **kwargs):
        self.prefix = self.get_prefix(request, *args, **kwargs)
        self.storage = get_storage(self.storage_name, self.prefix, request, getattr(self, 'file_storage', None))
        self.steps = StepsHelper(self)
        response = TemplateView.dispatch(self, request, *args, **kwargs)

        # update the response (e.g. adding cookies)
        self.storage.update_response(response)
        return response
Example #6
0
    def dispatch(self, request, *args, **kwargs):
        if request.COOKIES.get(COOKIE_MINOR) == 'true':
            return django.shortcuts.redirect('register_minor')

        if request.session.get(SESSION_RESET_FORM):
            del request.session[SESSION_RESET_FORM]
            prefix = self.get_prefix(request, *args, **kwargs)
            storage = get_storage(self.storage_name, prefix, request,
                                  getattr(self, 'file_storage', None))
            storage.reset()
        if not self.configuration:
            if self.check_configuration():
                self.process_registration_configuration()
            else:
                prefix = self.get_prefix(request, *args, **kwargs)
                storage = get_storage(self.storage_name, prefix, request,
                                      getattr(self, 'file_storage', None))
                storage.reset()
                # we are missing registration configuration,
                # so send the user back
                return django.shortcuts.redirect('start')
        return super(RegistrationWizardView, self).dispatch(
            request, *args, **kwargs)
Example #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()):
                obj = self.get_form_list().keys()
                if six.PY3:
                    obj = [s for s in obj]
                self.storage.current_step = obj[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()
Example #8
0
 def test_load_storage(self):
     self.assertIsInstance(
         get_storage('formtools.wizard.storage.base.BaseStorage',
                     'wizard1'), BaseStorage)
Example #9
0
 def test_load_storage(self):
     self.assertEqual(
         type(
             get_storage('formtools.wizard.storage.base.BaseStorage',
                         'wizard1')), BaseStorage)
 def test_load_storage(self):
     self.assertEqual(
         type(get_storage('formtools.wizard.storage.base.BaseStorage', 'wizard1')),
         BaseStorage)