Django

Code

Ticket #8040 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

SlugField format not enforced

Reported by: Daniel Pope <dan@mauveinternet.co.uk> Assigned to: nobody
Milestone: 1.0 Component: Forms
Version: SVN Keywords: aug22sprint
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

models.SlugField is documented as "a short label for something, containing only letters, numbers, underscores or hyphens."

However, with forms.ModelForm and newforms-admin, this formatting is not enforced. The ModelForms documentation instead states that models.SlugField is represented by a forms.CharField (ie. validation occurs).

models.SlugField.formfield() should return a forms.RegexField suitable for validating the field as a slug (and the ModelForms documentation should reflect this).

Attachments

8040-slug-validation.diff (2.3 kB) - added by Daniel Pope <dan@mauveinternet.co.uk> on 08/13/08 16:33:44.
8040.patch (2.3 kB) - added by cgrady on 08/22/08 19:28:20.
updated patch (minor position change in fields/init.py)

Change History

07/30/08 08:37:55 changed by Daniel Pope <dan@mauveinternet.co.uk>

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Should read:

...(ie. no validation occurs)

;)

08/01/08 01:58:31 changed by Jökull Sólberg Auðunsson <jokullsolberg@gmail.com>

Possibly related to model level validation propagation (a spoonful of sugar with that?)

#6845

08/12/08 11:01:06 changed by jacob

  • stage changed from Unreviewed to Accepted.
  • milestone set to 1.0.

08/13/08 16:33:44 changed by Daniel Pope <dan@mauveinternet.co.uk>

  • attachment 8040-slug-validation.diff added.

08/13/08 16:41:24 changed by Daniel Pope <dan@mauveinternet.co.uk>

  • has_patch set to 1.

I implemented that validation using a RegexField?, but all the other models fields that need syntax validation define their own forms.Field subclass. I was reluctant to go ahead and add that at this point.

08/22/08 19:28:20 changed by cgrady

  • attachment 8040.patch added.

updated patch (minor position change in fields/init.py)

08/22/08 19:28:59 changed by cgrady

  • keywords set to aug22sprint.

test properly fails before applying fix, passes after, validation then works correctly after patch is applied - looks good to me :)

08/22/08 19:46:06 changed by brosner

  • stage changed from Accepted to Ready for checkin.

08/22/08 23:59:26 changed by brosner

  • status changed from new to closed.
  • resolution set to fixed.

(In [8477]) Fixed #8040 -- SlugField? now returns a proper formfield to deal with validation. Thanks Daniel Pope for the ticket and patch.

08/27/08 02:19:45 changed by gwilson

(In [8616]) Removed oldforms, validators, and related code:

  • Removed Manipulator, AutomaticManipulator, and related classes.
  • Removed oldforms specific bits from model fields:
    • Removed validator_list and core arguments from constructors.
    • Removed the methods:
      • get_manipulator_field_names
      • get_manipulator_field_objs
      • get_manipulator_fields
      • get_manipulator_new_data
      • prepare_field_objs_and_params
      • get_follow
    • Renamed flatten_data method to value_to_string for better alignment with its use by the serialization framework, which was the only remaining code using flatten_data.
  • Removed oldforms methods from django.db.models.Options class: get_followed_related_objects, get_data_holders, get_follow, and has_field_type.
  • Removed oldforms-admin specific options from django.db.models.fields.related classes: num_in_admin, min_num_in_admin, max_num_in_admin, num_extra_on_change, and edit_inline.
  • Serialization framework
    • Serializer.get_string_value now calls the model fields' renamed value_to_string methods.
    • Removed a special-casing of models.DateTimeField in core.serializers.base.Serializer.get_string_value that's handled by django.db.models.fields.DateTimeField.value_to_string.
  • Removed django.core.validators:
    • Moved ValidationError exception to django.core.exceptions.
    • For the couple places that were using validators, brought over the necessary code to maintain the same functionality.
  • Introduced a SlugField? form field for validation and to compliment the SlugField? model field (refs #8040).
  • Removed an oldforms-style model creation hack (refs #2160).

Add/Change #8040 (SlugField format not enforced)




Change Properties
Action