本文整理汇总了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)
示例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")
示例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__)
示例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)
示例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
示例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))
示例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()
)
示例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)
示例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)
示例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)
示例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()
示例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
示例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)
示例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)
示例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