Skip to content

Commit

Permalink
Removed oldforms, validators, and related code:
Browse files Browse the repository at this point in the history
 * 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
gdub committed Aug 27, 2008
1 parent a157576 commit c2ba59f
Show file tree
Hide file tree
Showing 35 changed files with 158 additions and 3,468 deletions.
6 changes: 3 additions & 3 deletions django/contrib/admin/util.py
Expand Up @@ -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), []])
Expand All @@ -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), []])
Expand Down Expand Up @@ -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') % \
Expand Down
19 changes: 14 additions & 5 deletions django/contrib/auth/management/commands/createsuperuser.py
Expand Up @@ -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 + (
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion django/contrib/auth/models.py
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions django/contrib/comments/forms.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/comments/models.py
Expand Up @@ -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

Expand Down
21 changes: 5 additions & 16 deletions django/contrib/contenttypes/generic.py
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -395,4 +385,3 @@ class GenericStackedInline(GenericInlineModelAdmin):

class GenericTabularInline(GenericInlineModelAdmin):
template = 'admin/edit_inline/tabular.html'

1 change: 0 additions & 1 deletion django/contrib/flatpages/models.py
@@ -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 _
Expand Down
1 change: 0 additions & 1 deletion django/contrib/localflavor/jp/forms.py
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions django/core/exceptions.py
Expand Up @@ -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
7 changes: 1 addition & 6 deletions django/core/serializers/base.py
Expand Up @@ -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):
"""
Expand Down

0 comments on commit c2ba59f

Please sign in to comment.