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


Python defaultfilters.slugify方法代码示例

本文整理汇总了Python中django.template.defaultfilters.slugify方法的典型用法代码示例。如果您正苦于以下问题:Python defaultfilters.slugify方法的具体用法?Python defaultfilters.slugify怎么用?Python defaultfilters.slugify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.defaultfilters的用法示例。


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

示例1: model_from_slug

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def model_from_slug(product_line, model=None):
    """
    Returns product description for model slug or models dict for
    the specified product line
    """
    if not cache.get("slugmap"):
        slugmap = {}  # Map model slug to corresponding product description
        product_lines = gsxws.products.models()

        for k, v in product_lines.items():
            d = {}
            for p in v['models']:
                slug = slugify(p)
                d[slug] = p

            slugmap[k] = d

        cache.set("slugmap", slugmap)

    models = cache.get("slugmap").get(product_line)

    if model is not None:
        return models.get(model)

    return models 
开发者ID:fpsw,项目名称:Servo,代码行数:27,代码来源:device.py

示例2: save

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def save(self, *args, **kwargs):
        """
        - Make unique slug if it is not given.
        """
        if not self.slug:
            slug = slugify(unidecode(self.title))
            duplications = Contention.objects.filter(slug=slug)
            if duplications.exists():
                self.slug = "%s-%s" % (slug, uuid4().hex)
            else:
                self.slug = slug

        if not kwargs.pop('skip_date_update', False):
            self.date_modification = datetime.now()

        return super(Contention, self).save(*args, **kwargs) 
开发者ID:arguman,项目名称:arguman.org,代码行数:18,代码来源:models.py

示例3: form_valid

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def form_valid(self, form):
        topic = self.get_object()
        old_tags = [tag.title for tag in topic.tags.all()]
        topic = form.save()
        tags_text = form.cleaned_data['tags']
        if tags_text:
            new_tags = tags_text.split(',')
            remove_tags = set(new_tags) - set(old_tags)
            for tag in new_tags:
                tag_slug = slugify(tag)
                if not Tags.objects.filter(slug=tag_slug).exists():
                    tag = Tags.objects.create(slug=tag_slug, title=tag)
                    topic.tags.add(tag)
                else:
                    tag = Tags.objects.filter(slug=tag_slug).first()
                    if tag.title in remove_tags:
                        topic.remove(tag)
                    else:
                        topic.tags.add(tag)
        topic.save()
        return JsonResponse({"error": False, "success_url": reverse('django_simple_forum:signup')}) 
开发者ID:MicroPyramid,项目名称:django-simple-forum,代码行数:23,代码来源:views.py

示例4: save

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def save(self, commit=True):
        instance = super(CategoryForm, self).save(commit=False)
        instance.created_by = self.user
        instance.title = self.cleaned_data['title']
        if str(self.cleaned_data['is_votable']) == 'True':
            instance.is_votable = True
        else:
            instance.is_votable = False
        if str(self.cleaned_data['is_active']) == 'True':
            instance.is_active = True
        else:
            instance.is_active = False
        if not self.instance.id:
            instance.slug = slugify(self.cleaned_data['title'])

        if commit:
            instance.save()
        return instance 
开发者ID:MicroPyramid,项目名称:django-simple-forum,代码行数:20,代码来源:forms.py

示例5: environment

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def environment(**options: Any) -> Environment:
    env = Environment(**options)
    env.globals.update({
        'default_page_params': {
            'debug_mode': False,
            'webpack_public_path': staticfiles_storage.url(
                settings.WEBPACK_LOADER['DEFAULT']['BUNDLE_DIR_NAME'],
            ),
        },
        'static': staticfiles_storage.url,
        'url': reverse,
        'render_markdown_path': render_markdown_path,
    })

    env.install_gettext_translations(translation, True)

    env.filters['slugify'] = slugify
    env.filters['pluralize'] = pluralize
    env.filters['display_list'] = display_list
    env.filters['device_action'] = device_action
    env.filters['timesince'] = timesince

    return env 
开发者ID:zulip,项目名称:zulip,代码行数:25,代码来源:__init__.py

示例6: update_or_create_built_form_examples

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def update_or_create_built_form_examples(self, array_of_examples):

        built_form_key = self.key

        self.examples.clear()

        for object in array_of_examples:

            name = object["study_area_name"]
            name_slug = slugify(name).replace('-','_')
            study_area_aerial_map_view = object["study_area_aerial_map_view"]
            study_area_street_view = object["study_area_street_view"]
            example = BuiltFormExample.objects.update_or_create(
                key="%s_%s" % (built_form_key, name_slug),
                defaults=dict(
                    url_aerial = study_area_aerial_map_view,
                    url_street = study_area_street_view,
                    name=name
                ))[0]
            self.examples.add(example) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:22,代码来源:built_form.py

示例7: make_manifest_slug

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def make_manifest_slug(self, uuid, label, item_type, project_uuid):
        """
        gets the most recently updated Subject date
        """
        label = label.replace('_', ' ')
        raw_slug = slugify(unidecode(label[:55]))
        act_proj_short_id = self.get_project_index(project_uuid)
        if(raw_slug == '-' or len(raw_slug) < 1):
            raw_slug = 'x'  # slugs are not a dash or are empty
        if(act_proj_short_id is not False):
            raw_slug = str(act_proj_short_id) + '-' + raw_slug
        if(raw_slug[-1:] == '-'):
            raw_slug = raw_slug + 'x'  # slugs don't end with dashes
        raw_slug = re.sub(r'([-]){2,}', r'-', raw_slug)  # slugs can't have more than 1 dash characters
        slug = self.raw_to_final_slug(uuid, raw_slug)  # function for making sure unique slugs
        return slug 
开发者ID:ekansa,项目名称:open-context-py,代码行数:18,代码来源:models.py

示例8: save

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(unidecode(self.title))
        super(Group, self).save(*args, **kwargs) 
开发者ID:slyapustin,项目名称:django-classified,代码行数:6,代码来源:models.py

示例9: save

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(CustomerGroup, self).save() 
开发者ID:fpsw,项目名称:Servo,代码行数:5,代码来源:customer.py

示例10: save

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def save(self, *args, **kwargs):
        self.slug = slugify(self.tag)
        super(TaggedItem, self).save(*args, **kwargs) 
开发者ID:fpsw,项目名称:Servo,代码行数:5,代码来源:common.py

示例11: handle

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def handle(self, *args, **options):
        for i in Product.objects.filter(code__contains=' '):
            i.code = slugify(i.code)
            i.save()

        for i in ServiceOrderItem.objects.filter(code__contains=' '):
            i.code = slugify(i.code)
            i.save() 
开发者ID:fpsw,项目名称:Servo,代码行数:10,代码来源:fixproducts.py

示例12: handle

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def handle(self, *args, **options):
        logging.info("Cleaning up duplicate tags")
        for d in TaggedItem.objects.filter(slug=None):
            d.slug = slugify(d.description)
            d.save() 
开发者ID:fpsw,项目名称:Servo,代码行数:7,代码来源:cleandups.py

示例13: save

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.name)
        return super(Category, self).save(*args, **kwargs) 
开发者ID:APSL,项目名称:puput,代码行数:6,代码来源:models.py

示例14: on_pre_save

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def on_pre_save(sender, instance, *args, **kwargs):
    if not instance.slug:
        instance.slug = slugify(instance.label)
    else:
        instance.slug = slugify(instance.slug) 
开发者ID:javrasya,项目名称:django-river,代码行数:7,代码来源:state.py

示例15: new_nonstudent

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import slugify [as 别名]
def new_nonstudent(request, course_slug):
    course = get_object_or_404(CourseOffering, slug=course_slug)
    group_choices = [('', '\u2014')] + [(g.id, g.name) for g in DisciplineGroup.objects.filter(offering=course)]
    
    if request.method == 'POST':
        form = DisciplineInstrNonStudentCaseForm(data=request.POST)
        form.fields['group'].choices = group_choices
        if form.is_valid():
            instructor = Person.objects.get(userid=request.user.username)
            case = form.save(commit=False)
            case.owner = instructor
            case.offering = course
            case.slug = defaultfilters.slugify(case.first_name + " " + case.last_name)
            case.save()
            form.save_m2m()
            #LOG EVENT#
            l = LogEntry(userid=request.user.username,
                  description=("created a non-student discipline case for %s in %s") % (case.student.name(), course),
                  related_object=case)
            l.save()
            return HttpResponseRedirect(reverse('offering:discipline:show', kwargs={'course_slug': course_slug, 'case_slug': case.slug}))

    else:
        form = DisciplineInstrNonStudentCaseForm()
    
    form.fields['group'].choices = group_choices
    context = {'course': course, 'form': form}
    return render(request, "discipline/new_nonstudent.html", context) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:30,代码来源:views.py


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