コード例 #1
0
ファイル: models.py プロジェクト: hjunqq/myfish
    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)
コード例 #2
0
    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)
コード例 #3
0
 def test_russian(self):
     self.assertEquals(chinese_slugify(u'Компьютер'), 'Kompiuter')
コード例 #4
0
 def test_polyphone_word(self):
     self.assertEquals(chinese_slugify(u'还是还钱吧'), 'HaiShi-Huan-Qian-Ba')