def get_context_data(self, form, **kwargs):
     
     context = super(ClimateTranslatorWizard, self).get_context_data(form=form, **kwargs)
               
     # before rendering of first form: send data and geometry choices 
     if self.steps.current == self.steps.first:
         #context.update({'datasets':  json.dumps(ocgisDatasets.datasets) }) # FIXME ?
         context.update({'geometries':  json.dumps(ocgisGeometries.geometries) })
         
     elif self.steps.current == "1":  # note: string type
         context.update({'calculations':  json.dumps(ocgisCalculations.calcs) }) 
             
     # before very last view: create summary of user choices
     elif self.steps.current == self.steps.last:
         job_data = {}
         # retrieve form data for all previous views
         for step in self.steps.all:
             cleaned_data = self.get_cleaned_data_for_step(step) 
             
             # first form
             if step == '0':                
                 job_data['data_type'] = cleaned_data['data_type']  
                 if cleaned_data.has_key('long_name'):
                     job_data['long_name'] = cleaned_data['long_name']  
                 if cleaned_data.has_key('time_frequency'):
                     job_data['time_frequency'] = cleaned_data['time_frequency']                          
                 if cleaned_data.has_key("dataset_category"):
                     job_data['dataset_category'] = cleaned_data['dataset_category'] 
                 if cleaned_data.has_key("dataset"):
                     job_data['dataset'] = cleaned_data['dataset'] 
                 if cleaned_data.has_key("dataset_category2"):
                     job_data['dataset_category2'] = cleaned_data['dataset_category2'] 
                 if cleaned_data.has_key("package_name"):
                     job_data['package_name'] = cleaned_data['package_name']                         
                 if cleaned_data.has_key('geometry_category') and hasText(cleaned_data['geometry_category']):
                     job_data['geometry_category'] = cleaned_data['geometry_category']
                 if cleaned_data.has_key('geometry_subcategory') and hasText(cleaned_data['geometry_subcategory']):
                     job_data['geometry_subcategory'] = cleaned_data['geometry_subcategory']                        
                 if cleaned_data.has_key('geometry_id') and len( cleaned_data['geometry_id'] )>0:
                     job_data['geometry_id'] = formatListForDisplay(cleaned_data['geometry_id'])
                 if cleaned_data.has_key('latmin') and cleaned_data['latmin'] is not None:
                     job_data['latmin'] = float( cleaned_data['latmin'] )
                 if cleaned_data.has_key('latmax') and cleaned_data['latmax'] is not None:
                     job_data['latmax'] = float( cleaned_data['latmax'] )
                 if cleaned_data.has_key('lonmin') and cleaned_data['lonmin'] is not None:
                     job_data['lonmin'] = float( cleaned_data['lonmin'] )
                 if cleaned_data.has_key('lonmax') and cleaned_data['lonmax'] is not None:
                     job_data['lonmax'] = float( cleaned_data['lonmax'] )
                 if cleaned_data.has_key('lat') and cleaned_data['lat'] is not None:
                     job_data['lat'] = float( cleaned_data['lat'] )
                 if cleaned_data.has_key('lon') and cleaned_data['lon'] is not None:
                     job_data['lon'] = float( cleaned_data['lon'] )
                 if cleaned_data.has_key('agg_selection'):
                     job_data['agg_selection'] = bool(cleaned_data['agg_selection'])
                 if cleaned_data.has_key('datetime_start') and cleaned_data['datetime_start'] is not None:
                     job_data['datetime_start'] = cleaned_data['datetime_start']
                 if cleaned_data.has_key('datetime_stop') and cleaned_data['datetime_stop'] is not None:
                     job_data['datetime_stop'] = cleaned_data['datetime_stop']
                 if cleaned_data.has_key('timeregion_month') and cleaned_data['timeregion_month'] is not None:
                     job_data['timeregion_month'] = get_month_string( cleaned_data['timeregion_month'] )
                 if cleaned_data.has_key('timeregion_year') and cleaned_data['timeregion_year'] is not None:
                     job_data['timeregion_year'] = cleaned_data['timeregion_year']
              
             # second form       
             if step == '1':
                 if cleaned_data.has_key('calc') and cleaned_data['calc'] is not None and cleaned_data['calc'] != '':
                     job_data['calc'] = ocgisCalculations.getCalc(cleaned_data['calc'])["name"]             
                 if cleaned_data.has_key('par1') and cleaned_data['par1'] is not None:
                     job_data['par1'] = cleaned_data['par1']
                 if cleaned_data.has_key('par2') and cleaned_data['par2'] is not None:
                     job_data['par2'] = cleaned_data['par2']
                 if cleaned_data.has_key('par3') and cleaned_data['par3'] is not None:
                     job_data['par3'] = cleaned_data['par3']
                 if cleaned_data.has_key('calc_group'):
                     calc_groups =[]
                     for group in cleaned_data['calc_group']:
                         calc_groups.append(ocgisChoices(Config.CALCULATION_GROUP)[group])  
                         job_data['calc_group'] = formatListForDisplay(calc_groups)                           
                 if cleaned_data.has_key('calc_raw'):
                     job_data['calc_raw'] = bool(cleaned_data['calc_raw'])   
                 if cleaned_data.has_key('spatial_operation'):
                     job_data['spatial_operation'] = ocgisChoices(Config.SPATIAL_OPERATION)[cleaned_data['spatial_operation']]
                 if cleaned_data.has_key('aggregate'):
                     job_data['aggregate'] = bool(cleaned_data['aggregate'])       
                 if cleaned_data.has_key('output_format'):
                     job_data['output_format'] = ocgisChoices(Config.OUTPUT_FORMAT)[cleaned_data['output_format']]   
                 if cleaned_data.has_key('prefix'):
                     job_data['prefix'] = cleaned_data['prefix']    
                 if cleaned_data.has_key('with_auxiliary_files'):
                     job_data['with_auxiliary_files'] = bool(cleaned_data['with_auxiliary_files'])                       
                         
         context.update({'job_data': job_data})
                 
     return context
Exemple #2
0
    def get_context_data(self, form, **kwargs):

        context = super(OpenClimateGisWizard, self).get_context_data(form=form, **kwargs)

        # before rendering of first form: send data and geometry choices
        if self.steps.current == self.steps.first:
            context.update({"datasets": json.dumps(ocgisDatasets.datasets)})
            context.update({"geometries": json.dumps(ocgisGeometries.geometries)})

        elif self.steps.current == "1":  # note: string type
            context.update({"calculations": json.dumps(ocgisCalculations.calcs)})

        # before very last view: create summary of user choices
        elif self.steps.current == self.steps.last:
            job_data = {}
            # retrieve form data for all previous views
            for step in self.steps.all:
                if step != self.steps.current:
                    cleaned_data = self.get_cleaned_data_for_step(step)
                    if cleaned_data.has_key("dataset_category"):
                        job_data["dataset_category"] = cleaned_data["dataset_category"]
                    if cleaned_data.has_key("dataset"):
                        job_data["dataset"] = cleaned_data["dataset"]
                    if cleaned_data.has_key("variable"):
                        job_data["variable"] = cleaned_data["variable"]
                    if cleaned_data.has_key("geometry") and hasText(cleaned_data["geometry"]):
                        job_data["geometry"] = cleaned_data["geometry"]
                    if cleaned_data.has_key("geometry_id") and len(cleaned_data["geometry_id"]) > 0:
                        job_data["geometry_id"] = formatListForDisplay(cleaned_data["geometry_id"])
                    if cleaned_data.has_key("latmin") and cleaned_data["latmin"] is not None:
                        job_data["latmin"] = float(cleaned_data["latmin"])
                    if cleaned_data.has_key("latmax") and cleaned_data["latmax"] is not None:
                        job_data["latmax"] = float(cleaned_data["latmax"])
                    if cleaned_data.has_key("lonmin") and cleaned_data["lonmin"] is not None:
                        job_data["lonmin"] = float(cleaned_data["lonmin"])
                    if cleaned_data.has_key("lonmax") and cleaned_data["lonmax"] is not None:
                        job_data["lonmax"] = float(cleaned_data["lonmax"])
                    if cleaned_data.has_key("lat") and cleaned_data["lat"] is not None:
                        job_data["lat"] = float(cleaned_data["lat"])
                    if cleaned_data.has_key("lon") and cleaned_data["lon"] is not None:
                        job_data["lon"] = float(cleaned_data["lon"])
                    if cleaned_data.has_key("datetime_start") and cleaned_data["datetime_start"] is not None:
                        job_data["datetime_start"] = cleaned_data["datetime_start"]
                    if cleaned_data.has_key("datetime_stop") and cleaned_data["datetime_stop"] is not None:
                        job_data["datetime_stop"] = cleaned_data["datetime_stop"]
                    if cleaned_data.has_key("timeregion_month") and cleaned_data["timeregion_month"] is not None:
                        job_data["timeregion_month"] = get_month_string(cleaned_data["timeregion_month"])
                    if cleaned_data.has_key("timeregion_year") and cleaned_data["timeregion_year"] is not None:
                        job_data["timeregion_year"] = cleaned_data["timeregion_year"]
                    if cleaned_data.has_key("calc") and cleaned_data["calc"] is not None and cleaned_data["calc"] != "":
                        job_data["calc"] = ocgisCalculations.getCalc(cleaned_data["calc"])["name"]
                    if cleaned_data.has_key("par1") and cleaned_data["par1"] is not None:
                        job_data["par1"] = cleaned_data["par1"]
                    if cleaned_data.has_key("par2") and cleaned_data["par2"] is not None:
                        job_data["par2"] = cleaned_data["par2"]
                    if cleaned_data.has_key("par3") and cleaned_data["par3"] is not None:
                        job_data["par3"] = cleaned_data["par3"]
                    if cleaned_data.has_key("calc_group"):
                        calc_groups = []
                        for group in cleaned_data["calc_group"]:
                            calc_groups.append(ocgisChoices(Config.CALCULATION_GROUP)[group])
                            job_data["calc_group"] = formatListForDisplay(calc_groups)
                    if cleaned_data.has_key("calc_raw"):
                        job_data["calc_raw"] = bool(cleaned_data["calc_raw"])
                    if cleaned_data.has_key("spatial_operation"):
                        job_data["spatial_operation"] = ocgisChoices(Config.SPATIAL_OPERATION)[
                            cleaned_data["spatial_operation"]
                        ]
                    if cleaned_data.has_key("aggregate"):
                        job_data["aggregate"] = bool(cleaned_data["aggregate"])
                    if cleaned_data.has_key("output_format"):
                        job_data["output_format"] = ocgisChoices(Config.OUTPUT_FORMAT)[cleaned_data["output_format"]]
                    if cleaned_data.has_key("prefix"):
                        job_data["prefix"] = cleaned_data["prefix"]
                    if cleaned_data.has_key("with_auxiliary_files"):
                        job_data["with_auxiliary_files"] = bool(cleaned_data["with_auxiliary_files"])

            context.update({"job_data": job_data})

        return context