Permalink
Browse files

Merge branch 'master' into schema-alteration

  • Loading branch information...
2 parents ca9c3cd + 5999eb4 commit 828d691f62814edf3e93d981c0f991a48781fb79 @andrewgodwin andrewgodwin committed Sep 7, 2012
Showing with 414 additions and 415 deletions.
  1. +6 −5 django/contrib/auth/tests/models.py
  2. +5 −5 django/contrib/localflavor/hr/forms.py
  3. +11 −11 django/contrib/localflavor/ro/forms.py
  4. +1 −1 django/core/cache/backends/memcached.py
  5. +1 −1 django/core/mail/backends/console.py
  6. +6 −1 django/db/backends/creation.py
  7. +1 −4 django/db/backends/sqlite3/base.py
  8. +3 −9 django/db/models/sql/compiler.py
  9. +3 −2 django/db/models/sql/query.py
  10. +18 −18 django/forms/formsets.py
  11. +2 −6 django/forms/widgets.py
  12. +2 −3 django/http/multipartparser.py
  13. +1 −1 django/test/testcases.py
  14. +7 −0 django/utils/six.py
  15. +1 −1 docs/intro/tutorial03.txt
  16. +13 −13 docs/ref/contrib/gis/install.txt
  17. +2 −3 docs/ref/forms/validation.txt
  18. +4 −0 docs/ref/forms/widgets.txt
  19. +4 −3 docs/ref/models/options.txt
  20. +1 −2 docs/ref/models/querysets.txt
  21. +1 −1 docs/releases/1.3.txt
  22. +2 −2 docs/topics/db/queries.txt
  23. +13 −5 docs/topics/python3.txt
  24. +26 −6 docs/topics/security.txt
  25. +14 −14 tests/modeltests/basic/tests.py
  26. +4 −3 tests/modeltests/empty/tests.py
  27. +17 −17 tests/modeltests/fixtures/tests.py
  28. +2 −1 tests/modeltests/many_to_many/tests.py
  29. +1 −1 tests/modeltests/many_to_one/tests.py
  30. +1 −1 tests/modeltests/raw_query/tests.py
  31. +2 −1 tests/modeltests/update_only_fields/tests.py
  32. +2 −1 tests/modeltests/validation/test_error_messages.py
  33. +4 −3 tests/regressiontests/admin_filters/tests.py
  34. +3 −3 tests/regressiontests/admin_scripts/tests.py
  35. +1 −1 tests/regressiontests/backends/tests.py
  36. +3 −4 tests/regressiontests/cache/tests.py
  37. +1 −1 tests/regressiontests/file_storage/tests.py
  38. +7 −9 tests/regressiontests/file_uploads/tests.py
  39. +20 −24 tests/regressiontests/fixtures_regress/tests.py
  40. +3 −3 tests/regressiontests/forms/tests/fields.py
  41. +3 −7 tests/regressiontests/forms/tests/widgets.py
  42. +1 −3 tests/regressiontests/handlers/tests.py
  43. +5 −4 tests/regressiontests/i18n/commands/compilation.py
  44. +2 −2 tests/regressiontests/inline_formsets/tests.py
  45. +17 −15 tests/regressiontests/localflavor/tr/tests.py
  46. +3 −2 tests/regressiontests/m2m_regress/tests.py
  47. +3 −2 tests/regressiontests/many_to_one_regress/tests.py
  48. +64 −64 tests/regressiontests/modeladmin/tests.py
  49. +1 −4 tests/regressiontests/queries/tests.py
  50. +12 −10 tests/regressiontests/settings_tests/tests.py
  51. +34 −36 tests/regressiontests/signals_regress/tests.py
  52. +1 −1 tests/regressiontests/staticfiles_tests/tests.py
  53. +26 −25 tests/regressiontests/templates/custom.py
  54. +6 −6 tests/regressiontests/templates/loaders.py
  55. +3 −3 tests/regressiontests/test_utils/tests.py
  56. +7 −15 tests/regressiontests/transactions_regress/tests.py
  57. +4 −4 tests/regressiontests/urlpatterns_reverse/tests.py
  58. +0 −18 tests/regressiontests/utils/crypto.py
  59. +3 −4 tests/regressiontests/wsgi/tests.py
@@ -1,8 +1,9 @@
from django.conf import settings
+from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable,
+ UserManager)
from django.test import TestCase
from django.test.utils import override_settings
-from django.contrib.auth.models import (Group, User,
- SiteProfileNotAvailable, UserManager)
+from django.utils import six
@override_settings(USE_TZ=False, AUTH_PROFILE_MODULE='')
@@ -13,19 +14,19 @@ def test_site_profile_not_available(self):
# calling get_profile without AUTH_PROFILE_MODULE set
del settings.AUTH_PROFILE_MODULE
- with self.assertRaisesRegexp(SiteProfileNotAvailable,
+ with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"You need to set AUTH_PROFILE_MODULE in your project"):
user.get_profile()
# Bad syntax in AUTH_PROFILE_MODULE:
settings.AUTH_PROFILE_MODULE = 'foobar'
- with self.assertRaisesRegexp(SiteProfileNotAvailable,
+ with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"app_label and model_name should be separated by a dot"):
user.get_profile()
# module that doesn't exist
settings.AUTH_PROFILE_MODULE = 'foo.bar'
- with self.assertRaisesRegexp(SiteProfileNotAvailable,
+ with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"Unable to load the profile model"):
user.get_profile()
@@ -4,6 +4,7 @@
"""
from __future__ import absolute_import, unicode_literals
+import datetime
import re
from django.contrib.localflavor.hr.hr_choices import (
@@ -91,17 +92,16 @@ def clean(self, value):
dd = int(matches.group('dd'))
mm = int(matches.group('mm'))
yyy = int(matches.group('yyy'))
- import datetime
try:
- datetime.date(yyy,mm,dd)
- except:
+ datetime.date(yyy, mm, dd)
+ except ValueError:
raise ValidationError(self.error_messages['date'])
# Validate checksum.
k = matches.group('k')
checksum = 0
- for i,j in zip(range(7,1,-1),range(6)):
- checksum+=i*(int(value[j])+int(value[13-i]))
+ for i, j in zip(range(7, 1, -1), range(6)):
+ checksum += i * (int(value[j]) + int(value[13 - i]))
m = 11 - checksum % 11
if m == 10:
raise ValidationError(self.error_messages['invalid'])
@@ -4,6 +4,8 @@
"""
from __future__ import absolute_import, unicode_literals
+import datetime
+
from django.contrib.localflavor.ro.ro_counties import COUNTIES_CHOICES
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError, Field, RegexField, Select
@@ -69,10 +71,9 @@ def clean(self, value):
if value in EMPTY_VALUES:
return ''
# check birthdate digits
- import datetime
try:
- datetime.date(int(value[1:3]),int(value[3:5]),int(value[5:7]))
- except:
+ datetime.date(int(value[1:3]), int(value[3:5]), int(value[5:7]))
+ except ValueError:
raise ValidationError(self.error_messages['invalid'])
# checksum
key = '279146358279'
@@ -118,7 +119,7 @@ def clean(self, value):
# search for county name
normalized_CC = []
for entry in COUNTIES_CHOICES:
- normalized_CC.append((entry[0],entry[1].upper()))
+ normalized_CC.append((entry[0], entry[1].upper()))
for entry in normalized_CC:
if entry[1] == value:
return entry[0]
@@ -153,8 +154,8 @@ def clean(self, value):
value = super(ROIBANField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = value.replace('-','')
- value = value.replace(' ','')
+ value = value.replace('-', '')
+ value = value.replace(' ', '')
value = value.upper()
if value[0:2] != 'RO':
raise ValidationError(self.error_messages['invalid'])
@@ -185,10 +186,10 @@ def clean(self, value):
value = super(ROPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return ''
- value = value.replace('-','')
- value = value.replace('(','')
- value = value.replace(')','')
- value = value.replace(' ','')
+ value = value.replace('-', '')
+ value = value.replace('(', '')
+ value = value.replace(')', '')
+ value = value.replace(' ', '')
if len(value) != 10:
raise ValidationError(self.error_messages['invalid'])
return value
@@ -202,4 +203,3 @@ class ROPostalCodeField(RegexField):
def __init__(self, max_length=6, min_length=6, *args, **kwargs):
super(ROPostalCodeField, self).__init__(r'^[0-9][0-8][0-9]{4}$',
max_length, min_length, *args, **kwargs)
-
@@ -141,7 +141,7 @@ def __init__(self, server, params):
)
try:
import memcache
- except:
+ except ImportError:
raise InvalidCacheBackendError(
"Memcached cache backend requires either the 'memcache' or 'cmemcache' library"
)
@@ -21,7 +21,7 @@ def send_messages(self, email_messages):
stream_created = self.open()
for message in email_messages:
self.stream.write('%s\n' % message.message().as_string())
- self.stream.write('-'*79)
+ self.stream.write('-' * 79)
self.stream.write('\n')
self.stream.flush() # flush after each message
if stream_created:
@@ -1,8 +1,10 @@
+import hashlib
import sys
import time
from django.conf import settings
from django.db.utils import load_backend
+from django.utils.encoding import force_bytes
from django.utils.six.moves import input
# The prefix to put on the default database name when creating
@@ -29,7 +31,10 @@ def _digest(cls, *args):
Generates a 32-bit digest of a set of arguments that can be used to
shorten identifying names.
"""
- return '%x' % (abs(hash(args)) % 4294967296) # 2**32
+ h = hashlib.md5()
+ for arg in args:
+ h.update(force_bytes(arg))
+ return h.hexdigest()[:8]
def sql_create_model(self, model, style, known_models=set()):
"""
@@ -419,7 +419,4 @@ def _sqlite_format_dtdelta(dt, conn, days, secs, usecs):
return str(dt)
def _sqlite_regexp(re_pattern, re_string):
- try:
- return bool(re.search(re_pattern, re_string))
- except:
- return False
+ return bool(re.search(re_pattern, re_string))
@@ -4,7 +4,8 @@
from django.db import transaction
from django.db.backends.util import truncate_name
from django.db.models.query_utils import select_related_descend
-from django.db.models.sql.constants import *
+from django.db.models.sql.constants import (SINGLE, MULTI, ORDER_DIR,
+ LOOKUP_SEP, GET_ITERATOR_CHUNK_SIZE)
from django.db.models.sql.datastructures import EmptyResultSet
from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.query import get_order_dir, Query
@@ -811,7 +812,7 @@ def execute_sql(self, result_type=MULTI):
raise EmptyResultSet
except EmptyResultSet:
if result_type == MULTI:
- return empty_iter()
+ return iter([])
else:
return
@@ -1088,13 +1089,6 @@ def results_iter(self):
yield date
-def empty_iter():
- """
- Returns an iterator containing no results.
- """
- yield next(iter([]))
-
-
def order_modified_iter(cursor, trim, sentinel):
"""
Yields blocks of rows from a cursor. We use this iterator in the special
@@ -17,9 +17,9 @@
from django.db.models import signals
from django.db.models.expressions import ExpressionNode
from django.db.models.fields import FieldDoesNotExist
-from django.db.models.query_utils import InvalidQuery
from django.db.models.sql import aggregates as base_aggregates_module
-from django.db.models.sql.constants import *
+from django.db.models.sql.constants import (QUERY_TERMS, LOOKUP_SEP, ORDER_DIR,
+ SINGLE, ORDER_PATTERN, JoinInfo)
from django.db.models.sql.datastructures import EmptyResultSet, Empty, MultiJoin
from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.where import (WhereNode, Constraint, EverythingNode,
@@ -28,6 +28,7 @@
__all__ = ['Query', 'RawQuery']
+
class RawQuery(object):
"""
A single raw SQL query
@@ -71,7 +71,8 @@ def __bool__(self):
return True
__nonzero__ = __bool__ # Python 2
- def _management_form(self):
+ @property
+ def management_form(self):
"""Returns the ManagementForm instance for this FormSet."""
if self.is_bound:
form = ManagementForm(self.data, auto_id=self.auto_id, prefix=self.prefix)
@@ -84,7 +85,6 @@ def _management_form(self):
MAX_NUM_FORM_COUNT: self.max_num
})
return form
- management_form = property(_management_form)
def total_form_count(self):
"""Returns the total number of forms in this FormSet."""
@@ -140,17 +140,18 @@ def _construct_form(self, i, **kwargs):
self.add_fields(form, i)
return form
- def _get_initial_forms(self):
+ @property
+ def initial_forms(self):
"""Return a list of all the initial forms in this formset."""
return self.forms[:self.initial_form_count()]
- initial_forms = property(_get_initial_forms)
- def _get_extra_forms(self):
+ @property
+ def extra_forms(self):
"""Return a list of all the extra forms in this formset."""
return self.forms[self.initial_form_count():]
- extra_forms = property(_get_extra_forms)
- def _get_empty_form(self, **kwargs):
+ @property
+ def empty_form(self, **kwargs):
defaults = {
'auto_id': self.auto_id,
'prefix': self.add_prefix('__prefix__'),
@@ -160,19 +161,19 @@ def _get_empty_form(self, **kwargs):
form = self.form(**defaults)
self.add_fields(form, None)
return form
- empty_form = property(_get_empty_form)
# Maybe this should just go away?
- def _get_cleaned_data(self):
+ @property
+ def cleaned_data(self):
"""
Returns a list of form.cleaned_data dicts for every form in self.forms.
"""
if not self.is_valid():
raise AttributeError("'%s' object has no attribute 'cleaned_data'" % self.__class__.__name__)
return [form.cleaned_data for form in self.forms]
- cleaned_data = property(_get_cleaned_data)
- def _get_deleted_forms(self):
+ @property
+ def deleted_forms(self):
"""
Returns a list of forms that have been marked for deletion. Raises an
AttributeError if deletion is not allowed.
@@ -191,9 +192,9 @@ def _get_deleted_forms(self):
if self._should_delete_form(form):
self._deleted_form_indexes.append(i)
return [self.forms[i] for i in self._deleted_form_indexes]
- deleted_forms = property(_get_deleted_forms)
- def _get_ordered_forms(self):
+ @property
+ def ordered_forms(self):
"""
Returns a list of form in the order specified by the incoming data.
Raises an AttributeError if ordering is not allowed.
@@ -228,7 +229,6 @@ def compare_ordering_key(k):
# Return a list of form.cleaned_data dicts in the order specified by
# the form data.
return [self.forms[i[0]] for i in self._ordering]
- ordered_forms = property(_get_ordered_forms)
@classmethod
def get_default_prefix(cls):
@@ -244,14 +244,14 @@ def non_form_errors(self):
return self._non_form_errors
return self.error_class()
- def _get_errors(self):
+ @property
+ def errors(self):
"""
Returns a list of form.errors for every form in self.forms.
"""
if self._errors is None:
self.full_clean()
return self._errors
- errors = property(_get_errors)
def _should_delete_form(self, form):
"""
@@ -332,14 +332,14 @@ def is_multipart(self):
"""
return self.forms and self.forms[0].is_multipart()
- def _get_media(self):
+ @property
+ def media(self):
# All the forms on a FormSet are the same, so you only need to
# interrogate the first form for media.
if self.forms:
return self.forms[0].media
else:
return Media()
- media = property(_get_media)
def as_table(self):
"Returns this formset rendered as HTML <tr>s -- excluding the <table></table>."
@@ -507,11 +507,7 @@ def __init__(self, attrs=None, check_test=None):
def render(self, name, value, attrs=None):
final_attrs = self.build_attrs(attrs, type='checkbox', name=name)
- try:
- result = self.check_test(value)
- except: # Silently catch exceptions
- result = False
- if result:
+ if self.check_test(value):
final_attrs['checked'] = 'checked'
if not (value is True or value is False or value is None or value == ''):
# Only add the 'value' attribute if a value is non-empty.
@@ -525,7 +521,7 @@ def value_from_datadict(self, data, files, name):
return False
value = data.get(name)
# Translate true and false strings to boolean values.
- values = {'true': True, 'false': False}
+ values = {'true': True, 'false': False}
if isinstance(value, six.string_types):
value = values.get(value.lower(), value)
return value
@@ -68,11 +68,10 @@ def __init__(self, META, input_data, upload_handlers, encoding=None):
if not boundary or not cgi.valid_boundary(boundary):
raise MultiPartParserError('Invalid boundary in multipart: %s' % boundary)
-
# Content-Length should contain the length of the body we are about
# to receive.
try:
- content_length = int(META.get('HTTP_CONTENT_LENGTH', META.get('CONTENT_LENGTH',0)))
+ content_length = int(META.get('HTTP_CONTENT_LENGTH', META.get('CONTENT_LENGTH', 0)))
except (ValueError, TypeError):
content_length = 0
@@ -178,7 +177,7 @@ def parse(self):
content_type = meta_data.get('content-type', ('',))[0].strip()
try:
- charset = meta_data.get('content-type', (0,{}))[1].get('charset', None)
+ charset = meta_data.get('content-type', (0, {}))[1].get('charset', None)
except:
charset = None
Oops, something went wrong.

0 comments on commit 828d691

Please sign in to comment.