• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.slugify函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中misago.core.utils.slugify函数的典型用法代码示例。如果您正苦于以下问题:Python slugify函数的具体用法?Python slugify怎么用?Python slugify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了slugify函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: create_default_ranks

def create_default_ranks(apps, schema_editor):
    Rank = apps.get_model('misago_users', 'Rank')

    team = Rank.objects.create(
        name=_("Forum team"),
        slug=slugify(_("Forum team")),
        title=_("Team"),
        css_class='team',
        is_tab=True,
        is_on_index=True,
        order=0)

    member = Rank.objects.create(
        name=_("Members"),
        slug=slugify(_("Members")),
        is_default=True,
        order=1)

    Role = apps.get_model('misago_acl', 'Role')

    team.roles.add(Role.objects.get(name=_("Moderator")))
    team.roles.add(Role.objects.get(name=_("Private threads moderator")))
    team.roles.add(Role.objects.get(name=_("Deleting users")))

    member.roles.add(Role.objects.get(name=_("Private threads")))
开发者ID:Backenkoehler,项目名称:Misago,代码行数:25,代码来源:0004_default_ranks.py


示例2: post_thread

def post_thread(
        category,
        title='Test thread',
        poster='Tester',
        is_global=False,
        is_pinned=False,
        is_unapproved=False,
        is_hidden=False,
        is_closed=False,
        started_on=None
):
    started_on = started_on or timezone.now()

    kwargs = {
        'category': category,
        'title': title,
        'slug': slugify(title),
        'started_on': started_on,
        'last_post_on': started_on,
        'is_unapproved': is_unapproved,
        'is_hidden': is_hidden,
        'is_closed': is_closed,
    }

    if is_global:
        kwargs['weight'] = 2
    elif is_pinned:
        kwargs['weight'] = 1

    try:
        kwargs.update({
            'starter': poster,
            'starter_name': poster.username,
            'starter_slug': poster.slug,
            'last_poster': poster,
            'last_poster_name': poster.username,
            'last_poster_slug': poster.slug,
        })
    except AttributeError:
        kwargs.update({
            'starter_name': poster,
            'starter_slug': slugify(poster),
            'last_poster_name': poster,
            'last_poster_slug': slugify(poster),
        })

    thread = Thread.objects.create(**kwargs)
    reply_thread(
        thread,
        poster=poster,
        posted_on=started_on,
        is_hidden=is_hidden,
        is_unapproved=is_unapproved,
    )

    return thread
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:56,代码来源:testutils.py


示例3: create_default_categories_tree

def create_default_categories_tree(apps, schema_editor):
    Category = apps.get_model('misago_categories', 'Category')

    Category.objects.create(
        special_role='private_threads',
        name='Private',
        slug='private',
        lft=1,
        rght=2,
        tree_id=0,
        level=0,
    )

    root = Category.objects.create(
        special_role='root_category',
        name='Root',
        slug='root',
        lft=3,
        rght=6,
        tree_id=1,
        level=0,
    )

    category_name = _("First category")

    category = Category.objects.create(
        parent=root,
        lft=4,
        rght=5,
        tree_id=1,
        level=1,
        name=category_name,
        slug=slugify(category_name),
        css_class='accent'
    )
开发者ID:1905410,项目名称:Misago,代码行数:35,代码来源:0002_default_categories.py


示例4: __call__

    def __call__(self, value):
        slug = slugify(value)

        if not slug.replace('-', ''):
            raise ValidationError(self.error_short)

        if len(slug) > 255:
            raise ValidationError(self.error_long)
开发者ID:Backenkoehler,项目名称:Misago,代码行数:8,代码来源:validators.py


示例5: set_last_post

 def set_last_post(self, post):
     self.last_post_on = post.posted_on
     self.last_post = post
     self.last_poster = post.poster
     self.last_poster_name = post.poster_name
     if post.poster:
         self.last_poster_slug = post.poster.slug
     else:
         self.last_poster_slug = slugify(post.poster_name)
开发者ID:Backenkoehler,项目名称:Misago,代码行数:9,代码来源:thread.py


示例6: create_default_forums_tree

def create_default_forums_tree(apps, schema_editor):
    Forum = apps.get_model("misago_forums", "Forum")

    Forum.objects.create(
        special_role="private_threads", role="forum", name="Private", slug="private", lft=1, rght=2, tree_id=0, level=0
    )

    root = Forum.objects.create(
        special_role="root_category", role="category", name="Root", slug="root", lft=3, rght=10, tree_id=1, level=0
    )

    category_name = _("First category")
    forum_name = _("First forum")
    redirect_name = _("Misago support forums")
    redirect_link = _("http://misago-project.org")

    category = Forum.objects.create(
        parent=root,
        lft=4,
        rght=9,
        tree_id=1,
        level=1,
        role="category",
        name=category_name,
        slug=slugify(category_name),
        css_class="accent",
    )

    Forum.objects.create(
        parent=category, lft=5, rght=6, tree_id=1, level=2, role="forum", name=forum_name, slug=slugify(forum_name)
    )

    Forum.objects.create(
        parent=category,
        lft=7,
        rght=8,
        tree_id=1,
        level=2,
        role="redirect",
        name=redirect_name,
        slug=slugify(redirect_name),
        redirect_url=redirect_link,
    )
开发者ID:ZerGabriel,项目名称:Misago,代码行数:43,代码来源:0002_default_forums.py


示例7: set_username

    def set_username(self, new_username, changed_by=None):
        if new_username != self.username:
            old_username = self.username
            self.username = new_username
            self.slug = slugify(new_username)

            if self.pk:
                changed_by = changed_by or self
                self.record_name_change(changed_by, new_username, old_username)
                username_changed.send(sender=self)
开发者ID:nescode,项目名称:Misago,代码行数:10,代码来源:user.py


示例8: post_thread

def post_thread(forum, title='Test thread', poster='Tester', is_pinned=False,
                is_moderated=False, is_hidden=False, is_closed=False,
                started_on=None):
    started_on = started_on or timezone.now()

    kwargs = {
        'forum': forum,
        'title': title,
        'slug': slugify(title),
        'started_on': started_on,
        'last_post_on': started_on,
        'is_pinned': is_pinned,
        'is_moderated': is_moderated,
        'is_hidden': is_hidden,
        'is_closed': is_closed,
    }

    try:
        kwargs.update({
            'starter': poster,
            'starter_name': poster.username,
            'starter_slug': poster.slug,
            'last_poster': poster,
            'last_poster_name': poster.username,
            'last_poster_slug': poster.slug,
            })
    except AttributeError:
        kwargs.update({
            'starter_name': poster,
            'starter_slug': slugify(poster),
            'last_poster_name': poster,
            'last_poster_slug': slugify(poster),
        })

    thread = Thread.objects.create(**kwargs)
    reply_thread(thread,
        poster=poster,
        posted_on=thread.last_post_on,
        is_moderated=is_moderated)

    return thread
开发者ID:Backenkoehler,项目名称:Misago,代码行数:41,代码来源:testutils.py


示例9: set_first_post

    def set_first_post(self, post):
        self.started_on = post.posted_on
        self.first_post = post
        self.starter = post.poster
        self.starter_name = post.poster_name
        if post.poster:
            self.starter_slug = post.poster.slug
        else:
            self.starter_slug = slugify(post.poster_name)

        self.is_moderated = post.is_moderated
        self.is_hidden = post.is_hidden
开发者ID:Backenkoehler,项目名称:Misago,代码行数:12,代码来源:thread.py


示例10: set_username

    def set_username(self, new_username, changed_by=None):
        if new_username != self.username:
            old_username = self.username
            self.username = new_username
            self.slug = slugify(new_username)

            if self.pk:
                changed_by = changed_by or self
                self.record_name_change(
                    changed_by, new_username, old_username)

                from misago.users.signals import username_changed
                username_changed.send(sender=self)
开发者ID:fengrussell,项目名称:Misago,代码行数:13,代码来源:user.py


示例11: post_thread

def post_thread(forum, title='Test thread', weight=0, poster='Tester',
                is_moderated=False, is_hidden=False, is_closed=False,
                started_on=None):
    started_on = started_on or timezone.now()

    kwargs = {
        'forum': forum,
        'weight': weight,
        'title': title,
        'slug': slugify(title),
        'started_on': started_on,
        'last_post_on': started_on,
        'is_moderated': is_moderated,
        'is_hidden': is_hidden,
        'is_closed': is_closed,
    }

    try:
        kwargs.update({
            'starter': poster,
            'starter_name': poster.username,
            'starter_slug': poster.slug,
            'last_poster': poster,
            'last_poster_name': poster.username,
            'last_poster_slug': poster.slug,
            })
    except AttributeError:
        kwargs.update({
            'starter_name': poster,
            'starter_slug': slugify(poster),
            'last_poster_name': poster,
            'last_poster_slug': slugify(poster),
        })

    thread = Thread.objects.create(**kwargs)
    forum.synchronize()
    forum.save()
    return thread
开发者ID:dahito,项目名称:Misago,代码行数:38,代码来源:testutils.py


示例12: test_valid_slugify_output

    def test_valid_slugify_output(self):
        """Misago's slugify correctly slugifies string"""
        test_cases = (
            (u'Bob', u'bob'),
            (u'Eric The Fish', u'eric-the-fish'),
            (u'John   Snow', u'john-snow'),
            (u'J0n', u'j0n'),
            (u'An###ne', u'anne'),
            (u'S**t', u'st'),
            (u'Łók', u'lok'),
        )

        for original, slug in test_cases:
            self.assertEqual(slugify(original), slug)
开发者ID:Didan,项目名称:Misago,代码行数:14,代码来源:test_utils.py


示例13: like_post

def like_post(post, user=None, username=None):
    if not post.last_likes:
        post.last_likes = []

    if user:
        like = post.postlike_set.create(
            category=post.category,
            thread=post.thread,
            user=user,
            user_name=user.username,
            user_slug=user.slug,
            user_ip='127.0.0.1'
        )

        post.last_likes = [
            {
                'id': user.id,
                'username': user.username
            }
        ] + post.last_likes
    else:
        like = post.postlike_set.create(
            category=post.category,
            thread=post.thread,
            user_name=username,
            user_slug=slugify(username),
            user_ip='127.0.0.1'
        )

        post.last_likes = [
            {
                'id': None,
                'username': username
            }
        ] + post.last_likes

    post.likes += 1
    post.save()

    return like
开发者ID:1905410,项目名称:Misago,代码行数:40,代码来源:testutils.py


示例14: set_title

 def set_title(self, title):
     self.title = title
     self.slug = slugify(title)
开发者ID:Backenkoehler,项目名称:Misago,代码行数:3,代码来源:thread.py


示例15: set_name

 def set_name(self, name):
     self.name = name
     self.slug = slugify(name)
开发者ID:David1119,项目名称:Misago,代码行数:3,代码来源:models.py


示例16: get_by_username_or_email

 def get_by_username_or_email(self, login):
     queryset = models.Q(slug=slugify(login))
     queryset = queryset | models.Q(email_hash=hash_email(login))
     return self.get(queryset)
开发者ID:nikescar,项目名称:Misago,代码行数:4,代码来源:user.py


示例17: get_by_username

 def get_by_username(self, username):
     return self.get(slug=slugify(username))
开发者ID:nikescar,项目名称:Misago,代码行数:2,代码来源:user.py



注:本文中的misago.core.utils.slugify函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python messages.success函数代码示例发布时间:2022-05-27
下一篇:
Python shortcuts.paginate函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap