Beispiel #1
0
    def save(self, *args, **kwargs):
        self.description = sanitizeHtml(self.description)
        if self.parent is not None:
            self.country_code = self.parent.country_code
        self.parent_list = ",".join([str(x) for x in self.get_parent_id_list()])

        # Create unique slug that includes country code for SEO
        slug = slugify("-".join([self.name, self.country_code]))
        self.slug = slug
        success = False
        retries = 0
        while not success:
            check = self.__class__.objects.filter(slug=self.slug).exclude(pk=self.pk).count()
            if not check:
                success = True
            else:
                # We assume maximum number of 50 elements with the same name.
                # But the loop should be breaked if something went wrong.
                if retries >= 50:
                    raise models.ValidationError("Maximum number of retries exceeded")
                retries += 1
                self.slug = "{}-{}".format(slug, retries)

        # We check whether the image has changed and if needed, we delete the old one
        # FIXME: we are using signal for now, this is no longer necessary and deprecated.
        try:
            orig = Location.objects.get(pk=self.pk)
            if not "nowhere" in orig.image.name and orig.image != self.image:
                delete_image(orig.image.path)
                delete_image(rename_background_file(orig.image.path))
        except Location.DoesNotExist:
            pass
        super(Location, self).save(*args, **kwargs)
Beispiel #2
0
 def save(self, *args, **kwargs):
     self.description = sanitizeHtml(self.description)
     # Generujemy odpowiedni slug
     if not self.slug:
         slug_entry = slugify('-'.join([self.name, self.country_code]))
         chk = Location.objects.filter(slug__icontains=slug_entry).count()
         if chk:
             slug_entry = slug_entry + '-' + str(chk)
         self.slug = slug_entry
     # Sprawdzamy, czy zmienił się obrazek i w razie potrzeby usuwamy stary
     try:
         orig = Location.objects.get(pk=self.pk)
         if not u'nowhere' in orig.image.name and orig.image != self.image:
             delete_image(orig.image.path)
             delete_image(rename_background_file(orig.image.path))
     except Location.DoesNotExist:
         pass
     super(Location, self).save(*args, **kwargs)
Beispiel #3
0
 def save(self, *args, **kwargs):
     if self.description:
         self.description = strip_tags(self.description)
     if not self.clean_username:
         clean_username = slugify(self.user.get_full_name())
         chk = UserProfile.objects.filter(clean_username=clean_username).count()
         if chk:
             self.clean_username = "******" % (clean_username, self.pk)
         else:
             self.clean_username = clean_username
     # Sprawdzamy, czy zmienił się obrazek i w razie potrzeby usuwamy stary
     if self.pk:
         try:
             orig = UserProfile.objects.get(pk=self.pk)
             if not "background.jpg" in orig.image.name and orig.image != self.image:
                 delete_image(orig.image.path)
                 delete_image(rename_background_file(orig.image.path))
         except UserProfile.DoesNotExist:
             pass
     super(UserProfile, self).save(*args, **kwargs)
Beispiel #4
0
 def save(self, *args, **kwargs):
     if self.description:
         self.description = strip_tags(self.description)
     if not self.clean_username:
         clean_username = slugify(self.user.get_full_name())
         chk = UserProfile.objects.filter(clean_username=clean_username).count()
         if chk:
             self.clean_username = "******" % (clean_username, self.pk)
         else:
             self.clean_username = clean_username
     # Sprawdzamy, czy zmienił się obrazek i w razie potrzeby usuwamy stary
     if self.pk:
         try:
             orig = UserProfile.objects.get(pk=self.pk)
             if not u'background.jpg' in orig.image.name and orig.image != self.image:
                 delete_image(orig.image.path)
                 delete_image(rename_background_file(orig.image.path))
         except UserProfile.DoesNotExist:
             pass
     super(UserProfile, self).save(*args, **kwargs)
Beispiel #5
0
 def save(self, *args, **kwargs):
     self.description = sanitizeHtml(self.description)
     if self.parent is not None:
         self.country_code = self.parent.country_code
     # We generate the appropriate slug
     if not self.slug:
         slug_entry = slugify('-'.join([self.name, self.country_code]))
         chk = Location.objects.filter(slug__icontains=slug_entry).count()
         if chk:
             slug_entry = slug_entry + '-' + str(chk)
         self.slug = slug_entry
     # We check whether the image has changed and if needed, we delete the old one
     # FIXME: we are using signal for now, this is no longer necessary and deprecated.
     try:
         orig = Location.objects.get(pk=self.pk)
         if not u'nowhere' in orig.image.name and orig.image != self.image:
             delete_image(orig.image.path)
             delete_image(rename_background_file(orig.image.path))
     except Location.DoesNotExist:
         pass
     super(Location, self).save(*args, **kwargs)
 def save(self, *args, **kwargs):
     self.description = sanitizeHtml(self.description)
     if self.parent is not None:
         self.country_code = self.parent.country_code
     self.parent_list = ",".join([str(x)
                                  for x in self.get_parent_id_list()])
     # We generate the appropriate slug
     if not self.slug:
         slug_entry = slugify('-'.join([self.name, self.country_code]))
         chk = Location.objects.filter(slug__icontains=slug_entry).count()
         if chk:
             slug_entry = slug_entry + '-' + str(chk)
         self.slug = slug_entry
     # We check whether the image has changed and if needed, we delete the old one
     # FIXME: we are using signal for now, this is no longer necessary and deprecated.
     try:
         orig = Location.objects.get(pk=self.pk)
         if not u'nowhere' in orig.image.name and orig.image != self.image:
             delete_image(orig.image.path)
             delete_image(rename_background_file(orig.image.path))
     except Location.DoesNotExist:
         pass
     super(Location, self).save(*args, **kwargs)