def save(self, *args, **kwargs): slug = slugify(self.nom) self.slug = slug suffix = 2 while Interseccion.objects.filter(slug=self.slug).exists(): self.slug = "%s-%d" % (slug, suffix) suffix = suffix + 1 super(Interseccion, self).save(*args, **kwargs)
def save(self, *args, **kwargs): # Generar el SLUG a partir del origen y destino del recorrido try: self.slug = slugify(self.nombre + " desde " + self.inicio + " hasta " + self.fin) except Exception: self.slug = slugify(self.nombre) self.slug = self.slug[:200] self.ruta_simple = self.ruta.simplify(0.0001, True) # # Asegurarse de que no haya 'inicio' y/o 'fin' invalidos # assert ( # self.inicio != self.fin # and self.inicio != '' # and self.fin != '' # ), "Los campos 'inicio' y 'fin' no pueden ser vacios y/o iguales" # Ejecutar el SAVE original super(Recorrido, self).save(*args, **kwargs)
def get_absolute_url(self, argentina=None): return reverse( 'administrativearea', kwargs={ **({ 'country_code': self.country_code } if self.country_code else {}), 'osm_type': self.osm_type, 'osm_id': self.osm_id, 'slug': slugify(self.name), }, )
def save(self, *args, **kwargs): def alphanumeric_sort(objects_list, sort_key): """ Sort a list of objects by a given key This function sort a list of objects by a given key common across the objects Sorting can be implemented on keys that are either alphabets, integers or both """ import re convert = lambda text: int(text) if text.isdigit() else text alphanum_key = lambda key: [ convert(c) for c in re.split("([0-9]+)", getattr(key, sort_key)) ] return sorted(objects_list, key=alphanum_key, reverse=True) if not self.slug: baseslug = slugify(self.nom) allslugs = [ p.slug for p in alphanumeric_sort( Poi.objects.only('slug').filter( slug__startswith=baseslug).filter( slug__regex=r'^' + baseslug + r'(-\d*)?$'), 'slug') ] if len(allslugs) == 0: self.slug = baseslug elif len(allslugs) == 1: self.slug = baseslug + '-2' else: try: num = allslugs[0].split('-')[-1] try: num = int(num) except ValueError as e: num = 0 self.slug = baseslug + '-' + str(num + 1) except Exception as e: print('BASE: ' + baseslug) print(allslugs) print(str(e)) super(Poi, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.slug = slugify(self.nombre) super(Linea, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.slug = slugify(self.nombre) # if self.poligono: # self.centro = self.poligono.centroid super(Ciudad, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.slug = slugify(self.nombre) if self.poligono: self.centro = self.poligono.centroid super(Provincia, self).save(*args, **kwargs)
def uslugify(string): return slugify(string)