Entries in "September, 2008"

Django FormWizard - Passing Data Between Forms

Friday, September 26, 2008 - 9:35 PM

I recently had the need for a multi-step web form and so I wanted to give the Django FormWizard a spin because I haven't had a chance to use it yet.

The FormWizard documentation is lacking a little and it makes no mention of the support for passing an initial value for each form "step" to the Wizard. Passing an initial value is done by passing a dictionary, containing dictionaries, where the keys are the individual form step sequences. For example, the first form will have a key of 0 (zero), the second form will have a key of 1, etc. Here is an example urls.py...


# Import forms and custom wizard
from yourproject.yourapp.forms import *

init = {
0: {
'field1': 'value1',
'field2': 'value2',
},
1: {
'field3': 'value3',
'field4': 'value4',
}
}

# In your urlpatterns...
url(r'^wizard/$', BusinessWizard([Form1, Form2], initial=init),

This will create an instance of the BusinessWizard FormWizard (assuming that's the name of your Wizard) and it will have 2 steps, processing Form1 and Form2. When the wizard is processing the form it will pass the dictionary in key 0 to Form1 as it's initial value and it will iterate with each step.

So what happens if you need data from Form1 to be available in a field in Form2 as the initial value? Well there is no built in way to do this but the good folks over at Django decided to give us a nice helper method that is called from the __call__ method of the FormWizard class.

This helper method is called parse_params and it can be used to help us pass data to the next form by manipulating the FormWizard.initial dictionary.

One thing to note is that parse_params will be called when the form is being displayed and "written to" (via form POST). You need to check for the step PRIOR to the step where you want the data to be passed. If the request method is POST, then you can call the form and check for validation. If valid, you can assign the initial value for the next form based on the cleaned_data dictionary of the current form.

So in my case, I needed the form on step 1 (which is the second form, remember the counter starts at zero) to receive data from step 0.

Here's an example...


from django.contrib.formtools.wizard import FormWizard

class BusinessWizard(FormWizard):
def parse_params(self, request, *args, **kwargs):
current_step = self.determine_step(request, *args, **kwargs)
if request.method == 'POST' and current_step == 0:
form = self.get_form(current_step, request.POST)
if form.is_valid():
self.initial[(current_step + 1)] = {
'name': form.cleaned_data['name'],
'address': form.cleaned_data['address'],
'city': form.cleaned_data['city'],
}

def done(self, request, form_list):
# Your form processing code goes here

When the second form is displayed it will have the initial value assigned in the parse_params method.

I can't think of many situations where you would want to do this but they do pop up occasionally. If you are curious about the FormWizard class check the source code out. It's a small class and very easy to follow.

Note: This might not be the "best" way to do this. The process_step method may also be a good place for this type of operation but it was called twice, conditionally, in the __call__ method so it just felt "right" to use parse_params.

Technorati Tags: , , ,

Posted by Peter Sanchez in geek, technology 0 comments
 

Mom and Pop Money - Trading Customers For Cash

Wednesday, September 24, 2008 - 9:34 PM

I wrote a few weeks back about a new product I was getting ready to launch named "Mom and Pop Money". The product had been ready for a few weeks but I had to wrap up some things before I could officially release it.

Last week I gave an early release to the waiting list and my blog's mailing list. So far the feedback has been exceptional! I am very happy with the results so far and have received some awesome testimonials. Testimonials so good you'd think I paid the people to write them... but I didn't.

What exactly is "Trading Customers For Cash"?

Essentially it's generating leads online for resale to local "mom and pop" businesses. I've written in the past about this method and I got a few emails asking for more info. I decided then to create this product and offer it for sale. I can see this was a very smart decision.

The product guides you through the entire process and includes all the tools needed to run this sort of business online. Here is everything that's included:


Mom and Pop Money eBook - 14 chapters of "meat and potatoes" revolving around a lead generation system that I've been using for some time.

Lead Management Software - I spent good hard money to have this software produced. It makes managing the entire system an absolute breeze. It will be included in the product.

Free Templates - Some free website templates that I have actually used do work this system. I might be using them right now!

Video Tutorials - Tutorials that are easy to follow and show you how to install the lead management software and upload the free template that's also included.

Phone Consultation - I will personally spend some time on the phone with you to discus this system and how you can set yourself up to start making a profit a.s.a.p.

There is also another bonus that's included but I don't want to make this post to "sales pagey". That's what the actual sales page is for :)

So if you're tired of all the same old recycled "make money online" BS being passed around, you will probably get a kick out of Mom and Pop Money. I recommend you Check it out here...

Technorati Tags: , , , , , ,

Posted by Peter Sanchez in business, internet marketing 0 comments
 

Sept. 11th, 7 Year Anniversary

Thursday, September 11, 2008 - 12 PM

Today is the 7 year anniversary of the 9-11 attacks. Obviously this is a day in history that everyone will remember forever. One day that brings back a lot of emotions in a lot of people. Especially the people of New York.

Over a year ago I wrote a post about a strange prediction I had on September 10th, 2001. Sort of eerie post and I give links to the actual prediction from 2001 on LiveJournal. Maybe it isn't a prediction, but more of a "feeling". Anyways, it's sort of strange.

My daughters will be attending a "Patriot Day" Parade here in SoCal tonight (I will probably miss this because I am buried in work). It's important to my wife and I to make sure our kids know about the tragedy and that they respect the date.

Let's not forget about the people serving in our military. We all don't agree on the current war but I'm sure everyone can agree that the people fighting it are brave and selfless. I really appreciate their sacrifice!

Technorati Tags: , ,

Posted by Peter Sanchez in general, life, news 0 comments
 

Django 1.0 Released!!

Thursday, September 4, 2008 - 9:46 AM

Wow, Django has finally released version 1.0 of it's framework. I've been using Django for around 18 months now and have written about it many times in the past. There have many so many improvements to the framework since I started using it. If you want to create a powerful website quickly, Django is such an awesome framework to build from. Since it's pure Python it makes writing fast code such a breeze.

Anyways, I just wanted to say congrats to the entire Django team and user base. This is a big milestone for all of us.

Technorati Tags: , , ,

Posted by Peter Sanchez in geek, news 0 comments