Code

Opened 9 years ago

Closed 8 years ago

Last modified 7 years ago

#317 closed defect (fixed)

[Patch] slugify delimits words by hyphens, but its validator doesn't like them

Reported by: hugo <gb@…> Owned by: jacob
Component: Generic views Version: 0.95
Severity: normal Keywords: slugs slug slugify validation
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

. words separated by underscores ("_") or hyphens ("-") in URLs. Google will treat "keyword-phrase" as "keyword phrase" and "keyword_phrase" as "keywordphrase. - google handles _ and - differently, where the - form usually is what the user needs. So the slugify code should just handle multi-word sentences by delimiting the slugified words by hyphens.

Attachments (1)

slug.patch (2.5 KB) - added by sune.kirkeby@… 9 years ago.
Patch to change URLify.js, and add a separate validator for slugs.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 9 years ago by Manuzhai

I agree, and I have talked about this with jacobkm before. I also have patches, but they're kinda trivial. Just remember that you need to change both the validator and the prepopulating javascript.

Changed 9 years ago by sune.kirkeby@…

Patch to change URLify.js, and add a separate validator for slugs.

comment:2 Changed 9 years ago by sune.kirkeby@…

  • Summary changed from slugify should delimit words by hyphens to [patch] slugify should delimit words by hyphens

Just added a patch which updates the prepopulating javascript to replace spaces with dashes, and add a separate validator (isSlug) for slugs, which accepts dashes in slugs.
Please, could this (or something like it) get committed? As the OP said, dashes and underscores are different in URLs, so they should both be allowed in slugs.

comment:3 Changed 9 years ago by garthk

  • Keywords slugs slug slugify validation added
  • Summary changed from [patch] slugify should delimit words by hyphens to slugify delimits words by hyphens, but its validator doesn't like them

I'm seeing dashes in my SlugFields after using django.core.defaultfilters.slugify in my _pre_save, but when I try to edit one of the postings afterward in the administration interface I get validation errors.

comment:4 Changed 9 years ago by Manuzhai

  • Summary changed from slugify delimits words by hyphens, but its validator doesn't like them to [Patch] slugify delimits words by hyphens, but its validator doesn't like them

Hmm, isn't the regex just wrong?

Also, adding [Patch] to summary to gain inclusion in {12}.

comment:5 Changed 9 years ago by sune.kirkeby@…

Hmm, isn't the regex just wrong?

Which regex? I am running the patch I attached, and it works for me.

comment:6 Changed 9 years ago by jacob

  • milestone set to Version 1.0
  • Owner changed from adrian to jacob
  • Status changed from new to assigned

comment:7 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [968]) Fixed #317 -- SlugField now accepts hyphens. Thanks, Sune

comment:8 Changed 8 years ago by hugo

  • Resolution fixed deleted
  • Status changed from closed to reopened

urlify still delimits words by _ instead of -. I think we definitely should switch to delimiting by hyphens, as that's much more google friendly than underscores.

comment:9 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

This was fixed in [1017].

comment:10 Changed 7 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

comment:11 in reply to: ↑ description Changed 7 years ago by anonymous

  • Component changed from Admin interface to Generic views
  • Has patch set
  • Triage Stage changed from Unreviewed to Accepted
  • Version set to 0.95

Replying to hugo <gb@bofh.ms>:

. words separated by underscores ("_") or hyphens ("-") in URLs. Google will treat "keyword-phrase" as "keyword phrase" and "keyword_phrase" as "keywordphrase. - google handles _ and - differently, where the - form usually is what the user needs. So the slugify code should just handle multi-word sentences by delimiting the slugified words by hyphens.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.