1

I am trying to use django SessionWizard view for the forms with 2 steps. ON first step I get file location and on second step process the file contents and write them to db on submit of second step. When I am clicking on submit, the form goes back to first step. I tested it using CookieWizardView and the form works fine with that - I am able to write data to db on submit of second step. For SessionWizardView, I verified that sessions are enabled in my application as per documentation here - Also verified that sessions table is in my db and is non-empty.

Have seen related questions, but not to much help.

Below is the code snippet of my view

    class UploadWizard(SessionWizardView):

    def __init__(self, *args, **kwargs):
        super(UploadWizard, self).__init__(*args, **kwargs)        
        self.uploaded_file = None
        self.ingestable_upload = None
        self.error = None

    form_list = UPLOAD_FORMS
    # TODO: sweep for old files.  Maybe move to S3?
    upload_dir = os.path.join(settings.MEDIA_ROOT, 'uploads')
    file_storage = FileSystemStorage(location=upload_dir)

    def get_template_names(self):
        return [TEMPLATES[self.steps.current]]

    def get_form(self, step=None, data=None, files=None):
        if step is None:
            step = self.steps.current
        form = super(UploadBoxofficeWizard, self).get_form(step, data, files)
        if step == MAP_DATA_STEP:
           # do something
        return form

def process_step(self, form):

        if self.steps.current == PICK_FILE_STEP:
            action = form.cleaned_data.get('action')
            extractor = get_upload_extractor_for_source(form.cleaned_data.get('source'))
            uploaded_file = form.cleaned_data.get('file')
            start_date = form.cleaned_data.get('start_date')
            end_date = form.cleaned_data.get('end_date')
            if action == INGEST_ACTION:
                #do something               
        elif self.steps.current == MAP_DATA_STEP:
            # do something

def done(self, form_list, form_dict, **kwargs):       
        form = form_list[int(MAP_DATA_STEP)]
        num_rows= 0
        if form:
            num_rows = form.cleaned_data[0].get('num_rows')
        return render_to_response('formtools/wizard/show_result.html',{'num_rows':num_rows})

Sessions setup

INSTALLED_APPS = (
    'django.contrib.sessions',
)

MIDDLEWARE_CLASSES = [    
    'django.contrib.sessions.middleware.SessionMiddleware',    
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.RemoteUserMiddleware',    
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

Looking for some help to get ideas on what might be going wrong here. I have followed the steps from documentation but clearly I am missing something.

Community
  • 1
  • 1
Scooby
  • 635
  • 3
  • 9
  • 21

0 Answers0