예제 #1
0
 def show(self, form):
     appstruct = self.appstruct()
     if appstruct is None:
         rendered = form.render()
     else:
         rendered = form.render(appstruct)
     return {"form": rendered}
예제 #2
0
    def __call__(self, request):

        self.request = request

        form = self._gen_form()

        if request.POST:

            ws = WizardState(self.request, self.wizard.name)

            controls = request.POST.items()

            try:

                values = form.validate(controls)

            except deform.exception.ValidationFailure as e:

                return{'form': e.render()}

            ws.set_state(values)

            if 'Next' in request.POST:

                ws.increment_step()

                form = self._gen_form()

                values = ws.get_current_step()

                return {'form': form.render(values)}

            if 'Previous' in request.POST:

                ws = WizardState(self.request, self.wizard.name)

                ws.decrement_step()

                form = self._gen_form()

                values = ws.get_current_step()

                return {'form': form.render(values)}

            if 'Finish' in request.POST:

                states = ws.get_step_states()

                ws.clear()

                for i in states.keys():

                    del states[i]['csrf_token']

                return {'wizard_data': states}

        return {'form': form.render()}
예제 #3
0
    def show(self, form):
        """
        Render the given form, with or without an ``appstruct`` context.

        The given ``form`` argument will be rendered with an ``appstruct``
        if :meth:`appstruct` provides one.  Otherwise, it is rendered without.
        Returns the rendered form as the ``form`` key in a ``dict`` structure.
        """
        appstruct = self.appstruct()
        if appstruct is None:
            rendered = form.render()
        else:
            rendered = form.render(appstruct)
        return {
            'form': rendered,
            }
예제 #4
0
    def __call__(self):
        form, reqts = self._build_form()
        result = None

        for button in form.buttons:
            if button.name in self.request.POST:
                success_method = getattr(self, '%s_success' % button.name)
                try:
                    controls = self.request.POST.items()
                    validated = form.validate(controls)
                except deform.exception.ValidationFailure as e:
                    fail = getattr(self, '%s_failure' % button.name, None)
                    if fail is None:
                        fail = self.failure
                    result = fail(e)
                else:
                    try:
                        result = success_method(validated)
                    except FormError as e:
                        snippet = '<div class="error">Failed: %s</div>' % e
                        self.request.sdiapi.flash(snippet, 'danger',
                                                  allow_duplicate=True)
                        result = {'form': form.render(validated)}
                break

        if result is None:
            result = self.show(form)

        if isinstance(result, dict):
            result['js_links'] = reqts['js']
            result['css_links'] = reqts['css']

        return result
예제 #5
0
    def __call__(self):
        form, reqts = self._build_form()
        result = None

        for button in form.buttons:
            if button.name in self.request.POST:
                success_method = getattr(self, '%s_success' % button.name)
                try:
                    controls = self.request.POST.items()
                    validated = form.validate(controls)
                except deform.exception.ValidationFailure as e:
                    fail = getattr(self, '%s_failure' % button.name, None)
                    if fail is None:
                        fail = self.failure
                    result = fail(e)
                else:
                    try:
                        result = success_method(validated)
                    except FormError as e:
                        snippet = '<div class="error">Failed: %s</div>' % e
                        self.request.session.flash(snippet, 'error',
                                                allow_duplicate=True)
                        result = {'form': form.render(validated)}
                break

        if result is None:
            result = self.show(form)

        if isinstance(result, dict):
            result['js_links'] = reqts['js']
            result['css_links'] = reqts['css']

        return result
예제 #6
0
    def show(self, form):
        """
        Render the given form, with or without an ``appstruct`` context.

        The given ``form`` argument will be rendered with an ``appstruct``
        if :meth:`appstruct` provides one.  Otherwise, it is rendered without.
        Returns the rendered form as the ``form`` key in a ``dict`` structure.
        """
        appstruct = self.appstruct()
        if appstruct is None:
            rendered = form.render()
        else:
            rendered = form.render(appstruct)
        return {
            'form': rendered,
            }
예제 #7
0
 def show(self, form):
     appstruct = getattr(self.schema, 'appstruct', None)
     state = self.wizard_state.get_step_state(appstruct)
     state = self.deserialize(state)
     result = dict(form=form.render(appstruct=state))
     return result
예제 #8
0
 def show(self, form):
     return {
         'form':form.render(),
         }
예제 #9
0
 def show(self, form):
     return {
         'form':form.render(),
         }
예제 #10
0
 def show(self, form):
     return {"form": form.render()}
예제 #11
0
 def show(self, form):
     state = self.wizard_state.get_step_state()
     return {"form": form.render(appstruct=state)}
예제 #12
0
 def show(self, form):
     appstruct = getattr(self.schema, 'appstruct', None)
     state = self.wizard_state.get_step_state(appstruct)
     state = self.deserialize(state)
     result = dict(form=form.render(appstruct=state))
     return result