def filter_species(self, src, val): try: species = Species.objects.get(category=Species.SPECIES, name=val) except Species.DoesNotExist: msg = "L'espèce {} n'existe pas dans Geotrek. Merci de la créer.".format(val) raise RowImportError(msg) return species
def filter_species(self, src, val): (name, elevation, period, practice_names, url) = val species = Species(category=Species.REGULATORY) species.name = name if period: period = period.split(self.separator) for i in range(1, 13): if str(i) in period: setattr(species, 'period{:02}'.format(i), True) species.url = url species.radius = elevation practices = [] if practice_names: for practice_name in practice_names.split(self.separator): try: practice = SportPractice.objects.get(name=practice_name) except SportPractice.DoesNotExist: msg = "La pratique sportive {} n'existe pas dans Geotrek. Merci de l'ajouter.".format(practice_name) raise RowImportError(msg) practices.append(practice) species.save() species.practices.add(*practices) return species