mirror of
https://github.com/django/django.git
synced 2025-07-03 09:19:16 +00:00
boulder-oracle-sprint: Merged to [4934].
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4935 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5bcf13b607
commit
a9b2c0686d
2
AUTHORS
2
AUTHORS
@ -42,6 +42,7 @@ people who have submitted patches, reported bugs, added translations, helped
|
||||
answer newbie questions, and generally made Django that much better:
|
||||
|
||||
adurdin@gmail.com
|
||||
Daniel Alves Barbosa de Oliveira Vaz <danielvaz@gmail.com>
|
||||
Andreas
|
||||
andy@jadedplanet.net
|
||||
Fabrice Aneche <akh@nobugware.com>
|
||||
@ -127,6 +128,7 @@ answer newbie questions, and generally made Django that much better:
|
||||
Nicola Larosa <nico@teknico.net>
|
||||
Eugene Lazutkin <http://lazutkin.com/blog/>
|
||||
Jeong-Min Lee <falsetru@gmail.com>
|
||||
Jannis Leidel <jl@websushi.org>
|
||||
Christopher Lenz <http://www.cmlenz.net/>
|
||||
lerouxb@gmail.com
|
||||
Waylan Limberg <waylan@gmail.com>
|
||||
|
@ -1,8 +1,12 @@
|
||||
include README
|
||||
include AUTHORS
|
||||
include INSTALL
|
||||
include LICENSE
|
||||
include MANIFEST.in
|
||||
recursive-include docs *
|
||||
recursive-include scripts *
|
||||
recursive-include examples *
|
||||
recursive-include extras *
|
||||
recursive-include django/conf/locale *
|
||||
recursive-include django/contrib/admin/templates *
|
||||
recursive-include django/contrib/admin/media *
|
||||
|
@ -1 +1 @@
|
||||
VERSION = (0, 96, None)
|
||||
VERSION = (0, 97, 'pre')
|
||||
|
@ -31,9 +31,9 @@ def compile_messages(locale=None):
|
||||
os.environ['djangocompilemo'] = pf + '.mo'
|
||||
os.environ['djangocompilepo'] = pf + '.po'
|
||||
if sys.platform == 'win32': # Different shell-variable syntax
|
||||
cmd = 'msgfmt -o "%djangocompilemo%" "%djangocompilepo%"'
|
||||
cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'
|
||||
else:
|
||||
cmd = 'msgfmt -o "$djangocompilemo" "$djangocompilepo"'
|
||||
cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'
|
||||
os.system(cmd)
|
||||
|
||||
def main():
|
||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@ BR-specific Form helpers
|
||||
|
||||
from django.newforms import ValidationError
|
||||
from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
|
||||
from django.newforms.util import smart_unicode
|
||||
from django.utils.encoding import smart_unicode
|
||||
from django.utils.translation import gettext
|
||||
import re
|
||||
|
||||
@ -15,7 +15,7 @@ class BRZipCodeField(RegexField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$',
|
||||
max_length=None, min_length=None,
|
||||
error_message=u'Informe um código postal no formato XXXXX-XXX.',
|
||||
error_message=gettext(u'Enter a zip code in the format XXXXX-XXX.'),
|
||||
*args, **kwargs)
|
||||
|
||||
class BRPhoneNumberField(Field):
|
||||
@ -27,7 +27,7 @@ class BRPhoneNumberField(Field):
|
||||
m = phone_digits_re.search(value)
|
||||
if m:
|
||||
return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
|
||||
raise ValidationError(u'Números de telefone devem estar no formato XX-XXXX-XXXX.')
|
||||
raise ValidationError(gettext(u'Phone numbers must be in XX-XXXX-XXXX format.'))
|
||||
|
||||
class BRStateSelect(Select):
|
||||
"""
|
||||
|
0
django/contrib/localflavor/de/__init__.py
Normal file
0
django/contrib/localflavor/de/__init__.py
Normal file
21
django/contrib/localflavor/de/de_states.py
Normal file
21
django/contrib/localflavor/de/de_states.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
STATE_CHOICES = (
|
||||
('BW', _('Baden-Wuerttemberg')),
|
||||
('BY', _('Bavaria')),
|
||||
('BE', _('Berlin')),
|
||||
('BB', _('Brandenburg')),
|
||||
('HB', _('Bremen')),
|
||||
('HH', _('Hamburg')),
|
||||
('HE', _('Hessen')),
|
||||
('MV', _('Mecklenburg-Western Pomerania')),
|
||||
('NI', _('Lower Saxony')),
|
||||
('NW', _('North Rhine-Westphalia')),
|
||||
('RP', _('Rhineland-Palatinate')),
|
||||
('SL', _('Saarland')),
|
||||
('SN', _('Saxony')),
|
||||
('ST', _('Saxony-Anhalt')),
|
||||
('SH', _('Schleswig-Holstein')),
|
||||
('TH', _('Thuringia')),
|
||||
)
|
87
django/contrib/localflavor/de/forms.py
Normal file
87
django/contrib/localflavor/de/forms.py
Normal file
@ -0,0 +1,87 @@
|
||||
"""
|
||||
DE-specific Form helpers
|
||||
"""
|
||||
|
||||
from django.newforms import ValidationError
|
||||
from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
|
||||
from django.utils.translation import gettext
|
||||
import re
|
||||
|
||||
id_re = re.compile(r"^(?P<residence>\d{10})(?P<origin>\w{1,3})[-\ ]?(?P<birthday>\d{7})[-\ ]?(?P<validity>\d{7})[-\ ]?(?P<checksum>\d{1})$")
|
||||
|
||||
class DEZipCodeField(RegexField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DEZipCodeField, self).__init__(r'^\d{5}$',
|
||||
max_length=None, min_length=None,
|
||||
error_message=gettext(u'Enter a zip code in the format XXXXX.'),
|
||||
*args, **kwargs)
|
||||
|
||||
class DEStateSelect(Select):
|
||||
"""
|
||||
A Select widget that uses a list of DE states as its choices.
|
||||
"""
|
||||
def __init__(self, attrs=None):
|
||||
from de_states import STATE_CHOICES # relative import
|
||||
super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
||||
|
||||
class DEIdentityCardNumberField(Field):
|
||||
"""
|
||||
A German identity card number.
|
||||
|
||||
Checks the following rules to determine whether the number is valid:
|
||||
|
||||
* Conforms to the XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.
|
||||
* No group consists entirely of zeroes.
|
||||
* Included checksums match calculated checksums
|
||||
|
||||
Algorithm is documented at http://de.wikipedia.org/wiki/Personalausweis
|
||||
"""
|
||||
def has_valid_checksum(self, number):
|
||||
given_number, given_checksum = number[:-1], number[-1]
|
||||
calculated_checksum = 0
|
||||
fragment = ""
|
||||
parameter = 7
|
||||
|
||||
for i in range(len(given_number)):
|
||||
fragment = str(int(given_number[i])*parameter)
|
||||
if fragment.isalnum():
|
||||
calculated_checksum += int(fragment[-1])
|
||||
|
||||
if parameter == 1:
|
||||
parameter = 7
|
||||
elif parameter == 3:
|
||||
parameter = 1
|
||||
elif parameter ==7:
|
||||
parameter = 3
|
||||
|
||||
if str(calculated_checksum)[-1] == given_checksum:
|
||||
return True
|
||||
return False
|
||||
|
||||
def clean(self, value):
|
||||
super(DEIdentityCardNumberField, self).clean(value)
|
||||
error_msg = gettext(u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format')
|
||||
if value in EMPTY_VALUES:
|
||||
return u''
|
||||
match = re.match(id_re, value)
|
||||
if not match:
|
||||
raise ValidationError(error_msg)
|
||||
|
||||
residence, origin, birthday, validity, checksum = \
|
||||
match.groupdict()['residence'], match.groupdict()['origin'], \
|
||||
match.groupdict()['birthday'], match.groupdict()['validity'], \
|
||||
match.groupdict()['checksum']
|
||||
|
||||
if residence == '0000000000' or \
|
||||
birthday == '0000000' or \
|
||||
validity == '0000000':
|
||||
raise ValidationError(error_msg)
|
||||
|
||||
all_digits = "%s%s%s%s" % (residence, birthday, validity, checksum)
|
||||
if not self.has_valid_checksum(residence) or \
|
||||
not self.has_valid_checksum(birthday) or \
|
||||
not self.has_valid_checksum(validity) or \
|
||||
not self.has_valid_checksum(all_digits):
|
||||
raise ValidationError(error_msg)
|
||||
|
||||
return u'%s%s-%s-%s-%s' % (residence, origin, birthday, validity, checksum)
|
@ -4,7 +4,7 @@ FR-specific Form helpers
|
||||
|
||||
from django.newforms import ValidationError
|
||||
from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
|
||||
from django.newforms.util import smart_unicode
|
||||
from django.utils.encoding import smart_unicode
|
||||
from django.utils.translation import gettext
|
||||
import re
|
||||
|
||||
|
@ -4,7 +4,6 @@ IT-specific Form helpers
|
||||
|
||||
from django.newforms import ValidationError
|
||||
from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
|
||||
from django.newforms.util import smart_unicode
|
||||
from django.utils.translation import gettext
|
||||
import re
|
||||
|
||||
|
@ -4,11 +4,12 @@ USA-specific Form helpers
|
||||
|
||||
from django.newforms import ValidationError
|
||||
from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
|
||||
from django.newforms.util import smart_unicode
|
||||
from django.utils.encoding import smart_unicode
|
||||
from django.utils.translation import gettext
|
||||
import re
|
||||
|
||||
phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$')
|
||||
ssn_re = re.compile(r"^(?P<area>\d{3})[-\ ]?(?P<group>\d{2})[-\ ]?(?P<serial>\d{4})$")
|
||||
|
||||
class USZipCodeField(RegexField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -28,6 +29,45 @@ class USPhoneNumberField(Field):
|
||||
return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
|
||||
raise ValidationError(u'Phone numbers must be in XXX-XXX-XXXX format.')
|
||||
|
||||
class USSocialSecurityNumberField(Field):
|
||||
"""
|
||||
A United States Social Security number.
|
||||
|
||||
Checks the following rules to determine whether the number is valid:
|
||||
|
||||
* Conforms to the XXX-XX-XXXX format.
|
||||
* No group consists entirely of zeroes.
|
||||
* The leading group is not "666" (block "666" will never be allocated).
|
||||
* The number is not in the promotional block 987-65-4320 through 987-65-4329,
|
||||
which are permanently invalid.
|
||||
* The number is not one known to be invalid due to otherwise widespread
|
||||
promotional use or distribution (e.g., the Woolworth's number or the 1962
|
||||
promotional number).
|
||||
"""
|
||||
def clean(self, value):
|
||||
super(USSocialSecurityNumberField, self).clean(value)
|
||||
if value in EMPTY_VALUES:
|
||||
return u''
|
||||
msg = gettext(u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.')
|
||||
match = re.match(ssn_re, value)
|
||||
if not match:
|
||||
raise ValidationError(msg)
|
||||
area, group, serial = match.groupdict()['area'], match.groupdict()['group'], match.groupdict()['serial']
|
||||
|
||||
# First pass: no blocks of all zeroes.
|
||||
if area == '000' or \
|
||||
group == '00' or \
|
||||
serial == '0000':
|
||||
raise ValidationError(msg)
|
||||
|
||||
# Second pass: promotional and otherwise permanently invalid numbers.
|
||||
if area == '666' or \
|
||||
(area == '987' and group == '65' and 4320 <= int(serial) <= 4329) or \
|
||||
value == '078-05-1120' or \
|
||||
value == '219-09-9999':
|
||||
raise ValidationError(msg)
|
||||
return u'%s-%s-%s' % (area, group, serial)
|
||||
|
||||
class USStateField(Field):
|
||||
"""
|
||||
A form field that validates its input is a U.S. state name or abbreviation.
|
||||
|
@ -3,7 +3,8 @@ Field classes
|
||||
"""
|
||||
|
||||
from django.utils.translation import gettext
|
||||
from util import ErrorList, ValidationError, smart_unicode
|
||||
from django.utils.encoding import smart_unicode
|
||||
from util import ErrorList, ValidationError
|
||||
from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple
|
||||
import datetime
|
||||
import re
|
||||
|
@ -4,9 +4,10 @@ Form classes
|
||||
|
||||
from django.utils.datastructures import SortedDict, MultiValueDict
|
||||
from django.utils.html import escape
|
||||
from django.utils.encoding import StrAndUnicode
|
||||
from fields import Field
|
||||
from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput
|
||||
from util import flatatt, StrAndUnicode, ErrorDict, ErrorList, ValidationError
|
||||
from util import flatatt, ErrorDict, ErrorList, ValidationError
|
||||
import copy
|
||||
|
||||
__all__ = ('BaseForm', 'Form')
|
||||
@ -227,9 +228,9 @@ class BoundField(StrAndUnicode):
|
||||
value = self.as_widget(self.field.widget)
|
||||
if not isinstance(value, basestring):
|
||||
# Some Widget render() methods -- notably RadioSelect -- return a
|
||||
# "special" object rather than a string. Call the __str__() on that
|
||||
# "special" object rather than a string. Call __unicode__() on that
|
||||
# object to get its rendered value.
|
||||
value = value.__str__()
|
||||
value = unicode(value)
|
||||
return value
|
||||
|
||||
def _errors(self):
|
||||
|
@ -1,41 +1,12 @@
|
||||
from django.conf import settings
|
||||
from django.utils.html import escape
|
||||
from django.utils.functional import Promise, lazy
|
||||
from django.utils.encoding import smart_unicode
|
||||
|
||||
# Converts a dictionary to a single string with key="value", XML-style with
|
||||
# a leading space. Assumes keys do not need to be XML-escaped.
|
||||
flatatt = lambda attrs: u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()])
|
||||
|
||||
def smart_unicode(s):
|
||||
if isinstance(s, Promise):
|
||||
# The input is something from gettext_lazy or similar. We don't want to
|
||||
# translate it until render time, so defer the conversion.
|
||||
return smart_unicode_lazy(s)
|
||||
else:
|
||||
return smart_unicode_immediate(s)
|
||||
|
||||
def smart_unicode_immediate(s):
|
||||
if not isinstance(s, basestring):
|
||||
if hasattr(s, '__unicode__'):
|
||||
s = unicode(s)
|
||||
else:
|
||||
s = unicode(str(s), settings.DEFAULT_CHARSET)
|
||||
elif not isinstance(s, unicode):
|
||||
s = unicode(s, settings.DEFAULT_CHARSET)
|
||||
return s
|
||||
|
||||
smart_unicode_lazy = lazy(smart_unicode_immediate, unicode)
|
||||
|
||||
class StrAndUnicode(object):
|
||||
"""
|
||||
A class whose __str__ returns its __unicode__ as a bytestring
|
||||
according to settings.DEFAULT_CHARSET.
|
||||
|
||||
Useful as a mix-in.
|
||||
"""
|
||||
def __str__(self):
|
||||
return self.__unicode__().encode(settings.DEFAULT_CHARSET)
|
||||
|
||||
class ErrorDict(dict):
|
||||
"""
|
||||
A collection of errors that knows how to display itself in various formats.
|
||||
|
@ -9,10 +9,11 @@ __all__ = (
|
||||
'MultiWidget', 'SplitDateTimeWidget',
|
||||
)
|
||||
|
||||
from util import flatatt, StrAndUnicode, smart_unicode
|
||||
from util import flatatt
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
from django.utils.html import escape
|
||||
from django.utils.translation import gettext
|
||||
from django.utils.encoding import StrAndUnicode, smart_unicode
|
||||
from itertools import chain
|
||||
|
||||
try:
|
||||
|
@ -989,7 +989,9 @@ widthratio = register.tag(widthratio)
|
||||
def do_with(parser, token):
|
||||
"""
|
||||
Add a value to the context (inside of this block) for caching and easy
|
||||
access. For example::
|
||||
access.
|
||||
|
||||
For example::
|
||||
|
||||
{% with person.some_sql_method as total %}
|
||||
{{ total }} object{{ total|pluralize }}
|
||||
|
32
django/utils/encoding.py
Normal file
32
django/utils/encoding.py
Normal file
@ -0,0 +1,32 @@
|
||||
from django.conf import settings
|
||||
from django.utils.functional import Promise
|
||||
|
||||
def smart_unicode(s):
|
||||
if isinstance(s, Promise):
|
||||
# The input is the result of a gettext_lazy() call, or similar. It will
|
||||
# already be encoded in DEFAULT_CHARSET on evaluation and we don't want
|
||||
# to evaluate it until render time.
|
||||
# FIXME: This isn't totally consistent, because it eventually returns a
|
||||
# bytestring rather than a unicode object. It works wherever we use
|
||||
# smart_unicode() at the moment. Fixing this requires work in the
|
||||
# i18n internals.
|
||||
return s
|
||||
if not isinstance(s, basestring,):
|
||||
if hasattr(s, '__unicode__'):
|
||||
s = unicode(s)
|
||||
else:
|
||||
s = unicode(str(s), settings.DEFAULT_CHARSET)
|
||||
elif not isinstance(s, unicode):
|
||||
s = unicode(s, settings.DEFAULT_CHARSET)
|
||||
return s
|
||||
|
||||
class StrAndUnicode(object):
|
||||
"""
|
||||
A class whose __str__ returns its __unicode__ as a bytestring
|
||||
according to settings.DEFAULT_CHARSET.
|
||||
|
||||
Useful as a mix-in.
|
||||
"""
|
||||
def __str__(self):
|
||||
return self.__unicode__().encode(settings.DEFAULT_CHARSET)
|
||||
|
@ -1,6 +1,7 @@
|
||||
"HTML utilities suitable for global use."
|
||||
|
||||
import re, string
|
||||
from django.utils.encoding import smart_unicode
|
||||
|
||||
# Configuration for urlize() function
|
||||
LEADING_PUNCTUATION = ['(', '<', '<']
|
||||
|
@ -7,7 +7,7 @@ __all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext',
|
||||
'ngettext_lazy', 'string_concat', 'activate', 'deactivate',
|
||||
'get_language', 'get_language_bidi', 'get_date_formats',
|
||||
'get_partial_date_formats', 'check_for_language', 'to_locale',
|
||||
'get_language_from_request', 'install']
|
||||
'get_language_from_request', 'install', 'templatize']
|
||||
|
||||
# Here be dragons, so a short explanation of the logic won't hurt:
|
||||
# We are trying to solve two problems: (1) access settings, in particular
|
||||
@ -92,3 +92,6 @@ def get_language_from_request(request):
|
||||
def install():
|
||||
return real_install()
|
||||
|
||||
def templatize(src):
|
||||
return real_templatize(src)
|
||||
|
||||
|
@ -9,7 +9,6 @@ def ngettext(singular, plural, number):
|
||||
return plural
|
||||
ngettext_lazy = ngettext
|
||||
|
||||
gettext = gettext_noop = gettext_lazy = _ = lambda x: x
|
||||
string_concat = lambda *strings: ''.join([str(el) for el in strings])
|
||||
activate = lambda x: None
|
||||
deactivate = install = lambda: None
|
||||
@ -19,6 +18,20 @@ get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, sett
|
||||
get_partial_date_formats = lambda: (settings.YEAR_MONTH_FORMAT, settings.MONTH_DAY_FORMAT)
|
||||
check_for_language = lambda x: True
|
||||
|
||||
TECHNICAL_ID_MAP = {
|
||||
"DATE_WITH_TIME_FULL": settings.DATETIME_FORMAT,
|
||||
"DATE_FORMAT": settings.DATE_FORMAT,
|
||||
"DATETIME_FORMAT": settings.DATETIME_FORMAT,
|
||||
"TIME_FORMAT": settings.TIME_FORMAT,
|
||||
"YEAR_MONTH_FORMAT": settings.YEAR_MONTH_FORMAT,
|
||||
"MONTH_DAY_FORMAT": settings.MONTH_DAY_FORMAT,
|
||||
}
|
||||
|
||||
def gettext(message):
|
||||
return TECHNICAL_ID_MAP.get(message, message)
|
||||
|
||||
gettext_noop = gettext_lazy = _ = gettext
|
||||
|
||||
def to_locale(language):
|
||||
p = language.find('-')
|
||||
if p >= 0:
|
||||
|
@ -382,9 +382,9 @@ Why do I get an error about importing DJANGO_SETTINGS_MODULE?
|
||||
Make sure that:
|
||||
|
||||
* The environment variable DJANGO_SETTINGS_MODULE is set to a fully-qualified
|
||||
Python module (i.e. "mysite.settings.main").
|
||||
Python module (i.e. "mysite.settings").
|
||||
|
||||
* Said module is on ``sys.path`` (``import mysite.settings.main`` should work).
|
||||
* Said module is on ``sys.path`` (``import mysite.settings`` should work).
|
||||
|
||||
* The module doesn't contain syntax errors (of course).
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# this file is *inserted* into the install section of the generated
|
||||
# spec file
|
||||
# This file becomes the install section of the generated spec file.
|
||||
#
|
||||
|
||||
# this is, what dist.py normally does
|
||||
# This is what dist.py normally does.
|
||||
python setup.py install --root=${RPM_BUILD_ROOT} --record="INSTALLED_FILES"
|
||||
|
||||
# Sort the filelist so that directories appear before files. This avoids
|
||||
# duplicate filename problems on some systems.
|
||||
touch DIRS
|
||||
for i in `cat INSTALLED_FILES`; do
|
||||
if [ -f ${RPM_BUILD_ROOT}/$i ]; then
|
||||
echo $i >>FILES
|
||||
@ -16,4 +18,6 @@ for i in `cat INSTALLED_FILES`; do
|
||||
fi
|
||||
done
|
||||
|
||||
cat DIRS FILES >INSTALLED_FILES
|
||||
# Make sure we match foo.pyo and foo.pyc along with foo.py (but only once each)
|
||||
sed -e "/\.py[co]$/d" -e "s/\.py$/.py*/" DIRS FILES >INSTALLED_FILES
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
[bdist_rpm]
|
||||
doc_files = docs/*.txt
|
||||
doc_files = docs examples extras AUTHORS INSTALL LICENSE README
|
||||
install-script = scripts/rpm-install.sh
|
||||
|
||||
|
37
setup.py
37
setup.py
@ -3,6 +3,20 @@ from distutils.command.install import INSTALL_SCHEMES
|
||||
import os
|
||||
import sys
|
||||
|
||||
def fullsplit(path, result=None):
|
||||
"""
|
||||
Split a pathname into components (the opposite of os.path.join) in a
|
||||
platform-neutral way.
|
||||
"""
|
||||
if result is None:
|
||||
result = []
|
||||
head, tail = os.path.split(path)
|
||||
if head == '':
|
||||
return [tail] + result
|
||||
if head == path:
|
||||
return result
|
||||
return fullsplit(head, [tail] + result)
|
||||
|
||||
# Tell distutils to put the data_files in platform-specific installation
|
||||
# locations. See here for an explanation:
|
||||
# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
|
||||
@ -13,27 +27,28 @@ for scheme in INSTALL_SCHEMES.values():
|
||||
# an easy way to do this.
|
||||
packages, data_files = [], []
|
||||
root_dir = os.path.dirname(__file__)
|
||||
len_root_dir = len(root_dir)
|
||||
django_dir = os.path.join(root_dir, 'django')
|
||||
pieces = fullsplit(root_dir)
|
||||
if pieces[-1] == '':
|
||||
len_root_dir = len(pieces) - 1
|
||||
else:
|
||||
len_root_dir = len(pieces)
|
||||
|
||||
for dirpath, dirnames, filenames in os.walk(django_dir):
|
||||
# Ignore dirnames that start with '.'
|
||||
for i, dirname in enumerate(dirnames):
|
||||
if dirname.startswith('.'): del dirnames[i]
|
||||
if '__init__.py' in filenames:
|
||||
package = dirpath[len_root_dir:].lstrip('/').replace('/', '.')
|
||||
packages.append(package)
|
||||
else:
|
||||
packages.append('.'.join(fullsplit(dirpath)[len_root_dir:]))
|
||||
elif filenames:
|
||||
data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
|
||||
|
||||
# Small hack for working with bdist_wininst.
|
||||
# See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
|
||||
for file_info in data_files:
|
||||
file_info[0] = '/PURELIB/%s' % file_info[0]
|
||||
|
||||
# Dynamically calculate the version based on django.VERSION.
|
||||
version = "%d.%d-%s" % (__import__('django').VERSION)
|
||||
version_tuple = __import__('django').VERSION
|
||||
if version_tuple[2] is not None:
|
||||
version = "%d.%d_%s" % version_tuple
|
||||
else:
|
||||
version = "%d.%d" % version_tuple[:2]
|
||||
|
||||
setup(
|
||||
name = "Django",
|
||||
|
@ -1,3 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
r"""
|
||||
>>> floatformat(7.7)
|
||||
'7.7'
|
||||
@ -87,19 +89,19 @@ u'\xeb'
|
||||
>>> truncatewords('A sentence with a few words in it', 'not a number')
|
||||
'A sentence with a few words in it'
|
||||
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 0)
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 0)
|
||||
''
|
||||
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 2)
|
||||
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 2)
|
||||
'<p>one <a href="#">two ...</a></p>'
|
||||
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 4)
|
||||
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 4)
|
||||
'<p>one <a href="#">two - three <br>four ...</a></p>'
|
||||
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 5)
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 5)
|
||||
'<p>one <a href="#">two - three <br>four</a> five</p>'
|
||||
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 100)
|
||||
>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 100)
|
||||
'<p>one <a href="#">two - three <br>four</a> five</p>'
|
||||
|
||||
>>> upper('Mixed case input')
|
||||
@ -166,6 +168,9 @@ u'\xcb'
|
||||
>>> escape('<some html & special characters > here')
|
||||
'<some html & special characters > here'
|
||||
|
||||
>>> escape(u'<some html & special characters > here ĐÅ€£')
|
||||
u'<some html & special characters > here \xc4\x90\xc3\x85\xe2\x82\xac\xc2\xa3'
|
||||
|
||||
>>> linebreaks('line 1')
|
||||
'<p>line 1</p>'
|
||||
|
||||
|
@ -246,6 +246,18 @@ as its choices.
|
||||
<option value="WY">Wyoming</option>
|
||||
</select>
|
||||
|
||||
# USSocialSecurityNumberField #################################################
|
||||
>>> from django.contrib.localflavor.usa.forms import USSocialSecurityNumberField
|
||||
>>> f = USSocialSecurityNumberField()
|
||||
>>> f.clean('987-65-4330')
|
||||
u'987-65-4330'
|
||||
>>> f.clean('987654330')
|
||||
u'987-65-4330'
|
||||
>>> f.clean('078-05-1120')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.']
|
||||
|
||||
# UKPostcodeField #############################################################
|
||||
|
||||
UKPostcodeField validates that the data is a valid UK postcode.
|
||||
@ -734,23 +746,23 @@ u'12345-123'
|
||||
>>> f.clean('12345_123')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('1234-123')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('abcde-abc')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('12345-')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('-123')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
@ -768,23 +780,23 @@ u''
|
||||
>>> f.clean('-123')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('12345-')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('abcde-abc')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('1234-123')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('12345_123')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Informe um c\xf3digo postal no formato XXXXX-XXX.']
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX-XXX.']
|
||||
>>> f.clean('12345-123')
|
||||
u'12345-123'
|
||||
|
||||
@ -839,4 +851,35 @@ u'41-3562-3464'
|
||||
>>> w = BRStateSelect()
|
||||
>>> w.render('states', 'PR')
|
||||
u'<select name="states">\n<option value="AC">Acre</option>\n<option value="AL">Alagoas</option>\n<option value="AP">Amap\xe1</option>\n<option value="AM">Amazonas</option>\n<option value="BA">Bahia</option>\n<option value="CE">Cear\xe1</option>\n<option value="DF">Distrito Federal</option>\n<option value="ES">Esp\xedrito Santo</option>\n<option value="GO">Goi\xe1s</option>\n<option value="MA">Maranh\xe3o</option>\n<option value="MT">Mato Grosso</option>\n<option value="MS">Mato Grosso do Sul</option>\n<option value="MG">Minas Gerais</option>\n<option value="PA">Par\xe1</option>\n<option value="PB">Para\xedba</option>\n<option value="PR" selected="selected">Paran\xe1</option>\n<option value="PE">Pernambuco</option>\n<option value="PI">Piau\xed</option>\n<option value="RJ">Rio de Janeiro</option>\n<option value="RN">Rio Grande do Norte</option>\n<option value="RS">Rio Grande do Sul</option>\n<option value="RO">Rond\xf4nia</option>\n<option value="RR">Roraima</option>\n<option value="SC">Santa Catarina</option>\n<option value="SP">S\xe3o Paulo</option>\n<option value="SE">Sergipe</option>\n<option value="TO">Tocantins</option>\n</select>'
|
||||
|
||||
# DEZipCodeField ##############################################################
|
||||
|
||||
>>> from django.contrib.localflavor.de.forms import DEZipCodeField
|
||||
>>> f = DEZipCodeField()
|
||||
>>> f.clean('99423')
|
||||
u'99423'
|
||||
>>> f.clean(' 99423')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a zip code in the format XXXXX.']
|
||||
|
||||
# DEStateSelect #############################################################
|
||||
|
||||
>>> from django.contrib.localflavor.de.forms import DEStateSelect
|
||||
>>> w = DEStateSelect()
|
||||
>>> w.render('states', 'TH')
|
||||
u'<select name="states">\n<option value="BW">Baden-Wuerttemberg</option>\n<option value="BY">Bavaria</option>\n<option value="BE">Berlin</option>\n<option value="BB">Brandenburg</option>\n<option value="HB">Bremen</option>\n<option value="HH">Hamburg</option>\n<option value="HE">Hessen</option>\n<option value="MV">Mecklenburg-Western Pomerania</option>\n<option value="NI">Lower Saxony</option>\n<option value="NW">North Rhine-Westphalia</option>\n<option value="RP">Rhineland-Palatinate</option>\n<option value="SL">Saarland</option>\n<option value="SN">Saxony</option>\n<option value="ST">Saxony-Anhalt</option>\n<option value="SH">Schleswig-Holstein</option>\n<option value="TH" selected="selected">Thuringia</option>\n</select>'
|
||||
|
||||
# DEIdentityCardNumberField #################################################
|
||||
|
||||
>>> from django.contrib.localflavor.de.forms import DEIdentityCardNumberField
|
||||
>>> f = DEIdentityCardNumberField()
|
||||
>>> f.clean('7549313035D-6004103-0903042-0')
|
||||
u'7549313035D-6004103-0903042-0'
|
||||
>>> f.clean('9786324830D 6104243 0910271 2')
|
||||
u'9786324830D-6104243-0910271-2'
|
||||
>>> f.clean('0434657485D-6407276-0508137-9')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format']
|
||||
"""
|
||||
|
@ -11,11 +11,11 @@ It should be possible to re-use attribute dictionaries (#3810)
|
||||
>>> TestForm(auto_id=False).as_p()
|
||||
u'<p>F1: <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2: <input type="text" class="special" name="f2" /></p>'
|
||||
|
||||
#######################
|
||||
# Tests for form i18n #
|
||||
#######################
|
||||
#######################
|
||||
# Tests for form i18n #
|
||||
#######################
|
||||
There were some problems with form translations in #3600
|
||||
|
||||
|
||||
>>> from django.utils.translation import gettext_lazy, activate, deactivate
|
||||
>>> class SomeForm(Form):
|
||||
... username = CharField(max_length=10, label=gettext_lazy('Username'))
|
||||
@ -26,4 +26,12 @@ There were some problems with form translations in #3600
|
||||
>>> print f.as_p()
|
||||
<p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
|
||||
>>> deactivate()
|
||||
|
||||
Unicode decoding problems...
|
||||
>>> GENDERS = (('0', u'En tied\xe4'), ('1', u'Mies'), ('2', u'Nainen'))
|
||||
>>> class SomeForm(Form):
|
||||
... somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect())
|
||||
>>> f = SomeForm()
|
||||
>>> f.as_p()
|
||||
u'<p><label for="id_somechoice_0">Somechoice:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="0" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="1" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="2" name="somechoice" /> Nainen</label></li>\n</ul></p>'
|
||||
"""
|
||||
|
@ -1455,7 +1455,7 @@ u''
|
||||
>>> f.clean('http://www.google.com') # This will fail if there's no Internet connection
|
||||
u'http://www.google.com'
|
||||
|
||||
EmailField also access min_length and max_length parameters, for convenience.
|
||||
URLField also access min_length and max_length parameters, for convenience.
|
||||
>>> f = URLField(min_length=15, max_length=20)
|
||||
>>> f.clean('http://f.com')
|
||||
Traceback (most recent call last):
|
||||
@ -3276,7 +3276,7 @@ True
|
||||
#################################
|
||||
|
||||
# smart_unicode tests
|
||||
>>> from django.newforms.util import smart_unicode
|
||||
>>> from django.utils.encoding import smart_unicode
|
||||
>>> class Test:
|
||||
... def __str__(self):
|
||||
... return 'ŠĐĆŽćžšđ'
|
||||
|
Loading…
x
Reference in New Issue
Block a user