def _slugify_title(self): """Slugify the Entry title, but ensure it's less than the maximum number of characters. This method also ensures that a slug is unique by appending a timestamp to any duplicate slugs. """ # Restrict slugs to their maximum number of chars, but don't split mid-word self.slug = chinese_slugify(self.title) while len(self.slug) > 255: self.slug = '-'.join(self.slug.split('-')[:-1]) # Is the same slug as another entry? if Entry.objects.filter(slug=self.slug).exclude(id=self.id).exists(): # Append time to differentiate. self.slug = self._insert_timestamp(self.slug)
def test_russian(self): self.assertEquals(chinese_slugify(u'Компьютер'), 'Kompiuter')
def test_polyphone_word(self): self.assertEquals(chinese_slugify(u'还是还钱吧'), 'HaiShi-Huan-Qian-Ba')