Django

Code

Show
Ignore:
Timestamp:
07/19/08 08:30:47 (6 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7921,7926-7928,7938-7941,7945-7947,7949-7950,7952,7955-7956,7961,7964-7968,7970-7978 via svnmerge from trunk.

This includes the newforms-admin branch, and thus is backwards-incompatible. The geographic admin is _not_ in this changeset, and is forthcoming.

Files:

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  
    6161        "Returns an HttpResponse object for the given HttpRequest" 
    6262        from django.core import exceptions, urlresolvers 
    63         from django.core.mail import mail_admins 
    6463        from django.conf import settings 
    6564 
     
    123122            if settings.DEBUG_PROPAGATE_EXCEPTIONS: 
    124123                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) 
    140154 
    141155    def _get_traceback(self, exc_info=None): 
  • django/branches/gis/django/core/management/validation.py

    r7482 r7979  
    5252                except ImportError: 
    5353                    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) 
    5654            if f.choices: 
    5755                if isinstance(f.choices, basestring) or not is_iterable(f.choices): 
     
    146144                        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)) 
    147145 
    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_display 
    154                 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_links 
    167                 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_filter 
    181                 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_hierarchy 
    190                 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  
    196146        # Check ordering attribute. 
    197147        if opts.ordering: 
     
    211161                    e.add(opts, '"ordering" refers to "%s", a field that doesn\'t exist.' % field_name) 
    212162 
    213         # Check core=True, if needed. 
    214         for related in opts.get_followed_related_objects(): 
    215             if not related.edit_inline: 
    216                 continue 
    217             try: 
    218                 for f in related.opts.fields: 
    219                     if f.core: 
    220                         raise StopIteration 
    221                 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                 pass 
    224  
    225163        # Check unique_together. 
    226164        for ut in opts.unique_together: 
  • django/branches/gis/django/core/serializers/base.py

    r7642 r7979  
    99from django.db import models 
    1010from django.utils.encoding import smart_str, smart_unicode 
     11from django.utils import datetime_safe 
    1112 
    1213class SerializationError(Exception): 
     
    6061        """ 
    6162        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") 
    6365        else: 
    6466            value = field.flatten_data(follow=None, obj=obj).get(field.name, "") 
  • django/branches/gis/django/core/serializers/json.py

    r7176 r7979  
    77from django.core.serializers.python import Serializer as PythonSerializer 
    88from django.core.serializers.python import Deserializer as PythonDeserializer 
     9from django.utils import datetime_safe 
    910try: 
    1011    from cStringIO import StringIO 
     
    2122    """ 
    2223    internal_use_only = False 
    23      
     24 
    2425    def end_serialization(self): 
    2526        self.options.pop('stream', None) 
     
    5253    def default(self, o): 
    5354        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)) 
    5557        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) 
    5760        elif isinstance(o, datetime.time): 
    5861            return o.strftime(self.TIME_FORMAT) 
  • django/branches/gis/django/core/validators.py

    r7918 r7979  
    142142    # produces much friendlier error messages. 
    143143    year, month, day = map(int, date_string.split('-')) 
    144     # This check is needed because strftime is used when saving the date 
    145     # 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.') 
    148144    try: 
    149145        date(year, month, day) 
     
    408404    Usage: If you create an instance of the IsPowerOf validator: 
    409405        v = IsAPowerOf(2) 
    410      
     406 
    411407    The following calls will succeed: 
    412         v(4, None)  
     408        v(4, None) 
    413409        v(8, None) 
    414410        v(16, None) 
    415      
     411 
    416412    But this call: 
    417413        v(17, None)