1

I am having an issue with persisting data from one page to the next in a SessionWizardView on my production server. It works fine on my local machine but I kept getting an Exception Value: list index out of range error when I tried to access the value of the list on a subsequent page.

As a result I am trying to use the get_cleared_data_for_step method but with no success.

My current views.py

PATH_ONE_IMAGES =   ['P1D1.jpg', 'P2D2.jpg', 'P3D3.jpg', 'P4D4.jpg', 'P5D5.jpg']

class SurveyWizardOne(SessionWizardView):                      

    def get_context_data(self, form, **kwargs):
        context = super(SurveyWizardOne, self).get_context_data(form, **kwargs)  
        if self.steps.current in ['5','6','7','8','9','10']:
            step = int(self.steps.current)

            if step in (5, 6, 7):
                image = random.choice(PATH_ONE_IMAGES)   
                images.insert(step - 5, image)        
                PATH_ONE_IMAGES.remove(image)
                context['display_image'] = image

            elif step == 8:                          
                images[0] = self.get_cleaned_data_for_step(5)
                images[1] = self.get_cleaned_data_for_step(6)
                images[2] = self.get_cleaned_data_for_step(7)     

                print 'This is your first image', images[0]
                print 'This is your second image', images[1]
                print 'This is your third image', images[2]

Current outcome

This is your first image None
This is your second image None
This is your third image None

Expected outcome (sample)

This is your first image P1D1.jpg
This is your second image P3D3.jpg
This is your third image P4D4.jpg

What am I doing wrong? I can find very little info on how to implement the get_cleaned_data_for_step method online except for these two SO questions [1], [2] and going by these my implementation looks like it should work.

What annoys me most is that my previous solution works fine on my local machine but does not work in production.

Any help with this would be hugely appreciated. Thanks

Deepend

Community
  • 1
  • 1
Deepend
  • 4,057
  • 17
  • 60
  • 101
  • How do you pass data to the form in step 5? Do you provide it manually or do you use some initial data? – mariodev Nov 23 '14 at 22:43
  • On step 5 the only data added to the form is the `image` e.g. P1D1.jpg. This is generated by `random.choice(PATH_ONE_IMAGES)` the value of which I then save into a list (step 5 - `images[0], step 6 - `images[1], step 7 - images[2]). I then want to access this list and its values on step 8 so I can re-display whichever images where shown to the user. Does that answer your question? – Deepend Nov 24 '14 at 10:29

0 Answers0