Changeset 7979 for django/branches/gis/django/core
- Timestamp:
- 07/19/08 08:30:47 (6 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/core/handlers/base.py (modified) (2 diffs)
- django/branches/gis/django/core/management/validation.py (modified) (3 diffs)
- django/branches/gis/django/core/serializers/base.py (modified) (2 diffs)
- django/branches/gis/django/core/serializers/json.py (modified) (3 diffs)
- django/branches/gis/django/core/validators.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7917 to /django/trunk:1-7978
django/branches/gis/django/core/handlers/base.py
r7918 r7979 61 61 "Returns an HttpResponse object for the given HttpRequest" 62 62 from django.core import exceptions, urlresolvers 63 from django.core.mail import mail_admins64 63 from django.conf import settings 65 64 … … 123 122 if settings.DEBUG_PROPAGATE_EXCEPTIONS: 124 123 raise 125 elif settings.DEBUG: 126 from django.views import debug 127 return debug.technical_500_response(request, *exc_info) 128 else: 129 # When DEBUG is False, send an error message to the admins. 130 subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path) 131 try: 132 request_repr = repr(request) 133 except: 134 request_repr = "Request repr() unavailable" 135 message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr) 136 mail_admins(subject, message, fail_silently=True) 137 # Return an HttpResponse that displays a friendly error message. 138 callback, param_dict = resolver.resolve500() 139 return callback(request, **param_dict) 124 return self.handle_uncaught_exception(request, resolver, exc_info) 125 126 def handle_uncaught_exception(self, request, resolver, exc_info): 127 """ 128 Processing for any otherwise uncaught exceptions (those that will 129 generate HTTP 500 responses). Can be overridden by subclasses who want 130 customised 500 handling. 131 132 Be *very* careful when overriding this because the error could be 133 caused by anything, so assuming something like the database is always 134 available would be an error. 135 """ 136 from django.conf import settings 137 from django.core.mail import mail_admins 138 139 if settings.DEBUG: 140 from django.views import debug 141 return debug.technical_500_response(request, *exc_info) 142 143 # When DEBUG is False, send an error message to the admins. 144 subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path) 145 try: 146 request_repr = repr(request) 147 except: 148 request_repr = "Request repr() unavailable" 149 message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr) 150 mail_admins(subject, message, fail_silently=True) 151 # Return an HttpResponse that displays a friendly error message. 152 callback, param_dict = resolver.resolve500() 153 return callback(request, **param_dict) 140 154 141 155 def _get_traceback(self, exc_info=None): django/branches/gis/django/core/management/validation.py
r7482 r7979 52 52 except ImportError: 53 53 e.add(opts, '"%s": To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ .' % f.name) 54 if f.prepopulate_from is not None and type(f.prepopulate_from) not in (list, tuple):55 e.add(opts, '"%s": prepopulate_from should be a list or tuple.' % f.name)56 54 if f.choices: 57 55 if isinstance(f.choices, basestring) or not is_iterable(f.choices): … … 146 144 e.add(opts, "Reverse query name for m2m field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'." % (f.name, rel_opts.object_name, r.get_accessor_name(), f.name)) 147 145 148 # Check admin attribute.149 if opts.admin is not None:150 if not isinstance(opts.admin, models.AdminOptions):151 e.add(opts, '"admin" attribute, if given, must be set to a models.AdminOptions() instance.')152 else:153 # list_display154 if not isinstance(opts.admin.list_display, (list, tuple)):155 e.add(opts, '"admin.list_display", if given, must be set to a list or tuple.')156 else:157 for fn in opts.admin.list_display:158 try:159 f = opts.get_field(fn)160 except models.FieldDoesNotExist:161 if not hasattr(cls, fn):162 e.add(opts, '"admin.list_display" refers to %r, which isn\'t an attribute, method or property.' % fn)163 else:164 if isinstance(f, models.ManyToManyField):165 e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn)166 # list_display_links167 if opts.admin.list_display_links and not opts.admin.list_display:168 e.add(opts, '"admin.list_display" must be defined for "admin.list_display_links" to be used.')169 if not isinstance(opts.admin.list_display_links, (list, tuple)):170 e.add(opts, '"admin.list_display_links", if given, must be set to a list or tuple.')171 else:172 for fn in opts.admin.list_display_links:173 try:174 f = opts.get_field(fn)175 except models.FieldDoesNotExist:176 if not hasattr(cls, fn):177 e.add(opts, '"admin.list_display_links" refers to %r, which isn\'t an attribute, method or property.' % fn)178 if fn not in opts.admin.list_display:179 e.add(opts, '"admin.list_display_links" refers to %r, which is not defined in "admin.list_display".' % fn)180 # list_filter181 if not isinstance(opts.admin.list_filter, (list, tuple)):182 e.add(opts, '"admin.list_filter", if given, must be set to a list or tuple.')183 else:184 for fn in opts.admin.list_filter:185 try:186 f = opts.get_field(fn)187 except models.FieldDoesNotExist:188 e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn)189 # date_hierarchy190 if opts.admin.date_hierarchy:191 try:192 f = opts.get_field(opts.admin.date_hierarchy)193 except models.FieldDoesNotExist:194 e.add(opts, '"admin.date_hierarchy" refers to %r, which isn\'t a field.' % opts.admin.date_hierarchy)195 196 146 # Check ordering attribute. 197 147 if opts.ordering: … … 211 161 e.add(opts, '"ordering" refers to "%s", a field that doesn\'t exist.' % field_name) 212 162 213 # Check core=True, if needed.214 for related in opts.get_followed_related_objects():215 if not related.edit_inline:216 continue217 try:218 for f in related.opts.fields:219 if f.core:220 raise StopIteration221 e.add(related.opts, "At least one field in %s should have core=True, because it's being edited inline by %s.%s." % (related.opts.object_name, opts.module_name, opts.object_name))222 except StopIteration:223 pass224 225 163 # Check unique_together. 226 164 for ut in opts.unique_together: django/branches/gis/django/core/serializers/base.py
r7642 r7979 9 9 from django.db import models 10 10 from django.utils.encoding import smart_str, smart_unicode 11 from django.utils import datetime_safe 11 12 12 13 class SerializationError(Exception): … … 60 61 """ 61 62 if isinstance(field, models.DateTimeField): 62 value = getattr(obj, field.name).strftime("%Y-%m-%d %H:%M:%S") 63 d = datetime_safe.new_datetime(getattr(obj, field.name)) 64 value = d.strftime("%Y-%m-%d %H:%M:%S") 63 65 else: 64 66 value = field.flatten_data(follow=None, obj=obj).get(field.name, "") django/branches/gis/django/core/serializers/json.py
r7176 r7979 7 7 from django.core.serializers.python import Serializer as PythonSerializer 8 8 from django.core.serializers.python import Deserializer as PythonDeserializer 9 from django.utils import datetime_safe 9 10 try: 10 11 from cStringIO import StringIO … … 21 22 """ 22 23 internal_use_only = False 23 24 24 25 def end_serialization(self): 25 26 self.options.pop('stream', None) … … 52 53 def default(self, o): 53 54 if isinstance(o, datetime.datetime): 54 return o.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT)) 55 d = datetime_safe.new_datetime(o) 56 return d.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT)) 55 57 elif isinstance(o, datetime.date): 56 return o.strftime(self.DATE_FORMAT) 58 d = datetime_safe.new_date(o) 59 return d.strftime(self.DATE_FORMAT) 57 60 elif isinstance(o, datetime.time): 58 61 return o.strftime(self.TIME_FORMAT) django/branches/gis/django/core/validators.py
r7918 r7979 142 142 # produces much friendlier error messages. 143 143 year, month, day = map(int, date_string.split('-')) 144 # This check is needed because strftime is used when saving the date145 # value to the database, and strftime requires that the year be >=1900.146 if year < 1900:147 raise ValidationError, _('Year must be 1900 or later.')148 144 try: 149 145 date(year, month, day) … … 408 404 Usage: If you create an instance of the IsPowerOf validator: 409 405 v = IsAPowerOf(2) 410 406 411 407 The following calls will succeed: 412 v(4, None) 408 v(4, None) 413 409 v(8, None) 414 410 v(16, None) 415 411 416 412 But this call: 417 413 v(17, None)
