app/gae_django.py
changeset 2335 366e64ecba91
child 2414 a95ba3595554
equal deleted inserted replaced
2334:6f5f6a9965c6 2335:366e64ecba91
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2008 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """Module containing Melange Django 1.0+ configuration for Google App Engine.
       
    18 """
       
    19 
       
    20 import logging
       
    21 import os
       
    22 import sys
       
    23 
       
    24 __authors__ = [
       
    25   # alphabetical order by last name, please
       
    26   '"Pawel Solyga" <pawel.solyga@gmail.com>',
       
    27   ]
       
    28 
       
    29 
       
    30 # Remove the standard version of Django.
       
    31 for k in [k for k in sys.modules if k.startswith('django')]:
       
    32   del sys.modules[k]
       
    33 
       
    34 # Force sys.path to have our own directory first, in case we want to import
       
    35 # from it. This lets us replace the built-in Django
       
    36 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
       
    37 
       
    38 sys.path.insert(0, os.path.abspath('django.zip'))
       
    39 
       
    40 # Force Django to reload its settings.
       
    41 from django.conf import settings
       
    42 settings._target = None
       
    43 
       
    44 # Must set this env var before importing any part of Django
       
    45 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
       
    46 
       
    47 import django.core.signals
       
    48 import django.db
       
    49 
       
    50 # Log errors.
       
    51 def log_exception(*args, **kwds):
       
    52   """Function used for logging exceptions.
       
    53   """
       
    54   logging.exception('Exception in request:')
       
    55 
       
    56 # Log all exceptions detected by Django.
       
    57 django.core.signals.got_request_exception.connect(log_exception)
       
    58 
       
    59 # Unregister the rollback event handler.
       
    60 django.core.signals.got_request_exception.disconnect(
       
    61     django.db._rollback_on_exception)