| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # | 2 # |
| 3 # Copyright 2008 Google Inc. | 3 # Copyright 2008 Google Inc. |
| 4 # | 4 # |
| 5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 # you may not use this file except in compliance with 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 | 7 # You may obtain a copy of the License at |
| 8 # | 8 # |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 # | 10 # |
| (...skipping 256 matching lines...) Show 10 above Show 10 below |
| 267 for var in ["NAME", "USER", "PASSWORD", "HOST", "PORT"]: | 267 for var in ["NAME", "USER", "PASSWORD", "HOST", "PORT"]: |
| 268 val = getattr(settings, "DATABASE_%s" % var, "") | 268 val = getattr(settings, "DATABASE_%s" % var, "") |
| 269 if val: | 269 if val: |
| 270 setattr(settings, "DATABASE_%s" % var, "") | 270 setattr(settings, "DATABASE_%s" % var, "") |
| 271 logging.warn("DATABASE_%s should be blank. Value overriden!") | 271 logging.warn("DATABASE_%s should be blank. Value overriden!") |
| 272 | 272 |
| 273 # Remove incompatible middleware modules. | 273 # Remove incompatible middleware modules. |
| 274 mw_mods = list(getattr(settings, "MIDDLEWARE_CLASSES", ())) | 274 mw_mods = list(getattr(settings, "MIDDLEWARE_CLASSES", ())) |
| 275 disallowed_middleware_mods = ( | 275 disallowed_middleware_mods = ( |
| 276 'django.contrib.sessions.middleware.SessionMiddleware', | 276 'django.contrib.sessions.middleware.SessionMiddleware', |
| 277 'django.contrib.auth.middleware.AuthenticationMiddleware', | |
| 278 'django.middleware.doc.XViewMiddleware',) | 277 'django.middleware.doc.XViewMiddleware',) |
| 279 for modname in mw_mods[:]: | 278 for modname in mw_mods[:]: |
| 280 if modname in disallowed_middleware_mods: | 279 if modname in disallowed_middleware_mods: |
| 281 # Currently only the CommonMiddleware has been ported. As other base modu
les | 280 # Currently only the CommonMiddleware has been ported. As other base modu
les |
| 282 # are converted, remove from the disallowed_middleware_mods tuple. | 281 # are converted, remove from the disallowed_middleware_mods tuple. |
| 283 mw_mods.remove(modname) | 282 mw_mods.remove(modname) |
| 284 logging.warn("Middleware module '%s' is not compatible. Removed!" % | 283 logging.warn("Middleware module '%s' is not compatible. Removed!" % |
| 285 modname) | 284 modname) |
| 286 setattr(settings, "MIDDLEWARE_CLASSES", tuple(mw_mods)) | 285 setattr(settings, "MIDDLEWARE_CLASSES", tuple(mw_mods)) |
| 287 | 286 |
| 288 # Remove incompatible application modules | 287 # Remove incompatible application modules |
| 289 app_mods = list(getattr(settings, "INSTALLED_APPS", ())) | 288 app_mods = list(getattr(settings, "INSTALLED_APPS", ())) |
| 289 disallowed_apps = ( |
| 290 'django.contrib.contenttypes', |
| 291 'django.contrib.sessions', |
| 292 'django.contrib.sites',) |
| 290 for app in app_mods[:]: | 293 for app in app_mods[:]: |
| 291 if app.startswith("django."): | 294 if app in disallowed_apps: |
| 292 # TODO(mglb): Again this is probably overly broad. | 295 # TODO(mglb): Again this is probably overly broad. |
| 293 app_mods.remove(app) | 296 app_mods.remove(app) |
| 294 logging.warn("Application module '%s' is not compatible. Removed!" % app) | 297 logging.warn("Application module '%s' is not compatible. Removed!" % app) |
| 295 setattr(settings, "INSTALLED_APPS", tuple(app_mods)) | 298 setattr(settings, "INSTALLED_APPS", tuple(app_mods)) |
| 296 | 299 |
| 297 # Remove incompatible context processors. | |
| 298 bad_processors = ('django.core.context_processors.auth',) | |
| 299 ctx_procs = list(getattr(settings, "TEMPLATE_CONTEXT_PROCESSORS", ())) | |
| 300 for proc in ctx_procs[:]: | |
| 301 if proc in bad_processors: | |
| 302 ctx_procs.remove(proc) | |
| 303 logging.warn("Template Context Processor '%s' is incompatible. Removed!" | |
| 304 % proc) | |
| 305 setattr(settings, "TEMPLATE_CONTEXT_PROCESSORS", tuple(ctx_procs)) | |
| 306 | |
| 307 | 300 |
| 308 def ModifyAvailableCommands(): | 301 def ModifyAvailableCommands(): |
| 309 """Removes incompatible commands and installs replacements where possible.""" | 302 """Removes incompatible commands and installs replacements where possible.""" |
| 310 if have_appserver: | 303 if have_appserver: |
| 311 # Commands are not used when running from an appserver. | 304 # Commands are not used when running from an appserver. |
| 312 return | 305 return |
| 313 from django.core import management | 306 from django.core import management |
| 314 if VERSION < (0, 97, None): | 307 if VERSION < (0, 97, None): |
| 315 RemoveCommands(management.DEFAULT_ACTION_MAPPING) | 308 RemoveCommands(management.DEFAULT_ACTION_MAPPING) |
| 316 from appengine_django.management.commands import runserver | 309 from appengine_django.management.commands import runserver |
| (...skipping 50 matching lines...) Show 10 above Show 10 below |
| 367 # Must set this env var *before* importing any more of Django. | 360 # Must set this env var *before* importing any more of Django. |
| 368 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' | 361 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' |
| 369 | 362 |
| 370 LoadAppengineEnvironment() | 363 LoadAppengineEnvironment() |
| 371 InstallReplacementImpModule() | 364 InstallReplacementImpModule() |
| 372 InstallAppengineDatabaseBackend() | 365 InstallAppengineDatabaseBackend() |
| 373 PatchDjangoSerializationModules() | 366 PatchDjangoSerializationModules() |
| 374 CleanupDjangoSettings() | 367 CleanupDjangoSettings() |
| 375 ModifyAvailableCommands() | 368 ModifyAvailableCommands() |
| 376 InstallGoogleSMTPConnection() | 369 InstallGoogleSMTPConnection() |
| 370 InstallAuthentication() |
| 377 | 371 |
| 378 logging.debug("Successfully loaded the Google App Engine Helper for Django.") | 372 logging.debug("Successfully loaded the Google App Engine Helper for Django.") |
| 379 | 373 |
| 380 | 374 |
| 381 def InstallGoogleSMTPConnection(): | 375 def InstallGoogleSMTPConnection(): |
| 382 from appengine_django import mail as gmail | 376 from appengine_django import mail as gmail |
| 383 from django.core import mail | 377 from django.core import mail |
| 384 if VERSION >= (0, 97, None): | 378 if VERSION >= (0, 97, None): |
| 385 logging.debug("Installing Google Email Adapter for Django 0.97+") | 379 logging.debug("Installing Google Email Adapter for Django 0.97+") |
| 386 mail.SMTPConnection = gmail.GoogleSMTPConnection | 380 mail.SMTPConnection = gmail.GoogleSMTPConnection |
| 387 else: | 381 else: |
| 388 logging.debug("Installing Google Email Adapter for Django 0.96") | 382 logging.debug("Installing Google Email Adapter for Django 0.96") |
| 389 mail.send_mass_mail = gmail.send_mass_mail | 383 mail.send_mass_mail = gmail.send_mass_mail |
| 390 mail.mail_admins = gmail.mail_admins | 384 mail.mail_admins = gmail.mail_admins |
| 391 mail.mail_managers = gmail.mail_managers | 385 mail.mail_managers = gmail.mail_managers |
| 386 |
| 387 def InstallAuthentication(): |
| 388 logging.debug("Installing authentication framework") |
| 389 from appengine_django.auth import models as helper_models |
| 390 from django.contrib.auth import models |
| 391 models.User = helper_models.User |
| 392 models.Group = helper_models.Group |
| 393 models.Permission = helper_models.Permission |
| 394 models.Message = helper_models.Message |
| 395 from django.contrib.auth import middleware as django_middleware |
| 396 from appengine_django.auth import middleware |
| 397 django_middleware.AuthenticationMiddleware = middleware.AuthenticationMiddlewa
re |
| 398 if VERSION >= (0, 97, None): |
| 399 from appengine_django.auth import tests |
| 400 from django.contrib.auth import tests as django_tests |
| 401 django_tests.__doc__ = tests.__doc__ |
| OLD | NEW |