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( u"Maximum number of retries exceeded") retries += 1 self.slug = "{}-{}".format(slug, retries) 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()]) # 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)
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(u"Maximum number of retries exceeded") retries += 1 self.slug = "{}-{}".format(slug, retries) super(Location, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.question = strip_tags(self.question) self.intro = sanitizeHtml(self.intro) if not self.slug: to_slug_entry = self.question chk = Discussion.objects.filter(question=self.question) if len(chk) > 0: to_slug_entry = self.question + '-' + str(len(chk)) self.slug = slugify(to_slug_entry) super(Discussion, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.title = strip_tags(self.title) self.question = sanitizeHtml(self.question) if not self.pk: to_slug_entry = self.title chk = Poll.objects.filter(title=self.title) if len(chk): to_slug_entry = self.title + '-' + str(len(chk)) self.slug = slugify(to_slug_entry) super(Poll, self).save(*args, **kwargs)
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)
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.title = strip_tags(self.title) self.content = sanitizeHtml(self.content) if self.pk: self.edited = True slug = slugify(self.title) if not self.slug: 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 ValidationError(u"Maximum number of retries exceeded") retries += 1 self.slug = "{}-{}".format(slug, retries) super(News, self).save(*args, **kwargs)
def save(self, *args, **kwargs): # Clean user input data self.name = strip_tags(self.name) if len(self.name) >= 64: self.name = truncatesmart(self.name, 60) self.description = sanitizeHtml(self.description) # Create unique SEO-frinedly slug slug = slugify(self.name) 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 ValidationError(u"Maximum number of retries exceeded") retries += 1 self.slug = "{}-{}".format(slug, retries) super(Idea, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.comment = sanitizeHtml(self.comment) if not self.pk: mention_notify(self) super(CustomComment, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.description = sanitizeHtml(self.description) super(SocialForumTopic, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.content = sanitizeHtml(self.content) if self.pk: # The owner or the mod has edited the entry. self.is_edited = True super(SocialForumEntry, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.description = sanitizeHtml(self.description) if not self.authors_group: self.authors_group = EtherpadGroup.objects.create(name=self.name) super(SocialProject, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.name = strip_tags(self.name) self.description = sanitizeHtml(self.description) super(Task, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.content = sanitizeHtml(self.content) super(BlogEntry, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.comment = sanitizeHtml(self.comment) super(CustomComment, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.content = sanitizeHtml(self.content) if self.pk is not None: self.is_edited = True super(Entry, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.description = sanitizeHtml(self.description) super(SocialProject, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.content = sanitizeHtml(self.content) if self.pk: # Właściciel lub moderator wyedytował wpis. self.is_edited = True super(SocialForumEntry, self).save(*args, **kwargs)