Django

Code

root/django/trunk/django/contrib/localflavor/jp/forms.py

Revision 8616, 1.2 kB (checked in by gwilson, 3 months ago)

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).
  • Property svn:eol-style set to native
Line 
1 """
2 JP-specific Form helpers
3 """
4
5 from django.forms import ValidationError
6 from django.utils.translation import ugettext_lazy as _
7 from django.forms.fields import RegexField, Select
8
9 class JPPostalCodeField(RegexField):
10     """
11     A form field that validates its input is a Japanese postcode.
12
13     Accepts 7 digits, with or without a hyphen.
14     """
15     default_error_messages = {
16         'invalid': _('Enter a postal code in the format XXXXXXX or XXX-XXXX.'),
17     }
18
19     def __init__(self, *args, **kwargs):
20         super(JPPostalCodeField, self).__init__(r'^\d{3}-\d{4}$|^\d{7}$',
21             max_length=None, min_length=None, *args, **kwargs)
22
23     def clean(self, value):
24         """
25         Validates the input and returns a string that contains only numbers.
26         Returns an empty string for empty values.
27         """
28         v = super(JPPostalCodeField, self).clean(value)
29         return v.replace('-', '')
30
31 class JPPrefectureSelect(Select):
32     """
33     A Select widget that uses a list of Japanese prefectures as its choices.
34     """
35     def __init__(self, attrs=None):
36         from jp_prefectures import JP_PREFECTURES
37         super(JPPrefectureSelect, self).__init__(attrs, choices=JP_PREFECTURES)
Note: See TracBrowser for help on using the browser.