当前位置: 首页>>代码示例>>Python>>正文


Python uuslug.slugify函数代码示例

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


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

示例1: assert_list_case_plans

    def assert_list_case_plans(self, response, case):
        for case_plan_rel in TestCasePlan.objects.filter(case=case):
            plan = case_plan_rel.plan
            self.assertContains(
                response,
                '<a href="/plan/{0}/{1}">{0}</a>'.format(plan.pk, slugify(plan.name)),
                html=True)

            self.assertContains(
                response,
                '<a href="/plan/{}/{}">{}</a>'.format(plan.pk, slugify(plan.name), plan.name),
                html=True)
开发者ID:yangxiangfu,项目名称:Nitrate,代码行数:12,代码来源:tests.py

示例2: test_manager

    def test_manager(self):
        s = "This is a test ---"
        r = slugify(s)
        self.assertEquals(r, "this-is-a-test")

        s = 'C\'est déjà l\'été.'
        r = slugify(s)
        self.assertEquals(r, "cest-deja-lete")

        s = 'Nín hǎo. Wǒ shì zhōng guó rén'
        r = slugify(s)
        self.assertEquals(r, "nin-hao-wo-shi-zhong-guo-ren")

        s = '影師嗎'
        r = slugify(s)
        self.assertEquals(r, "ying-shi-ma")
开发者ID:jedie,项目名称:django-uuslug,代码行数:16,代码来源:test_uuslug.py

示例3: get_page_file_path

def get_page_file_path(obj, filename):
    if hasattr(obj, 'upload_dir'):
        extension = filename.split('.')[-1]
        filename = "%s.%s" % (slugify(obj.url), extension)
        return os.path.join(obj.upload_dir, filename)
    else:
        raise AttributeError("%s does not have 'upload_dir' attribute" % obj.__class__.__name__)
开发者ID:whitespy,项目名称:svs,代码行数:7,代码来源:views.py

示例4: form_valid

    def form_valid(self, form):
        u"""
        Sobrescreve o metodo form_valid para buscar
        o palestrante/user através do request
        """
        talk = form.save(commit=False)
        # seta o commit do formulario como false

        from uuslug import slugify
        # importa o slugfy

        talk.slug = slugify(talk.title)
        # adiciona no formulario talk
        # no atributo slug a chamada do metodo
        # slugify de acordo com o titulo
        # passado no formulario

        talk.speaker = SpeakerUser.objects.get(
            username=self.request.user.username
        )
        # associa o palestrante de acordo
        # com uma pesquisa feito no model SpeakerUser
        # filtrando pelo usuario logado

        talk.save()
        # salvar a o formulario

        super(TalkUpdateView, self).form_valid(form)
开发者ID:lucassimon,项目名称:pywatch.com.br,代码行数:28,代码来源:talk_views.py

示例5: slugify_raise_on_invalid

def slugify_raise_on_invalid(title, use_old_slugify=False):
    """
    use uuslug to generate a slug but if the title is incorrect (only special chars or slug is empty), an exception
    is raised.

    :param title: to be slugified title
    :type title: str
    :param use_old_slugify: use the function `slugify()` defined in zds.utils instead of the one in uuslug. Usefull \
    for retro-compatibility with the old article/tutorial module, SHOULD NOT be used for the new one !
    :type use_old_slugify: bool
    :raise InvalidSlugError: on incorrect slug
    :return: the slugified title
    :rtype: str
    """

    if not isinstance(title, str):
        raise InvalidSlugError('', source=title)
    if not use_old_slugify:
        slug = slugify(title)
    else:
        slug = old_slugify(title)

    if not check_slug(slug):
        raise InvalidSlugError(slug, source=title)

    return slug
开发者ID:josephcab,项目名称:zds-site,代码行数:26,代码来源:utils.py

示例6: get

def get(request, plan_id, slug=None, template_name='plan/get.html'):
    '''Display the plan details.'''
    SUB_MODULE_NAME = 'plans'

    try:
        tp = TestPlan.objects.select_related().get(plan_id=plan_id)
        tp.latest_text = tp.latest_text()
    except ObjectDoesNotExist:
        raise Http404

    # redirect if has a cheated slug
    if slug != slugify(tp.name):
        return HttpResponsePermanentRedirect(tp.get_absolute_url())

    # Initial the case counter
    confirm_status_name = 'CONFIRMED'
    tp.run_case = tp.case.filter(case_status__name=confirm_status_name)
    tp.review_case = tp.case.exclude(case_status__name=confirm_status_name)

    context_data = {
        'module': MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'test_plan': tp,
        'xml_form': ImportCasesViaXMLForm(initial={'a': 'import_cases'}),
    }
    return render_to_response(template_name, context_data,
                              context_instance=RequestContext(request))
开发者ID:yangxiangfu,项目名称:Nitrate,代码行数:27,代码来源:views.py

示例7: form_valid

    def form_valid(self, form):
        """
        Sobrescreve o metodo form_valid para salvar
        o slug field
        """
        event = form.save(commit=False)
        # seta o commit do formulario como false

        from uuslug import slugify
        # importa o slugfy

        event.slug = slugify(event.name)
        # adiciona no formulario talk
        # no atributo slug a chamada do metodo
        # slugify de acordo com o titulo
        # passado no formulario

        event.save()
        # salvar a o formulario

        super(EventCreateView, self).form_valid(form)
        # chama o metodo super

        # e retorna para a página de sucesso
        return HttpResponseRedirect(
            self.get_success_url()
        )
开发者ID:lucassimon,项目名称:pywatch.com.br,代码行数:27,代码来源:event_views.py

示例8: save

    def save(self, *args, **kwargs):
        """Override save method for custom functionality."""
        # Create unique slug
        if not self.pk:
            self.slug = slugify(self.name, instance=self)

        # Calculate planning pad url
        if not self.planning_pad_url:
            url = urljoin(settings.ETHERPAD_URL,
                          getattr(settings, 'ETHERPAD_PREFIX', '') + self.slug)
            self.planning_pad_url = url

        # Update action items
        if self.pk:
            current_event = Event.objects.get(id=self.pk)
            if current_event.owner != self.owner:
                model = ContentType.objects.get_for_model(self)
                action_items = ActionItem.objects.filter(content_type=model,
                                                         object_id=self.pk)
                action_items.update(user=self.owner)

        super(Event, self).save(*args, **kwargs)

        # Subscribe owner to event
        Attendance.objects.get_or_create(event=self, user=self.owner)
开发者ID:abshetewy,项目名称:remo,代码行数:25,代码来源:models.py

示例9: image_upload_to_featured

def image_upload_to_featured(instance, filename):
    title = instance.product.title
    if len(title) > 50:
        title = title[:50]
    slug = slugify(title)
    basename, file_extension = filename.split(".")
    new_filename = "%s-%s.%s" % (slug, instance.id, file_extension)
    return "products/%s/featured/%s" % (slug, new_filename)
开发者ID:koztay,项目名称:stb,代码行数:8,代码来源:models.py

示例10: save

    def save(self, **kwargs):
        if self.pk:
            self.modified_at = datetime.now()

        if not self.slug:
            self.slug = slugify(self.title, instance=self)

        super(Entry, self).save(**kwargs)
开发者ID:Alkemic,项目名称:webpage,代码行数:8,代码来源:models.py

示例11: save

 def save(self, *args, **kwargs):
     if self.pk is None:
         self.slug = slugify(self.title)
     try:
         super(ForumThread, self).save()
     except IntegrityError:
         self.slug += '-' + str(ForumThread.objects.filter(slug__startswith=self.slug).count())
         super(ForumThread, self).save()
开发者ID:ajoen,项目名称:django-arena,代码行数:8,代码来源:models.py

示例12: create_slug

def create_slug(sender, instance, raw, **kwargs):
    """Auto create unique slug and calculate planning_pad_url."""
    if not instance.slug:
        instance.slug = slugify(instance.name, instance=instance)

    if not instance.planning_pad_url:
        url = urljoin(settings.ETHERPAD_URL, getattr(settings, "ETHERPAD_PREFIX", "") + instance.slug)
        instance.planning_pad_url = url
开发者ID:serkanh,项目名称:remo,代码行数:8,代码来源:models.py

示例13: save

    def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(Theme,self).save(*args,**kwargs)

        if os.path.exists(self.extracted_path):
            shutil.rmtree(self.extracted_path)
        os.makedirs(self.extracted_path)
        z = ZipFile(self.zipfile.file,'r')
        z.extractall(self.extracted_path)
开发者ID:reshama,项目名称:editor,代码行数:9,代码来源:models.py

示例14: save

 def save(self, *args, **kwargs):
     self.slug = slugify(self.article_title)
     try:
         curr_article = Article.objects.get(id=self.id)
         if curr_article.article_image != self.article_image:
             curr_article.article_image.delete(save=False)
     except ObjectDoesNotExist:
         pass
     super().save(*args, **kwargs)
开发者ID:igrik6556,项目名称:igrik_blog,代码行数:9,代码来源:models.py

示例15: generate_unique_code

def generate_unique_code(title):
    project_code = slugify(title)
    if Project.objects.filter(code=project_code).exists():
        match = re.match(r'/.*-another-(\d+)$/g', title)
        if match:
            project_code = generate_unique_code(title + '-another-' + match[1])
        else:
            project_code = generate_unique_code(title + '-another-1')
    return project_code
开发者ID:vagoncheg,项目名称:panesh_com,代码行数:9,代码来源:views.py


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