Permalink
Browse files

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).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8616 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent a157576 commit c2ba59fc1da5287d6286e2c2aca4083d5bafe056 @gdub gdub committed Aug 27, 2008
Showing with 158 additions and 3,468 deletions.
  1. +3 −3 django/contrib/admin/util.py
  2. +14 −5 django/contrib/auth/management/commands/createsuperuser.py
  3. +0 −1 django/contrib/auth/models.py
  4. +0 −3 django/contrib/comments/forms.py
  5. +1 −1 django/contrib/comments/models.py
  6. +5 −16 django/contrib/contenttypes/generic.py
  7. +0 −1 django/contrib/flatpages/models.py
  8. +0 −1 django/contrib/localflavor/jp/forms.py
  9. +3 −0 django/core/exceptions.py
  10. +1 −6 django/core/serializers/base.py
  11. +0 −598 django/core/validators.py
  12. +1 −2 django/db/models/__init__.py
  13. +2 −6 django/db/models/base.py
  14. +63 −250 django/db/models/fields/__init__.py
  15. +4 −50 django/db/models/fields/files.py
  16. +26 −72 django/db/models/fields/related.py
  17. +0 −333 django/db/models/manipulators.py
  18. +0 −47 django/db/models/options.py
  19. +1 −97 django/db/models/related.py
  20. +12 −1 django/forms/fields.py
  21. +0 −1,056 django/oldforms/__init__.py
  22. +11 −26 docs/howto/custom-model-fields.txt
  23. +2 −2 docs/intro/whatsnext.txt
  24. +0 −692 docs/obsolete/forms.txt
  25. +0 −48 docs/obsolete/newforms-migration.txt
  26. +0 −5 docs/ref/forms/fields.txt
  27. +1 −28 docs/ref/models/fields.txt
  28. +1 −2 docs/topics/forms/modelforms.txt
  29. +1 −2 docs/topics/testing.txt
  30. +0 −3 tests/modeltests/field_subclassing/models.py
  31. +4 −4 tests/modeltests/invalid_models/models.py
  32. 0 tests/modeltests/manipulators/__init__.py
  33. +0 −105 tests/modeltests/manipulators/models.py
  34. +1 −1 tests/modeltests/mutually_referential/models.py
  35. +1 −1 tests/regressiontests/model_fields/tests.py
@@ -85,7 +85,7 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
perms_needed.add(related.opts.verbose_name)
# We don't care about populating deleted_objects now.
continue
- if related.field.rel.edit_inline or not has_admin:
+ if not has_admin:
# Don't display link to edit, because it either has no
# admin or is edited inline.
nh(deleted_objects, current_depth, [u'%s: %s' % (force_unicode(capfirst(related.opts.verbose_name)), sub_obj), []])
@@ -101,7 +101,7 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
has_related_objs = False
for sub_obj in getattr(obj, rel_opts_name).all():
has_related_objs = True
- if related.field.rel.edit_inline or not has_admin:
+ if not has_admin:
# Don't display link to edit, because it either has no
# admin or is edited inline.
nh(deleted_objects, current_depth, [u'%s: %s' % (force_unicode(capfirst(related.opts.verbose_name)), sub_obj), []])
@@ -132,7 +132,7 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
if has_related_objs:
for sub_obj in rel_objs.all():
- if related.field.rel.edit_inline or not has_admin:
+ if not has_admin:
# Don't display link to edit, because it either has no
# admin or is edited inline.
nh(deleted_objects, current_depth, [_('One or more %(fieldname)s in %(name)s: %(obj)s') % \
@@ -8,10 +8,19 @@
import sys
from optparse import make_option
from django.contrib.auth.models import User
-from django.core import validators
+from django.core import exceptions
from django.core.management.base import BaseCommand, CommandError
+from django.utils.translation import ugettext as _
RE_VALID_USERNAME = re.compile('\w+$')
+EMAIL_RE = re.compile(
+ r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
+ r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"' # quoted-string
+ r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain
+
+def is_valid_email(value):
+ if not EMAIL_RE.search(value):
+ raise exceptions.ValidationError(_('Enter a valid e-mail address.'))
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
@@ -39,8 +48,8 @@ def handle(self, *args, **options):
if not RE_VALID_USERNAME.match(username):
raise CommandError("Invalid username. Use only letters, digits, and underscores")
try:
- validators.isValidEmail(email, None)
- except validators.ValidationError:
+ is_valid_email(email)
+ except exceptions.ValidationError:
raise CommandError("Invalid email address.")
password = ''
@@ -94,8 +103,8 @@ def handle(self, *args, **options):
if not email:
email = raw_input('E-mail address: ')
try:
- validators.isValidEmail(email, None)
- except validators.ValidationError:
+ is_valid_email(email)
+ except exceptions.ValidationError:
sys.stderr.write("Error: That e-mail address is invalid.\n")
email = None
else:
@@ -1,5 +1,4 @@
from django.contrib import auth
-from django.core import validators
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models.manager import EmptyManager
@@ -117,9 +117,6 @@ def clean_comment(self):
"""
comment = self.cleaned_data["comment"]
if settings.COMMENTS_ALLOW_PROFANITIES == False:
- # Logic adapted from django.core.validators; it's not clear if they
- # should be used in newforms or will be deprecated along with the
- # rest of oldforms
bad_words = [w for w in settings.PROFANITIES_LIST if w in comment.lower()]
if bad_words:
plural = len(bad_words) > 1
@@ -5,7 +5,7 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.db import models
-from django.core import urlresolvers, validators
+from django.core import urlresolvers
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
@@ -2,18 +2,16 @@
Classes allowing "generic" relations through ContentType and object-id fields.
"""
-from django import oldforms
from django.core.exceptions import ObjectDoesNotExist
from django.db import connection
from django.db.models import signals
from django.db import models
from django.db.models.fields.related import RelatedField, Field, ManyToManyRel
from django.db.models.loading import get_model
-from django.utils.functional import curry
-
from django.forms import ModelForm
from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance
from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets
+from django.utils.encoding import smart_unicode
class GenericForeignKey(object):
"""
@@ -120,19 +118,12 @@ def __init__(self, to, **kwargs):
kwargs['serialize'] = False
Field.__init__(self, **kwargs)
- def get_manipulator_field_objs(self):
- choices = self.get_choices_default()
- return [curry(oldforms.SelectMultipleField, size=min(max(len(choices), 5), 15), choices=choices)]
-
def get_choices_default(self):
return Field.get_choices(self, include_blank=False)
- def flatten_data(self, follow, obj = None):
- new_data = {}
- if obj:
- instance_ids = [instance._get_pk_val() for instance in getattr(obj, self.name).all()]
- new_data[self.name] = instance_ids
- return new_data
+ def value_to_string(self, obj):
+ qs = getattr(obj, self.name).all()
+ return smart_unicode([instance._get_pk_val() for instance in qs])
def m2m_db_table(self):
return self.rel.to._meta.db_table
@@ -290,7 +281,6 @@ def __init__(self, to, related_name=None, limit_choices_to=None, symmetrical=Tru
self.to = to
self.related_name = related_name
self.limit_choices_to = limit_choices_to or {}
- self.edit_inline = False
self.symmetrical = symmetrical
self.multiple = True
@@ -300,7 +290,7 @@ class BaseGenericInlineFormSet(BaseModelFormSet):
"""
ct_field_name = "content_type"
ct_fk_field_name = "object_id"
-
+
def __init__(self, data=None, files=None, instance=None, save_as_new=None):
opts = self.model._meta
self.instance = instance
@@ -395,4 +385,3 @@ class GenericStackedInline(GenericInlineModelAdmin):
class GenericTabularInline(GenericInlineModelAdmin):
template = 'admin/edit_inline/tabular.html'
-
@@ -1,4 +1,3 @@
-from django.core import validators
from django.db import models
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
@@ -2,7 +2,6 @@
JP-specific Form helpers
"""
-from django.core import validators
from django.forms import ValidationError
from django.utils.translation import ugettext_lazy as _
from django.forms.fields import RegexField, Select
@@ -32,3 +32,6 @@ class FieldError(Exception):
"""Some kind of problem with a model field."""
pass
+class ValidationError(Exception):
+ """An error while validating data."""
+ pass
@@ -57,12 +57,7 @@ def get_string_value(self, obj, field):
"""
Convert a field's value to a string.
"""
- if isinstance(field, models.DateTimeField):
- d = datetime_safe.new_datetime(getattr(obj, field.name))
- value = d.strftime("%Y-%m-%d %H:%M:%S")
- else:
- value = field.flatten_data(follow=None, obj=obj).get(field.name, "")
- return smart_unicode(value)
+ return smart_unicode(field.value_to_string(obj))
def start_serialization(self):
"""
Oops, something went wrong.

0 comments on commit c2ba59f

Please sign in to comment.