Ok, so I set up the FormWizard, but it has some strange side effects. I 
implemented the process in three steps:

   1. Choose a workflow
   2. Specify information for the new Job (Adress, deadline, customer...)
   3. Review deadlines and assigness for the different steps.

Problems occur in the third step: 

   - for some reason additional, unrelated tasks from the db are shown
   -  even though values for the mandatory fields in the form are chosen, 
   an error is thrown that these are missing
   - if I specify a non-mandatory field (assignee) suddenly the error above 
   does not occur anymore an the process finishes without error (but not 
   necessarily the right result)

I am thinking that FormWizard cannot handle the 'dynamic' changes I am 
doing: The third step is adjusted based on the chosen workflow in the first 
step. I read somewhere that this is can be an issue. 


Maybe one of you can tell me where the mistake is? Any hint is appreciated.


My FormWizard:

class JobWizard(SessionWizardView):
    form_list = [
            ('first', forms.WorkflowSelectForm),
            ('second', forms.JobForm),
            ('third', forms.TaskFormSet)
            ]

    def done(self, form_list, **kwargs):
        # store Job in database
        # how do I access data in ValuesView?
        forms = []
        for form in form_list:
            forms.append(form)
        
        job = forms[1].save()
        for form in forms[2]:
            current_task = form.save(commit=False)
            current_task.job = job            
            current_task.save()
        

        return HttpResponseRedirect('/jobs/')

    def get_form_initial(self, step):
        if step is None:
            step = self.steps.current

        if step == 'second':
            prev_data = self.storage.get_step_data('first')
        
            return {'deadline': (timezone.now() + timezone.timedelta(days=30
)).replace(hour=12, minute=0, second=0),
                        'workflow': Workflow.objects.get(pk = prev_data.get(
'first-workflow')),
                        'creator': self.request.user
                        }
        
        if step == 'third':
            first_step_data = self.get_cleaned_data_for_step('first')
            second_step_data = self.get_cleaned_data_for_step('second')
            steps = Step.objects.filter(workflow=first_step_data['workflow'
]).order_by('order')
            # get total time
            t_total = 0.
            for step in steps:
                t_total += step.time_fraction
            deadline = second_step_data['deadline']
            start_date = second_step_data['start_date']
            job_duration = (deadline - start_date).total_seconds()
            
            initial_data = []
            task_deadline = start_date
            for step in steps:
                fraction = step.time_fraction / t_total
                task_duration = fraction * job_duration
                task_deadline = task_deadline + timezone.timedelta(seconds = 
task_duration)
                assignee = step.assigned_to
                data = {'deadline':  task_deadline,
                        'assigned_to': assignee,
                        'step': step}
                initial_data.append(data)
        
            return initial_data 
            
        return self.initial_dict.get(step, {}) 

    def get_form(self, step=None, data=None, files=None):
        form = super(JobWizard, self).get_form(step, data, files)
        if step is None:
            step = self.steps.current

        if step == 'third':
            first_step_data = self.get_cleaned_data_for_step('first')
            steps = Step.objects.filter(workflow=first_step_data['workflow'
]).order_by('order')
            form.extra = len(steps)
        return form

The forms:


class JobForm(forms.ModelForm):
    start_date = forms.DateTimeField(widget=forms.DateTimeInput, initial=
timezone.now())
    workflow = forms.ModelChoiceField(queryset=Workflow.objects.all(),widget
=forms.TextInput(attrs={'readonly':'readonly'}))
    creator = forms.ModelChoiceField(queryset=User.objects.all(),widget=
forms.TextInput(attrs={'readonly':'readonly'}))
    class Meta:
        model = Job
        exclude = ('creation_date', 'paused', 'paused_until', 'completed')


class TaskForm(forms.ModelForm):
    class Meta:
        model = Task
        exclude = ('job', 'finished', )

TaskFormSet = modelformset_factory(Task, form=TaskForm )



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/03c566c7-a69b-4185-9d53-46dee1b27982%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to