Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#34567 closed New feature (duplicate)

slugify template filter with allow_unicode

Reported by: benjaoming Owned by: Arthur Moreira
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Currently, the slugify template filter in defaultfilters doesn't handle the allow_unicode from django.utils.text.slugify. This should be trivial to add and be beneficial for languages that won't have characters normally converted to ASCII.

Could this be implemented as an argument for the default template filter? Or a separate default template filter?

Which version would be preferred?

{{ value|slugify:allow_unicode=True }}

or

{{ value|slugify_unicode }}

?

Change History (4)

comment:1 by Arthur Moreira, 19 months ago

Owner: changed from nobody to Arthur Moreira
Status: newassigned
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

Reproduced.

>>> from django.utils.text import slugify
>>> slugify("你好 ni hao") 
'ni-hao'
>>> slugify("你好 ni hao", allow_unicode=True)
'你好-ni-hao'

but given following context

{"my_text": "你好 ni hao"}

in the template

<p>{{ my_text | slugify }}</p>

it produces

ni-hao 

i agree that a way to allow unicode from the template filter should exist

Version 0, edited 19 months ago by Arthur Moreira (next)

comment:2 by Mariusz Felisiak, 19 months ago

Component: UncategorizedTemplate system
Resolution: duplicate
Status: assignedclosed
Triage Stage: AcceptedUnreviewed

Duplicate of #8391. Also, the current thread is to keep Django a core framework, not providing every utility which might be useful. You can write that filter in your own library. You can start a discussion about #8391 on DevelopersMailingList if you don't agree.

comment:3 by benjaoming, 19 months ago

Duplicate of #8391.

Thanks Mariusz, I did look at that issue, and I should have noted it in the description - but I think #8391 is from before django.utils.text.slugify existed and provided allow_unicode. The previous issue was mostly about the complex area of mapping one character to another - allow_unicode=True doesn't want to map anything AFAIK.

Also, the current thread is to keep Django a core framework, not providing every utility which might be useful.

That's fair. The functionality is already implemented in django.utils.text - so this is only a proposal to expose the keyword allow_unicode. But yeah, exposing it will of course lead to more usage.

I was particularly intrigued by the fact that I had introduced bugs in my codebase because I used |slugify without considering its affect on translated versions.

You can start a discussion about #8391 on DevelopersMailingList if you don't agree.

That's a nice page <3 I have been "WONTFIX'ed" :) I don't feel like having a discussion on this topic. I tried to write a topic for the forum, but it became disproportionate -- adding the keyword to the template filter is both very easy to implement in Django defaultfilters, it's also very easy to port my own boilerplate around between projects. If it cannot be a quick yes/no, then I think leaving it aside is better.

in reply to:  3 comment:4 by Mariusz Felisiak, 19 months ago

Replying to benjaoming:

That's a nice page <3 I have been "WONTFIX'ed" :) I don't feel like having a discussion on this topic. I tried to write a topic for the forum, but it became disproportionate -- adding the keyword to the template filter is both very easy to implement in Django defaultfilters, it's also very easy to port my own boilerplate around between projects. If it cannot be a quick yes/no, then I think leaving it aside is better.

Not you, it's been "wontfixed" 9 years ago ;) I'm just trying to keep a discussion in a single place 🧹. TBH, I'm fine with exposing allow_unicode in the slugify template filter but we should do this by reopening #8391. You can start a short thread on the Django Forum or the mailing list, a few "+1" should be enough to reopen.

Note: See TracTickets for help on using tickets.
Back to Top