本文整理汇总了Python中uuslug.slugify函数的典型用法代码示例。如果您正苦于以下问题:Python slugify函数的具体用法?Python slugify怎么用?Python slugify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slugify函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: save
def save(self, *args, **kwargs):
from DjangoBlog.blog_signals import article_save_signal
if not self.slug or self.slug == 'no-slug' or not self.id:
slug = self.title if 'title' in self.__dict__ else self.name
self.slug = slugify(slug)
super().save(*args, **kwargs)
# type = self.__class__.__name__
is_update_views = 'update_fields' in kwargs and len(kwargs['update_fields']) == 1 and kwargs['update_fields'][
0] == 'views'
article_save_signal.send(sender=self.__class__, is_update_views=is_update_views, id=self.id)
开发者ID:lutianba2014,项目名称:DjangoBlog,代码行数:10,代码来源:models.py
示例17: create_slug
def create_slug(instance, sender, new_slug=None):
print(instance)
slug = slugify(instance.title)
if new_slug is not None:
slug = new_slug
qs = sender.objects.filter(slug=slug)
exists = qs.exists()
if exists:
new_slug = "%s-%s" % (slug, qs.first().id)
return create_slug(instance, sender=sender, new_slug=new_slug)
return slug
开发者ID:koztay,项目名称:stb,代码行数:11,代码来源:signals.py
示例18: save
def save(self, *args, **kwargs):
"""
Customiza o metodo salvar da classe
para guardar o slug do palestrante
"""
from uuslug import uuslug as slugify
if not self.first_name:
self.first_name = 'speaker noname'
slug_str = "%s %s" % (self.first_name, self.last_name)
self.slug = slugify(slug_str, instance=self, start_no=1)
super(SpeakerUser, self).save(**kwargs)
开发者ID:lucassimon,项目名称:pywatch.com.br,代码行数:12,代码来源:models.py
示例19: save
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
pinyin = slugify(self.product_category.category, max_length=100)
code = ""
for word in pinyin.split('-'):
first_letter = word[0].upper()
code += first_letter
data_index = code + ''.join([choice('0123456789') for i in range(5)])
while not Product.objects.filter(product_index=data_index).count() == 0:
data_index = code + ''.join([choice('0123456789') for i in range(5)])
if not self.product_index:
self.product_index = data_index
super(Product, self).save(force_insert, force_update, using, update_fields)
开发者ID:jyst7275,项目名称:Suiyuan,代码行数:12,代码来源:model.py
示例20: save
def save(self, commit=True):
custom_part_type = super(NewCustomPartTypeForm, self).save(commit=False)
slug = slugify(custom_part_type.name)
custom_part_type.set_short_name(slug)
custom_part_type.author = self._user
if commit:
custom_part_type.save()
self.save_m2m()
return custom_part_type
开发者ID:numbas,项目名称:editor,代码行数:12,代码来源:forms.py
注:本文中的uuslug.slugify函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论