#8040 closed (fixed)
SlugField format not enforced
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Keywords: | aug22sprint | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
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 (2)
Change History (11)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Possibly related to model level validation propagation (a spoonful of sugar with that?)
comment:3 by , 17 years ago
| milestone: | → 1.0 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
by , 17 years ago
| Attachment: | 8040-slug-validation.diff added |
|---|
comment:4 by , 17 years ago
| Has patch: | set |
|---|
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.
by , 17 years ago
| Attachment: | 8040.patch added |
|---|
updated patch (minor position change in fields/init.py)
comment:5 by , 17 years ago
| Keywords: | aug22sprint added |
|---|
test properly fails before applying fix, passes after, validation then works correctly after patch is applied - looks good to me :)
comment:6 by , 17 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:7 by , 17 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:8 by , 17 years ago
(In [8616]) Removed oldforms, validators, and related code:
- Removed
Manipulator,AutomaticManipulator, and related classes. - Removed oldforms specific bits from model fields:
- Removed
validator_listandcorearguments from constructors. - Removed the methods:
get_manipulator_field_namesget_manipulator_field_objsget_manipulator_fieldsget_manipulator_new_dataprepare_field_objs_and_paramsget_follow
- Renamed
flatten_datamethod tovalue_to_stringfor better alignment with its use by the serialization framework, which was the only remaining code usingflatten_data.
- Removed
- Removed oldforms methods from
django.db.models.Optionsclass:get_followed_related_objects,get_data_holders,get_follow, andhas_field_type. - Removed oldforms-admin specific options from
django.db.models.fields.relatedclasses:num_in_admin,min_num_in_admin,max_num_in_admin,num_extra_on_change, andedit_inline. - Serialization framework
Serializer.get_string_valuenow calls the model fields' renamedvalue_to_stringmethods.- Removed a special-casing of
models.DateTimeFieldincore.serializers.base.Serializer.get_string_valuethat's handled bydjango.db.models.fields.DateTimeField.value_to_string.
- Removed
django.core.validators:- Moved
ValidationErrorexception todjango.core.exceptions. - For the couple places that were using validators, brought over the necessary code to maintain the same functionality.
- Moved
- 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).
Should read:
...(ie. no validation occurs)
;)