3 # Copyright 2008 the Melange authors.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 """Module containing Melange Django 1.0+ configuration for Google App Engine.
25 # alphabetical order by last name, please
26 '"Pawel Solyga" <pawel.solyga@gmail.com>',
30 if os
.environ
['SERVER_SOFTWARE'].startswith('Dev'):
32 # Remove the standard version of Django.
33 for k
in [k
for k
in sys
.modules
if k
.startswith('django')]:
36 # Force sys.path to have our own directory first, in case we want to import
37 # from it. This lets us replace the built-in Django
38 sys
.path
.insert(0, os
.path
.abspath(os
.path
.dirname(__file__
)))
39 sys
.path
.insert(0, os
.path
.abspath('django'))
40 sys
.path
.insert(0, os
.path
.abspath('django.zip'))
43 # Declare the Django version we need.
44 from google
.appengine
.dist
import use_library
45 use_library('django', '1.0')
47 # Force Django to reload its settings.
48 from django
.conf
import settings
49 settings
._target
= None
51 # Must set this env var before importing any part of Django
52 os
.environ
['DJANGO_SETTINGS_MODULE'] = 'settings'
54 import django
.core
.signals
58 def log_exception(*args
, **kwds
):
59 """Function used for logging exceptions.
61 logging
.exception('Exception in request:')
63 # Log all exceptions detected by Django.
64 django
.core
.signals
.got_request_exception
.connect(log_exception
)
66 # Unregister the rollback event handler.
67 django
.core
.signals
.got_request_exception
.disconnect(
68 django
.db
._rollback
_on
_exception
)