Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Wizard like forms
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
voltron  
View profile  
 More options Oct 12 2007, 5:14 am
From: voltron <nhy...@googlemail.com>
Date: Fri, 12 Oct 2007 02:14:39 -0700
Local: Fri, Oct 12 2007 5:14 am
Subject: Wizard like forms
I have to collect a lot od data from users, the forms used are
separate but interconnected. This has me coding  for every form, a
processing function and a "display form" function in the controllers
and then both functions have to be defined in the routes
configuration, is there some cleaner and less strenous way of doing
this in pylons? How do others code wizards?

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jgardner@jonathangardner. net  
View profile  
 More options Oct 12 2007, 4:15 pm
From: "jgard...@jonathangardner.net" <jgard...@jonathangardner.net>
Date: Fri, 12 Oct 2007 20:15:34 -0000
Local: Fri, Oct 12 2007 4:15 pm
Subject: Re: Wizard like forms
I would actually do things a little differently. Rather than using a
separate controller for each step, I would combine all the steps into
one controller because a lot of the data is going to be shared.

Each page would be rendered simply by rendering a different template.

Your program state will have to be stored in hidden variables, of
course.

Here's some of my thoughts (incomplete and rough) to describe why I
think this:

http://dervish.jonathangardner.net/tech/w/Web_Application/Wizards

On Oct 12, 2:14 am, voltron <nhy...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
voltron  
View profile  
 More options Oct 12 2007, 4:55 pm
From: voltron <nhy...@googlemail.com>
Date: Fri, 12 Oct 2007 20:55:47 -0000
Local: Fri, Oct 12 2007 4:55 pm
Subject: Re: Wizard like forms
Actually thats what I meant, different functions in one controller,
its just that I have two functions for each step, one to render the
form and one to save and process the data. Hidden variables? I have
been trying my best to avoid those. You mention in your blog this:

"Each page in the wizard would get its own template. Each page would
submit to the same URL"

Posting to the same URL? how is this meant? That would be the answer
to my question in the first place as as I said I would have to create
different URLs or each step( form)

Thanks

On Oct 12, 10:15 pm, "jgard...@jonathangardner.net"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aaaron  
View profile  
 More options Oct 13 2007, 2:41 pm
From: aaaron <aaronmb...@gmail.com>
Date: Sat, 13 Oct 2007 11:41:30 -0700
Local: Sat, Oct 13 2007 2:41 pm
Subject: Re: Wizard like forms
We've created a shuttle helper object that shuttle's form results
between the different steps of the wizard (ie, flow). Each shuttle has
an unique identifier that is used to persist the shuttle to the beaker
session between actions. In the final action of the wizard, we take
all the data that has been collected in the shuttle, then generate and
persist the appropriate model objects, etc.

The user interactions looks like this:

action1 -> collectaction1 (redirect) -> action2 -> collectaction2
(redirect) -> generate/persist

code (put this in your lib.helpers module)
-----------------------------------------------------------

def fetch_shuttle(id=None, action=None):
    """
    To create a new shuttle, don't pass in an id
    """
    if not id:
        id = utils.uuid()

    if id in session:
        shuttle = session.get(id)
    else:
        shuttle = Shuttle(id)
        session[id] = shuttle
        session.save()

    if action:
        return shuttle[action]
    return shuttle

class Shuttle(dict):
    """
    We refer to a multi-page form as a "flow"
    This helper class "shuttles" form result data between
        the different pages of the flow
    This class keeps track of the state of the flow
        which includes form data, steps completed, etc
    """

    def __init__(self, id, *args, **kw):
        super(Shuttle, self).__init__(self, *args, **kw)
        self.id = id

        self.batch_save = False

    def __getitem__(self, key):
        return dict.__getitem__(self, key)

    def start_batch(self):
        """
        instead of saving each time a key/val is set,
            we can batch them together, followed by a save()
        """
        self.batch_save = True

    def set(self, val):
        """
        sets the form_result for the current action
        """
        key = self._get_current_action()
        return self.__setitem__(key, val)

    def __setitem__(self, key, val):
        """
        sets the form_result and saves the session
        """
        dict.__setitem__(self, key, val)
        if not self.batch_save:
            session.save()

    def current(self):
        """
        gets the form_result for the current action
        """
        key = self._get_current_action()
        if not key in self:
            return {} # return empty form result
        return dict.__getitem__(self, key)

    def __delitem__(self, key):
        if key in self:
            dict.__delitem__(self, key)

    def _get_current_action(self):
        return request.environ['pylons.routes_dict']['action']

    def save(self):
        self.batch_save = False
        session.save()

usage: (in your controller)
-------------------------------------

    def __before__(self):

        id = request.environ['pylons.routes_dict'].get('id', None)
        c.shuttle = h.fetch_shuttle(id)

    def action1(self, id):

        c.action = h.url_for(action='storeaction1', id=c.shuttle.id)

        return render_response('/action1_form.html')

    @validate(schema=action1schema, form='action1')
    def storeaction1(self, id):

        c.shuttle['action1'] = self.form_result

        h.redirect_to(action='action2')

    def action2(self, id):
        ... etc...

    # eventually
    def saveall(self, id):
        # gen db objects from all the shuttle data
        model_obj = action1schema.to_model(c.shuttle['action1'])
        ... etc...

If people are interested, I can articulate this more thoughtfully on
the hq wiki. I feel the "Form Handling" page (http://wiki.pylonshq.com/
display/pylonsdocs/Form+Handling) in the official pylons docs could
use an update. It doesn't give much insight into setting default
values on forms (htmlfill) or how <form:errors> works... still alludes
to the rise of a "Turbogears widget system".


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »