Personal tools
You are here: Home Products Plone Roadmap #73: Auto-generate short names from title
Document Actions

#73: Auto-generate short names from title

Contents
  1. Motivation
  2. Assumptions
  3. Proposal
  4. Implementation
  5. Deliverables
  6. Participants
by Alexander Limi last modified June 11, 2006 - 00:21
Id of an object should be auto-generated from the title upon first save; subsequent changes to title are not propaged to ID, to avoid link rot and confusion.
Proposed by
Alexander Limi
Seconded by
Alec Mitchell
Proposal type
User interface
Repository branch
uiteam-plip73-sanitize-short-names
State
completed

Motivation

The concept of short names is confusing to users, and the auto-generated IDs are incredibly ugly. In 90% of cases, we would want the short name to be the same as title, santised a little to work as a URL. In custom content types, it may be desirable to change this behaviour, but for the default document, image, etc. types, the title and id will tend to conincide.

Assumptions

For those wondering, there are two main reasons why we use hyphens instead of underscores as the default word separator:

  1. Underscores disappear when the URL is underlined (for example in a mail), and people reading the URL to someone on the phone (for instance) may believe they are spaces, not underscores.
  2. Many people don't know how to write the underscore - I've seen this myself, especially with elderly people who can't find the underscore on their keyboard. Remember, it's not part of standard typography in any way, it was pretty much unheard of before computers came along.

Additionally, Google doesn't treat underscores as word separators, which is another good reason to use the hyphen.

Proposal

There is already a script sanitizeForURL in the CMF1.5 integration branch for 2.1. This can take a title and convert it to a sensible URL. This should be called to generate and set an id when the object is first validated and saved. However, subsequent changes should not do this, to avoid link rot.

Thus, we first need to re-enable an AT feature which was implemented poorly before and disabled - the creation flag. This flag is set as the object is created, and unset after the product has been sucessfully validated and instantiated from the factory (if applicable). This will be done in ATContentTypes for now, with a view of backporting it to AT 1.4.

With this in place, ATContentTypes can check if a type is being created, and if so, change the id to the value returned by sanitizeForURL. See the Implementation section for details.

Also: There must be a way of turning this behaviour off - not all custom types will want this.

Implementation

There are three implementation options:

  • Alec has an example which overrides processForm() and does the rename there, after calling self._processForm(). He claims there are no errors. This may be the way to go, but requires some more investigation. (this is the preferred solution at the moment)
  • To allow overriding this behavior, the method will check that the current id (after any setId calls done during edition) is auto-generated using plone_scripts/isIDSutoGenerated, and will only set id if it determines that the current id hasn't been set to a sensible value in an earlier stage of edition.
  • Need to change the widget to look at site_properties for a global policy, not on user prefs, whether or not to display it. (Limi says it's OK if we break compatability on this issue).

Deliverables

  • Replace all use of visible_ids property of members and portal_memberdata with visible_ids in site_properties.
  • Add a migration to CMFPlone which installs the new sitewide visible_ids property in site_properties, disabled by default.
  • Add a unit test for the CMFPlone migration.
  • Make all ATCT use a custom IdWidget which no longer references the member based visible_ids (makes ATCT 1.0 dependent on plone 2.1). This should be moved into AT in the default IdWidget for 1.4.
  • Add flag in ATCT to indicate that an archetype is newly created (when created TTW) during initializeArchetype(), remove this flag during processForm(). Should be moved into AT for 1.4.
  • Rename object after edit in processForm() if the object is flagged as new, and if the id is autogenerated (determined using plone_scripts/isIDAutoGenerated).
  • Unit test to ensure creation flag is set on TTW type creation and not set otherwise.
  • Functional test to ensure that the object is renamed. This test is disabled because it currently fails inexplicably (the FormController probably needs some massaging in the functional test).

Participants

Tiran (Christian Heimes)
AlecM (Alec Mitchell)
Optilude (Martin Aspeli)


For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by