def slugify_field(self, field_name): pretranslate = load_slug_rule(self.language) slugify_url = Slugify(pretranslate=pretranslate) slugify_url.to_lower = True slugify_url.stop_words = () slugify_url.max_length = 1000 return slugify_url(self.field_dict[field_name], max_length=1000)
def test_to_lower_arg(self): slugify = Slugify() slugify.to_lower = True self.assertEqual(slugify('Test TO lower'), 'test-to-lower') self.assertEqual(slugify('Test TO lower', to_lower=False), 'Test-TO-lower')
def slugify_name(name): """Get a slugifier used to ensure asset names are safe""" # Create the slugifier slugifier = Slugify() # Configure the slugifier slugifier.to_lower = True slugifier.safe_chars = '-/' slugifier.max_length = 200 # Names cannot start or end with forward slashes '/' return slugifier(name).strip('/')
def slugify(self): if (self.field_dict["product_name"] is not None and self.field_dict["brand"] is not None and self.field_dict["fingerprint"] is not None): key_word_list = self.keyword_list_lookup() pretranslate = load_slug_rule(self.language) slugify_url = Slugify(pretranslate=pretranslate) slugify_url.to_lower = True slugify_url.stop_words = () slugify_url.max_length = 1000 first_bit = slugify_url( "-".join(key_word for key_word in key_word_list if key_word).lower(), max_length=1000, ) if len(first_bit) == 0: return "" friendly_id = "-".join([first_bit, self.field_dict["fingerprint"]]) return friendly_id
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations from slugify import Slugify my_slugify = Slugify() my_slugify.separator = '-' my_slugify.pretranslate = {'&': 'and'} my_slugify.to_lower = True my_slugify.max_length = None my_slugify.capitalize = False my_slugify.safe_chars = '' def add_slug(CategoryModel, category_name, category_group, category_code, category_description): category = CategoryModel.objects.get(code=category_code) category.slug = my_slugify(category_name) category.save() def create_category_slugs(apps, schema_editor): CategoryModel = apps.get_model("core", "ChCategory") print("CategoryModel: ", CategoryModel) # Art & cultural events // Arte y eventos culturales add_slug(CategoryModel, 'Art & Cultural events', 'Art & Cultural events', '01.01', 'Dummy description') # Books & Comics // Libros y cómics
def getUsername(self): email_slug = Slugify() email_slug.to_lower = True email_slug.pretranslate = {"ə": "e"} return f"{email_slug(self.getFullName(),to_lower = True,separator = '.')}.{self.user[3].lower()}{self.suffix}"
from django.db import models from slugify import Slugify slugify_text = Slugify() slugify_text.to_lower = True slugify_text.stop_words = ('a', 'an', 'the') slugify_text.max_length = 200 def get_image_url(instance, filename): return f'blogs/{instance.slug}/{filename}' class Blog(models.Model): title = models.CharField(max_length=200) slug = models.CharField(max_length=230) date_created = models.DateField() title_image = models.ImageField(upload_to=get_image_url) def save(self, *args, **kwargs): if not self.id: self.slug = slugify_text(self.title) super(Blog, self).save(*args, **kwargs) def __str__(self): return self.title
def slugify_string(str): my_slugify = Slugify() my_slugify.to_lower = True return my_slugify(str)
def slugify_string(str): my_slugify = Slugify() my_slugify.pretranslate = {'AT&T': 'att'} my_slugify.to_lower = True return my_slugify(str)