Esempio n. 1
0
 def _create_data_validation(self, field):
     allow_blank = not util_model.is_mandatory(field)
     dv = None
     if util_model.is_lookup_field(field) and util_model.has_related_objects(field):
         # here we expect that the lookup has been registered as named range.
         # The name of the lookup is the lookup model name (see _write_lookups)
         strict = util_model.is_strict_lookup_field(field)
         lookup_name = util_model.get_field_lookup_model_name(field)
         dv = util_xls.create_list_validation(lookup_name, strict=strict, allow_blank=allow_blank)
     elif util_model.has_choices(field):
         # Should we also add the choices in the Lookups sheet?
         values = [str(choice[1]) for choice in util_model.get_field_choices(field)]
         strict = True
         dv = util_xls.create_list_validation(values, strict=strict, allow_blank=allow_blank)
     elif util_model.is_boolean_field(field):
         allow_blank = True  # blank is False
         values = ['Y', 'N']
         strict = False
         dv = util_xls.create_list_validation(values, strict=strict, allow_blank=allow_blank)
     # species. Hack! Last minute update. We want species data validation on animals only
     elif util_model.is_species_observation_field(field)\
             and self.file_species is not None \
             and field.model._meta.app_label == 'animals':
         # we expect here that a range call species has been registered (see _write_species)
         strict = False
         dv = util_xls.create_list_validation('species', strict=strict, allow_blank=allow_blank)
     return dv
Esempio n. 2
0
 def _build_lookups_dict(self):
     """
     Return a dict with key=lookup name
     and value=lookup values (list)
     :return:
     """
     datasheet_models = [mapping.model for mapping in DATASHEET_MODELS_MAPPING]
     result = OrderedDict()
     for model in datasheet_models:
         lookup_fields = util_model.get_lookup_fields(model)
         for field in lookup_fields:
             values = self._build_lookup_validation_list(field)
             lookup_name = util_model.get_field_lookup_model_name(field)
             if lookup_name not in result:
                 result[lookup_name] = values
     return result