Starting upgrading to Django 1.7: removed module-level get_user_model() calls to adjust for new models loading flow + replaced WSFIHandler() with get_wsgi_application()
authorndurand
Fri, 03 Apr 2015 17:52:48 +0200
changeset 1362 df60d20f965c
parent 1361 5087560b51b6
child 1363 a8f354a9b8e4
Starting upgrading to Django 1.7: removed module-level get_user_model() calls to adjust for new models loading flow + replaced WSFIHandler() with get_wsgi_application()
src/ldt/ldt/__init__.py
src/ldt/ldt/core/handlers/modwsgi.py
src/ldt/ldt/management/__init__.py
src/ldt/ldt/security/__init__.py
--- a/src/ldt/ldt/__init__.py	Thu Apr 02 17:29:54 2015 +0200
+++ b/src/ldt/ldt/__init__.py	Fri Apr 03 17:52:48 2015 +0200
@@ -24,5 +24,5 @@
 # This method cause the load of all installed apps, causing the circular dependency problem.
 # the following code force a "pre-load" of all installed app, solving the dependecy pb.
 # TODO: remove this by reworking ldt dependencies
-from django.db.models.loading import get_models
-_ = get_models()
+#from django.db.models.loading import get_models
+#_ = get_models()
--- a/src/ldt/ldt/core/handlers/modwsgi.py	Thu Apr 02 17:29:54 2015 +0200
+++ b/src/ldt/ldt/core/handlers/modwsgi.py	Fri Apr 03 17:52:48 2015 +0200
@@ -19,8 +19,8 @@
             sys.path.remove(item)
     sys.path[:0] = new_sys_path 
 
-    import django.core.handlers.wsgi
+    import django.core.wsgi
 
-    _application = django.core.handlers.wsgi.WSGIHandler()
+    _application = django.core.wsgi.get_wsgi_application()
 
     return _application(environ, start_response)
--- a/src/ldt/ldt/management/__init__.py	Thu Apr 02 17:29:54 2015 +0200
+++ b/src/ldt/ldt/management/__init__.py	Fri Apr 03 17:52:48 2015 +0200
@@ -5,17 +5,17 @@
 from django.core.exceptions import ObjectDoesNotExist
 from django.db.models import signals
 
-User = get_user_model()
 
 def post_save_user(instance, raw, created, **kwargs):
     if created:
         try:
             owner = instance
         except ObjectDoesNotExist:
+            User = get_user_model()
             owner = User(instance)
             owner.save() 
     
-signals.post_save.connect(post_save_user, User) 
+signals.post_save.connect(post_save_user, settings.AUTH_USER_MODEL) 
         
 def test_ldt():
     if 'ldt.ldt_utils' in settings.INSTALLED_APPS:
--- a/src/ldt/ldt/security/__init__.py	Thu Apr 02 17:29:54 2015 +0200
+++ b/src/ldt/ldt/security/__init__.py	Fri Apr 03 17:52:48 2015 +0200
@@ -4,13 +4,12 @@
 from django.core.signals import request_started
 from ldt.security.permissionchecker import check_object_perm_for_user 
 
-User = get_user_model()
 
 try:
     from threading import local
 except ImportError:
     from django.utils._threading_local import local
-        
+
 _thread_locals = local()
 
 # The function that protect models is called on the first
@@ -36,14 +35,14 @@
     if hasattr(get_anonymous_user, 'anonymous_user'):
         return get_anonymous_user.anonymous_user
     
-    get_anonymous_user.anonymous_user = User.objects.get(id=settings.ANONYMOUS_USER_ID)
+    get_anonymous_user.anonymous_user = get_user_model().objects.get(id=settings.ANONYMOUS_USER_ID)
     return get_anonymous_user.anonymous_user 
 
 def get_current_user_or_admin():
     current = get_current_user()
     if current:
         return current
-    admin = User.objects.filter(is_superuser=True)[0]
+    admin = get_user_model().objects.filter(is_superuser=True)[0]
     return admin
 
 def protect_models():