def clean(self): # invoke superclass cleaning method super(ClimateTranslatorForm2, self).clean() # validate calculation if 'calc' in self.cleaned_data and hasText(self.cleaned_data['calc']) and self.cleaned_data['calc'].lower() != 'none': # calculation group must be selected if len( self.cleaned_data['calc_group'] ) == 0: self._errors["calc_group"] = self.error_class(["Calculation Group(s) not selected."]) # validate keyword values func = self.cleaned_data['calc'] calc = ocgisCalculations.getCalc(func) if 'keywords' in calc: for i, keyword in enumerate(calc["keywords"]): parN = 'par%s' % (i+1) value = self.cleaned_data[parN] if keyword["type"]=="float": try: x = float(value) except ValueError: self._errors[parN] = self.error_class(["Invalid float value for keyword: "+keyword["name"]]) elif keyword["type"] == "string": if "values" in keyword: if not value.lower() in keyword["values"]: self._errors[parN] = self.error_class(["Invalid string value for keyword: "+keyword["name"]]) # if no calculation is selected, there cannot be any temporal grouping else: self.cleaned_data['calc_group'] = None if 'prefix' in self.cleaned_data and re.search(INVALID_CHARS, self.cleaned_data['prefix']): self._errors['prefix'] = self.error_class(["The prefix contains invalid characters."]) if not self.is_valid(): print 'VALIDATION ERRORS: %s' % self.errors # return cleaned data return self.cleaned_data
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