I made a project that works like ifttt.com .
For this I use FormWizard .
Actually, this only works great with two RSS and Evernote services.
I could set FORMS and TEMPLATES as expected in FormWizard, here is the world of my urls.py and views.py :
urls.py
# wizard url(r'^service/create/$', UserServiceWizard.as_view([RssForm, EvernoteForm, ServicesDescriptionForm]), name='create_service'),
views.py
from th_rss.forms import RssForm from th_evernote.forms import EvernoteForm from django_th.forms.base import ServicesDescriptionForm FORMS = [("rss", RssForm), ("evernote", EvernoteForm), ("services", ServicesDescriptionForm), ] TEMPLATES = { '0': 'rss/wz-rss-form.html', '1': 'evernote/wz-evernote-form.html', '2': 'services_wizard/wz-description.html'} class UserServiceWizard(SessionWizardView): instance = None def get_form_instance(self, step): if self.instance is None: self.instance = TriggerService() return self.instance def done(self, form_list, **kwargs): trigger = self.instance trigger.provider = UserService.objects.get( name='ServiceRss', user=self.request.user) trigger.consummer = UserService.objects.get(name='ServiceEvernote', user=self.request.user) trigger.user = self.request.user trigger.status = True
But since in fact the project processes only 2 services, I do not want (and cannot imagine) creating one dedicated CBV for each pair of new services, such as TwitterEvernoteWizard, RssTwitterWizard, FacebookTwitterWizard, etc.
So, first of all, I will need to change the process to these steps:
- The first page displays the services that the user can select.
- The second page asks the user what data he wants to capture from the selected service in step 1.
- The third page displays the services that the user can choose without selecting un step1
- The 4th page asks the user where the data will be displayed (which the system will capture) (in the selected service in step 3)
- The fifth (and last) page displays a description field for the trigger name.
With a specific that will give:
- page 1 I choose Twitter
- page 2 I choose to capture data from the timeline
- page 3 I choose Facebook
- page 4 I choose to place data on the wall
- page 5 I put "Here is my twitter trigger on facebook";)
So, with this process, I need to be able to dynamically change the contents of FORMS to populate it with the name FormWizard from the Service, which I chose one step earlier. Same for TEMPLATES dict.
As you can see, at the beginning of the Wizard I cannot know in advance which service will be selected. This is why I need to dynamically populate FORMS and TEMPLATES
If someone knows how to do this or can simply suggest a way to continue, I will appreciate it.
considers
notice: I am using Django 1.4