def create_declar3(self, idfoy=None, description=None): ''' Creates a Declar3Form from compo.scenario data ''' if idfoy is None: idfoy = 0 if description is None: print 'a description should be provided' # TODO convert this to exception declar = self.scenario.declar[idfoy] cleaned_indiv = extract_foy_indiv(self.scenario, idfoy=idfoy) data = declar def indiv2foy(varname, quifoy): ''' Yields the field of the foy corresponding to the varname ''' convert = foy2of_dict() value = None for field in convert.keys(): if field2quifoy(field) == quifoy: if convert[field] == varname: value = field return value for person in cleaned_indiv.itervalues(): for varname, value in person.iteritems(): quifoy = person['quifoy'] field = indiv2foy(varname, quifoy) data[field] = value form = Declar3Form(data=declar, description=description) return form
def create_declar3(self, idfoy = None, description=None): ''' Creates a Declar3Form from compo.scenario data ''' if idfoy is None: idfoy = 0 if description is None: print 'a description should be provided' # TODO convert this to exception declar = self.scenario.declar[idfoy] cleaned_indiv = extract_foy_indiv(self.scenario, idfoy=idfoy) data = declar def indiv2foy(varname, quifoy): ''' Yields the field of the foy corresponding to the varname ''' convert = foy2of_dict() value = None for field in convert.keys(): if field2quifoy(field) == quifoy: if convert[field] == varname: value = field return value for person in cleaned_indiv.itervalues(): for varname, value in person.iteritems(): quifoy = person['quifoy'] field = indiv2foy(varname, quifoy) data[field] = value form = Declar3Form(data=declar, description=description) return form
def get_declar3(self, form=None, idfoy=0): ''' Gets declar values in compo.scenario from Declar3Form ''' declar = self.scenario.declar[idfoy] # Build a dict of individulas present on the declar cleaned_indiv = extract_foy_indiv(self.scenario, idfoy=idfoy) convert = foy2of_dict() data = form.cleaned_data for field, value in data.iteritems(): if field in convert.keys(): quifoy = field2quifoy(field) varname = convert[field] for person in cleaned_indiv.itervalues(): if person['quifoy'] == quifoy: person[varname] = value else: declar[field] = value
def get_declar3(self, form = None, idfoy = 0): ''' Gets declar values in compo.scenario from Declar3Form ''' declar = self.scenario.declar[idfoy] # Build a dict of individulas present on the declar cleaned_indiv = extract_foy_indiv(self.scenario, idfoy= idfoy) convert = foy2of_dict() data = form.cleaned_data for field, value in data.iteritems(): if field in convert.keys(): quifoy = field2quifoy(field) varname = convert[field] for person in cleaned_indiv.itervalues(): if person['quifoy'] == quifoy: person[varname] = value else: declar[field] = value