Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(27)

Side by Side Diff: appengine_django/__init__.py

Issue 908: [issue6] Google's Users API Integration (Closed) SVN Base: http://google-app-engine-django.googlecode.com/svn/trunk/
Patch Set: DjangoUserModel, better helpers integration for authentication Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 231 matching lines...) Show 10 above Show 10 below
242 for var in ["NAME", "USER", "PASSWORD", "HOST", "PORT"]: 242 for var in ["NAME", "USER", "PASSWORD", "HOST", "PORT"]:
243 val = getattr(settings, "DATABASE_%s" % var, "") 243 val = getattr(settings, "DATABASE_%s" % var, "")
244 if val: 244 if val:
245 setattr(settings, "DATABASE_%s" % var, "") 245 setattr(settings, "DATABASE_%s" % var, "")
246 logging.warn("DATABASE_%s should be blank. Value overriden!") 246 logging.warn("DATABASE_%s should be blank. Value overriden!")
247 247
248 # Remove incompatible middleware modules. 248 # Remove incompatible middleware modules.
249 mw_mods = list(getattr(settings, "MIDDLEWARE_CLASSES", ())) 249 mw_mods = list(getattr(settings, "MIDDLEWARE_CLASSES", ()))
250 disallowed_middleware_mods = ( 250 disallowed_middleware_mods = (
251 'django.contrib.sessions.middleware.SessionMiddleware', 251 'django.contrib.sessions.middleware.SessionMiddleware',
252 'django.contrib.auth.middleware.AuthenticationMiddleware',
253 'django.middleware.doc.XViewMiddleware',) 252 'django.middleware.doc.XViewMiddleware',)
254 for modname in mw_mods[:]: 253 for modname in mw_mods[:]:
255 if modname in disallowed_middleware_mods: 254 if modname in disallowed_middleware_mods:
256 # Currently only the CommonMiddleware has been ported. As other base modu les 255 # Currently only the CommonMiddleware has been ported. As other base modu les
257 # are converted, remove from the disallowed_middleware_mods tuple. 256 # are converted, remove from the disallowed_middleware_mods tuple.
258 mw_mods.remove(modname) 257 mw_mods.remove(modname)
259 logging.warn("Middleware module '%s' is not compatible. Removed!" % 258 logging.warn("Middleware module '%s' is not compatible. Removed!" %
260 modname) 259 modname)
261 setattr(settings, "MIDDLEWARE_CLASSES", tuple(mw_mods)) 260 setattr(settings, "MIDDLEWARE_CLASSES", tuple(mw_mods))
262 261
263 # Remove incompatible application modules 262 # Remove incompatible application modules
264 app_mods = list(getattr(settings, "INSTALLED_APPS", ())) 263 app_mods = list(getattr(settings, "INSTALLED_APPS", ()))
264 allowed_apps = ("django.contrib.auth",)
mattbrown.nz 2008/05/18 11:23:43 We're using a blacklist for middleware modules, fo
aalbrecht 2008/05/18 19:17:47 On 2008/05/18 11:23:43, mattbrown.nz wrote: > We'r
265 for app in app_mods[:]: 265 for app in app_mods[:]:
266 if app.startswith("django."): 266 if app.startswith("django.") and app not in allowed_apps:
267 # TODO(mglb): Again this is probably overly broad. 267 # TODO(mglb): Again this is probably overly broad.
268 app_mods.remove(app) 268 app_mods.remove(app)
269 logging.warn("Application module '%s' is not compatible. Removed!" % app) 269 logging.warn("Application module '%s' is not compatible. Removed!" % app)
270 setattr(settings, "INSTALLED_APPS", tuple(app_mods)) 270 setattr(settings, "INSTALLED_APPS", tuple(app_mods))
271 271
272 # Remove incompatible context processors. 272 # Remove incompatible context processors.
273 bad_processors = ('django.core.context_processors.auth',) 273 bad_processors = tuple()
274 ctx_procs = list(getattr(settings, "TEMPLATE_CONTEXT_PROCESSORS", ())) 274 ctx_procs = list(getattr(settings, "TEMPLATE_CONTEXT_PROCESSORS", ()))
275 for proc in ctx_procs[:]: 275 for proc in ctx_procs[:]:
276 if proc in bad_processors: 276 if proc in bad_processors:
277 ctx_procs.remove(proc) 277 ctx_procs.remove(proc)
278 logging.warn("Template Context Processor '%s' is incompatible. Removed!" 278 logging.warn("Template Context Processor '%s' is incompatible. Removed!"
279 % proc) 279 % proc)
280 setattr(settings, "TEMPLATE_CONTEXT_PROCESSORS", tuple(ctx_procs)) 280 setattr(settings, "TEMPLATE_CONTEXT_PROCESSORS", tuple(ctx_procs))
mattbrown.nz 2008/05/18 11:23:43 This stanza can be removed completely. the auth co
aalbrecht 2008/05/18 19:17:47 On 2008/05/18 11:23:43, mattbrown.nz wrote: > This
281 281
282 282
283 def ModifyAvailableCommands(): 283 def ModifyAvailableCommands():
284 """Removes incompatible commands and installs replacements where possible.""" 284 """Removes incompatible commands and installs replacements where possible."""
285 if have_appserver: 285 if have_appserver:
286 # Commands are not used when running from an appserver. 286 # Commands are not used when running from an appserver.
287 return 287 return
288 from django.core import management 288 from django.core import management
289 if VERSION < (0, 97, None): 289 if VERSION < (0, 97, None):
290 RemoveCommands(management.DEFAULT_ACTION_MAPPING) 290 RemoveCommands(management.DEFAULT_ACTION_MAPPING)
(...skipping 51 matching lines...) Show 10 above Show 10 below
342 # Must set this env var *before* importing any more of Django. 342 # Must set this env var *before* importing any more of Django.
343 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 343 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
344 344
345 LoadAppengineEnvironment() 345 LoadAppengineEnvironment()
346 InstallReplacementImpModule() 346 InstallReplacementImpModule()
347 InstallAppengineDatabaseBackend() 347 InstallAppengineDatabaseBackend()
348 PatchDjangoSerializationModules() 348 PatchDjangoSerializationModules()
349 CleanupDjangoSettings() 349 CleanupDjangoSettings()
350 ModifyAvailableCommands() 350 ModifyAvailableCommands()
351 InstallGoogleSMTPConnection() 351 InstallGoogleSMTPConnection()
352 InstallAuthentication()
352 353
353 logging.debug("Successfully loaded the Google App Engine Helper for Django.") 354 logging.debug("Successfully loaded the Google App Engine Helper for Django.")
354 355
355 356
356 def InstallGoogleSMTPConnection(): 357 def InstallGoogleSMTPConnection():
357 from appengine_django import mail as gmail 358 from appengine_django import mail as gmail
358 from django.core import mail 359 from django.core import mail
359 if VERSION >= (0, 97, None): 360 if VERSION >= (0, 97, None):
360 logging.debug("Installing Google Email Adapter for Django 0.97+") 361 logging.debug("Installing Google Email Adapter for Django 0.97+")
361 mail.SMTPConnection = gmail.GoogleSMTPConnection 362 mail.SMTPConnection = gmail.GoogleSMTPConnection
362 else: 363 else:
363 logging.debug("Installing Google Email Adapter for Django 0.96") 364 logging.debug("Installing Google Email Adapter for Django 0.96")
364 mail.send_mass_mail = gmail.send_mass_mail 365 mail.send_mass_mail = gmail.send_mass_mail
365 mail.mail_admins = gmail.mail_admins 366 mail.mail_admins = gmail.mail_admins
366 mail.mail_managers = gmail.mail_managers 367 mail.mail_managers = gmail.mail_managers
368
369 def InstallAuthentication():
370 logging.debug("Installing authentication framework")
371 from django.contrib.auth import models as django_models
372 from appengine_django.auth.models import DjangoUser
373 django_models.User = DjangoUser
374 from django.contrib.auth import middleware as django_middleware
375 from appengine_django.auth import middleware
376 django_middleware.AuthenticationMiddleware = middleware.AuthenticationMiddlewa re
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r338