diff options
Diffstat (limited to 'django/core')
-rw-r--r-- | django/core/cache/backends/base.py | 2 | ||||
-rw-r--r-- | django/core/context_processors.py | 8 | ||||
-rw-r--r-- | django/core/handlers/base.py | 2 | ||||
-rw-r--r-- | django/core/management.py | 62 | ||||
-rw-r--r-- | django/core/paginator.py | 2 | ||||
-rw-r--r-- | django/core/servers/basehttp.py | 8 | ||||
-rw-r--r-- | django/core/urlresolvers.py | 2 | ||||
-rw-r--r-- | django/core/validators.py | 33 |
8 files changed, 64 insertions, 55 deletions
diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py index ad8941204e..ef5f6a6b3e 100644 --- a/django/core/cache/backends/base.py +++ b/django/core/cache/backends/base.py @@ -5,7 +5,7 @@ from django.core.exceptions import ImproperlyConfigured class InvalidCacheBackendError(ImproperlyConfigured): pass -class BaseCache: +class BaseCache(object): def __init__(self, params): timeout = params.get('timeout', 300) try: diff --git a/django/core/context_processors.py b/django/core/context_processors.py index 1ab0768776..2ae9a6d972 100644 --- a/django/core/context_processors.py +++ b/django/core/context_processors.py @@ -36,6 +36,10 @@ def i18n(request): context_extras['LANGUAGE_CODE'] = request.LANGUAGE_CODE else: context_extras['LANGUAGE_CODE'] = settings.LANGUAGE_CODE + + from django.utils import translation + context_extras['LANGUAGE_BIDI'] = translation.get_language_bidi() + return context_extras def request(request): @@ -44,7 +48,7 @@ def request(request): # PermWrapper and PermLookupDict proxy the permissions system into objects that # the template system can understand. -class PermLookupDict: +class PermLookupDict(object): def __init__(self, user, module_name): self.user, self.module_name = user, module_name def __repr__(self): @@ -54,7 +58,7 @@ class PermLookupDict: def __nonzero__(self): return self.user.has_module_perms(self.module_name) -class PermWrapper: +class PermWrapper(object): def __init__(self, user): self.user = user def __getitem__(self, module_name): diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 20f0d04669..c25ff2b14e 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -3,7 +3,7 @@ from django.dispatch import dispatcher from django import http import sys -class BaseHandler: +class BaseHandler(object): def __init__(self): self._request_middleware = self._view_middleware = self._response_middleware = self._exception_middleware = None diff --git a/django/core/management.py b/django/core/management.py index 931372cc5e..61213d0965 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -211,35 +211,38 @@ def _get_sql_for_pending_references(klass, pending_references): def _get_many_to_many_sql_for_model(klass): from django.db import backend, get_creation_module + from django.db.models import GenericRel + data_types = get_creation_module().DATA_TYPES opts = klass._meta final_output = [] for f in opts.many_to_many: - table_output = [style.SQL_KEYWORD('CREATE TABLE') + ' ' + \ - style.SQL_TABLE(backend.quote_name(f.m2m_db_table())) + ' ('] - table_output.append(' %s %s %s,' % \ - (style.SQL_FIELD(backend.quote_name('id')), - style.SQL_COLTYPE(data_types['AutoField']), - style.SQL_KEYWORD('NOT NULL PRIMARY KEY'))) - table_output.append(' %s %s %s %s (%s),' % \ - (style.SQL_FIELD(backend.quote_name(f.m2m_column_name())), - style.SQL_COLTYPE(data_types[get_rel_data_type(opts.pk)] % opts.pk.__dict__), - style.SQL_KEYWORD('NOT NULL REFERENCES'), - style.SQL_TABLE(backend.quote_name(opts.db_table)), - style.SQL_FIELD(backend.quote_name(opts.pk.column)))) - table_output.append(' %s %s %s %s (%s),' % \ - (style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name())), - style.SQL_COLTYPE(data_types[get_rel_data_type(f.rel.to._meta.pk)] % f.rel.to._meta.pk.__dict__), - style.SQL_KEYWORD('NOT NULL REFERENCES'), - style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)), - style.SQL_FIELD(backend.quote_name(f.rel.to._meta.pk.column)))) - table_output.append(' %s (%s, %s)' % \ - (style.SQL_KEYWORD('UNIQUE'), - style.SQL_FIELD(backend.quote_name(f.m2m_column_name())), - style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name())))) - table_output.append(');') - final_output.append('\n'.join(table_output)) + if not isinstance(f.rel, GenericRel): + table_output = [style.SQL_KEYWORD('CREATE TABLE') + ' ' + \ + style.SQL_TABLE(backend.quote_name(f.m2m_db_table())) + ' ('] + table_output.append(' %s %s %s,' % \ + (style.SQL_FIELD(backend.quote_name('id')), + style.SQL_COLTYPE(data_types['AutoField']), + style.SQL_KEYWORD('NOT NULL PRIMARY KEY'))) + table_output.append(' %s %s %s %s (%s),' % \ + (style.SQL_FIELD(backend.quote_name(f.m2m_column_name())), + style.SQL_COLTYPE(data_types[get_rel_data_type(opts.pk)] % opts.pk.__dict__), + style.SQL_KEYWORD('NOT NULL REFERENCES'), + style.SQL_TABLE(backend.quote_name(opts.db_table)), + style.SQL_FIELD(backend.quote_name(opts.pk.column)))) + table_output.append(' %s %s %s %s (%s),' % \ + (style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name())), + style.SQL_COLTYPE(data_types[get_rel_data_type(f.rel.to._meta.pk)] % f.rel.to._meta.pk.__dict__), + style.SQL_KEYWORD('NOT NULL REFERENCES'), + style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)), + style.SQL_FIELD(backend.quote_name(f.rel.to._meta.pk.column)))) + table_output.append(' %s (%s, %s)' % \ + (style.SQL_KEYWORD('UNIQUE'), + style.SQL_FIELD(backend.quote_name(f.m2m_column_name())), + style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name())))) + table_output.append(');') + final_output.append('\n'.join(table_output)) return final_output def get_sql_delete(app): @@ -815,10 +818,8 @@ def get_validation_errors(outfile, app=None): # Do field-specific validation. for f in opts.fields: - # Check for deprecated args - dep_args = getattr(f, 'deprecated_args', None) - if dep_args: - e.add(opts, "'%s' Initialized with deprecated args:%s" % (f.name, ",".join(dep_args))) + if f.name == 'id' and not f.primary_key and opts.pk.name == 'id': + e.add(opts, '"%s": You can\'t use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.' % f.name) if isinstance(f, models.CharField) and f.maxlength in (None, 0): e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name) if isinstance(f, models.FloatField): @@ -836,8 +837,8 @@ def get_validation_errors(outfile, app=None): if f.prepopulate_from is not None and type(f.prepopulate_from) not in (list, tuple): e.add(opts, '"%s": prepopulate_from should be a list or tuple.' % f.name) if f.choices: - if not type(f.choices) in (tuple, list): - e.add(opts, '"%s": "choices" should be either a tuple or list.' % f.name) + if not hasattr(f.choices, '__iter__'): + e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name) else: for c in f.choices: if not type(c) in (tuple, list) or len(c) != 2: @@ -923,6 +924,7 @@ def get_validation_errors(outfile, app=None): field_name = field_name[1:] if opts.order_with_respect_to and field_name == '_order': continue + if '.' in field_name: continue # Skip ordering in the format 'table.field'. try: opts.get_field(field_name, many_to_many=False) except models.FieldDoesNotExist: diff --git a/django/core/paginator.py b/django/core/paginator.py index f4941cb678..195ad1009e 100644 --- a/django/core/paginator.py +++ b/django/core/paginator.py @@ -4,7 +4,7 @@ from math import ceil class InvalidPage(Exception): pass -class ObjectPaginator: +class ObjectPaginator(object): """ This class makes pagination easy. Feed it a QuerySet, plus the number of objects you want on each page. Then read the hits and pages properties to diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py index 5772912031..259a931594 100644 --- a/django/core/servers/basehttp.py +++ b/django/core/servers/basehttp.py @@ -21,7 +21,7 @@ software_version = server_version + ' ' + sys_version class WSGIServerException(Exception): pass -class FileWrapper: +class FileWrapper(object): """Wrapper to convert file-like objects to iterables""" def __init__(self, filelike, blksize=8192): @@ -63,7 +63,7 @@ def _formatparam(param, value=None, quote=1): else: return param -class Headers: +class Headers(object): """Manage a collection of HTTP response headers""" def __init__(self,headers): if type(headers) is not ListType: @@ -218,7 +218,7 @@ def is_hop_by_hop(header_name): """Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header""" return _hoppish(header_name.lower()) -class ServerHandler: +class ServerHandler(object): """Manage the invocation of a WSGI application""" # Configuration parameters; can override per-subclass or per-instance @@ -591,7 +591,7 @@ class WSGIRequestHandler(BaseHTTPRequestHandler): return sys.stderr.write("[%s] %s\n" % (self.log_date_time_string(), format % args)) -class AdminMediaHandler: +class AdminMediaHandler(object): """ WSGI middleware that intercepts calls to the admin media directory, as defined by the ADMIN_MEDIA_PREFIX setting, and serves those images. diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index 91e999f802..a1661a2ecd 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -83,7 +83,7 @@ class MatchChecker(object): raise NoReverseMatch("Value %r didn't match regular expression %r" % (value, test_regex)) return str(value) # TODO: Unicode? -class RegexURLPattern: +class RegexURLPattern(object): def __init__(self, regex, callback, default_args=None): # regex is a string representing a regular expression. # callback is something like 'foo.views.news.stories.story_detail', diff --git a/django/core/validators.py b/django/core/validators.py index a2e9bfaf89..f98589578e 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -237,7 +237,7 @@ def hasNoProfanities(field_data, all_data): "Watch your mouth! The words %s are not allowed here.", plural) % \ get_text_list(['"%s%s%s"' % (i[0], '-'*(len(i)-2), i[-1]) for i in words_seen], 'and') -class AlwaysMatchesOtherField: +class AlwaysMatchesOtherField(object): def __init__(self, other_field_name, error_message=None): self.other = other_field_name self.error_message = error_message or lazy_inter(gettext_lazy("This field must match the '%s' field."), self.other) @@ -247,7 +247,7 @@ class AlwaysMatchesOtherField: if field_data != all_data[self.other]: raise ValidationError, self.error_message -class ValidateIfOtherFieldEquals: +class ValidateIfOtherFieldEquals(object): def __init__(self, other_field, other_value, validator_list): self.other_field, self.other_value = other_field, other_value self.validator_list = validator_list @@ -258,7 +258,7 @@ class ValidateIfOtherFieldEquals: for v in self.validator_list: v(field_data, all_data) -class RequiredIfOtherFieldNotGiven: +class RequiredIfOtherFieldNotGiven(object): def __init__(self, other_field_name, error_message=gettext_lazy("Please enter something for at least one field.")): self.other, self.error_message = other_field_name, error_message self.always_test = True @@ -267,7 +267,7 @@ class RequiredIfOtherFieldNotGiven: if not all_data.get(self.other, False) and not field_data: raise ValidationError, self.error_message -class RequiredIfOtherFieldsGiven: +class RequiredIfOtherFieldsGiven(object): def __init__(self, other_field_names, error_message=gettext_lazy("Please enter both fields or leave them both empty.")): self.other, self.error_message = other_field_names, error_message self.always_test = True @@ -282,7 +282,7 @@ class RequiredIfOtherFieldGiven(RequiredIfOtherFieldsGiven): def __init__(self, other_field_name, error_message=gettext_lazy("Please enter both fields or leave them both empty.")): RequiredIfOtherFieldsGiven.__init__(self, [other_field_name], error_message) -class RequiredIfOtherFieldEquals: +class RequiredIfOtherFieldEquals(object): def __init__(self, other_field, other_value, error_message=None): self.other_field = other_field self.other_value = other_value @@ -294,7 +294,7 @@ class RequiredIfOtherFieldEquals: if all_data.has_key(self.other_field) and all_data[self.other_field] == self.other_value and not field_data: raise ValidationError(self.error_message) -class RequiredIfOtherFieldDoesNotEqual: +class RequiredIfOtherFieldDoesNotEqual(object): def __init__(self, other_field, other_value, error_message=None): self.other_field = other_field self.other_value = other_value @@ -306,7 +306,7 @@ class RequiredIfOtherFieldDoesNotEqual: if all_data.has_key(self.other_field) and all_data[self.other_field] != self.other_value and not field_data: raise ValidationError(self.error_message) -class IsLessThanOtherField: +class IsLessThanOtherField(object): def __init__(self, other_field_name, error_message): self.other, self.error_message = other_field_name, error_message @@ -314,7 +314,7 @@ class IsLessThanOtherField: if field_data > all_data[self.other]: raise ValidationError, self.error_message -class UniqueAmongstFieldsWithPrefix: +class UniqueAmongstFieldsWithPrefix(object): def __init__(self, field_name, prefix, error_message): self.field_name, self.prefix = field_name, prefix self.error_message = error_message or gettext_lazy("Duplicate values are not allowed.") @@ -324,7 +324,7 @@ class UniqueAmongstFieldsWithPrefix: if field_name != self.field_name and value == field_data: raise ValidationError, self.error_message -class IsAPowerOf: +class IsAPowerOf(object): """ >>> v = IsAPowerOf(2) >>> v(4, None) @@ -342,7 +342,7 @@ class IsAPowerOf: if val != int(val): raise ValidationError, gettext("This value must be a power of %s.") % self.power_of -class IsValidFloat: +class IsValidFloat(object): def __init__(self, max_digits, decimal_places): self.max_digits, self.decimal_places = max_digits, decimal_places @@ -355,11 +355,14 @@ class IsValidFloat: if len(data) > (self.max_digits + 1): raise ValidationError, ngettext("Please enter a valid decimal number with at most %s total digit.", "Please enter a valid decimal number with at most %s total digits.", self.max_digits) % self.max_digits + if (not '.' in data and len(data) > (self.max_digits - self.decimal_places)) or ('.' in data and len(data) > (self.max_digits - (self.decimal_places - len(data.split('.')[1])) + 1)): + raise ValidationError, ngettext( "Please enter a valid decimal number with a whole part of at most %s digit.", + "Please enter a valid decimal number with a whole part of at most %s digits.", str(self.max_digits-self.decimal_places)) % str(self.max_digits-self.decimal_places) if '.' in data and len(data.split('.')[1]) > self.decimal_places: raise ValidationError, ngettext("Please enter a valid decimal number with at most %s decimal place.", "Please enter a valid decimal number with at most %s decimal places.", self.decimal_places) % self.decimal_places -class HasAllowableSize: +class HasAllowableSize(object): """ Checks that the file-upload field data is a certain size. min_size and max_size are measurements in bytes. @@ -379,7 +382,7 @@ class HasAllowableSize: if self.max_size is not None and len(content) > self.max_size: raise ValidationError, self.max_error_message -class MatchesRegularExpression: +class MatchesRegularExpression(object): """ Checks that the field matches the given regular-expression. The regex should be in string format, not already compiled. @@ -392,7 +395,7 @@ class MatchesRegularExpression: if not self.regexp.search(field_data): raise ValidationError(self.error_message) -class AnyValidator: +class AnyValidator(object): """ This validator tries all given validators. If any one of them succeeds, validation passes. If none of them succeeds, the given message is thrown @@ -416,7 +419,7 @@ class AnyValidator: pass raise ValidationError(self.error_message) -class URLMimeTypeCheck: +class URLMimeTypeCheck(object): "Checks that the provided URL points to a document with a listed mime type" class CouldNotRetrieve(ValidationError): pass @@ -441,7 +444,7 @@ class URLMimeTypeCheck: raise URLMimeTypeCheck.InvalidContentType, gettext("The URL %(url)s returned the invalid Content-Type header '%(contenttype)s'.") % { 'url': field_data, 'contenttype': content_type} -class RelaxNGCompact: +class RelaxNGCompact(object): "Validate against a Relax NG compact schema" def __init__(self, schema_path, additional_root_element=None): self.schema_path = schema_path |