Add web based python shell to Melange.
[Melange.git] / app / gae_django.py
blob5455a3d1d3dd61f4a7afa1fddc7928eb6901751f
1 #!/usr/bin/python2.5
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.
18 """
20 import logging
21 import os
22 import sys
24 __authors__ = [
25 # alphabetical order by last name, please
26 '"Pawel Solyga" <pawel.solyga@gmail.com>',
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]
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__)))
38 sys.path.insert(0, os.path.abspath('django.zip'))
40 # Force Django to reload its settings.
41 from django.conf import settings
42 settings._target = None
44 # Must set this env var before importing any part of Django
45 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
47 import django.core.signals
48 import django.db
50 # Log errors.
51 def log_exception(*args, **kwds):
52 """Function used for logging exceptions.
53 """
54 logging.exception('Exception in request:')
56 # Log all exceptions detected by Django.
57 django.core.signals.got_request_exception.connect(log_exception)
59 # Unregister the rollback event handler.
60 django.core.signals.got_request_exception.disconnect(
61 django.db._rollback_on_exception)