Repository: django-cms/django-cms

Issue:
ImproperlyConfigured: Error importing module cms.middleware.page: "cannot import name get_app_urls"
I can't successfully run site on django-cms 3.0c2.dev1. I followed installation instructions from http://docs.django-cms.org/en/latest/getting_started/installation/integrate.html (pip install https://github.com/divio/django-cms/archive/develop.zip) but Apache which is responsible for running wsgi apps responds with "500 Internal Server Error" instead of "welcome page". Below, is part of server's error log:

```
[Tue Apr 01 17:46:51 2014] [e[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1] mod_wsgi (pid=8859): Exception occurred processing WSGI script '/home/user1/test_env1/prj1/prj1/wsgi.py'.
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1] Traceback (most recent call last):
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     self.load_middleware()
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     mw_class = import_by_path(middleware_path)
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/django/utils/module_loading.py", line 26, in import_by_path
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     sys.exc_info()[2])
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/django/utils/module_loading.py", line 21, in import_by_path
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     module = import_module(module_path)
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     __import__(name)
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/middleware/page.py", line 2, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.appresolver import applications_page_check
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/appresolver.py", line 7, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.models.pagemodel import Page
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/models/__init__.py", line 9, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from .placeholderpluginmodel import *  # nopyflakes
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/models/placeholderpluginmodel.py", line 3, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.models.fields import PlaceholderField
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/models/fields.py", line 2, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.forms.fields import PageSelectFormField
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/forms/fields.py", line 7, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.forms.widgets import PageSelectWidget, PageSmartLinkWidget
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/forms/widgets.py", line 14, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.templatetags.cms_admin import CMS_ADMIN_ICON_BASE
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/templatetags/cms_admin.py", line 9, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.utils.admin import get_admin_menu_item_context
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/utils/admin.py", line 13, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.utils import permissions
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/utils/permissions.py", line 9, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.plugin_pool import plugin_pool
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/plugin_pool.py", line 2, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.views import invalidate_cms_page_cache
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]   File "/home/user1/test_env1/lib/python2.6/site-packages/cms/views.py", line 18, in <module>
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1]     from cms.appresolver import get_app_urls
[Tue Apr 01 17:46:51 2014] [error] [client 127.0.0.1] ImproperlyConfigured: Error importing module cms.middleware.page: "cannot import name get_app_urls"
```



Discussion:
seams to be a circual import

I suppose its the same issue in my case, where I try use uwsgi or just python shell instead manage.py shell:

```
(mytestproject)root@ubuntu:/home/env/mytestproject/src# python
Python 2.7.3 (default, Feb 27 2014, 19:58:35) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cms.utils
>>> from cms.utils.page_resolver import get_page_from_request
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/utils/page_resolver.py", line 2, in <module>
    from cms.utils.moderator import use_draft
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/utils/moderator.py", line 2, in <module>
    from cms.models import CMSPlugin, Title
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/models/__init__.py", line 9, in <module>
    from .placeholderpluginmodel import *  # nopyflakes
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/models/placeholderpluginmodel.py", line 3, in <module>
    from cms.models.fields import PlaceholderField
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/models/fields.py", line 2, in <module>
    from cms.forms.fields import PageSelectFormField
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/forms/fields.py", line 7, in <module>
    from cms.forms.widgets import PageSelectWidget, PageSmartLinkWidget
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/forms/widgets.py", line 14, in <module>
    from cms.templatetags.cms_admin import CMS_ADMIN_ICON_BASE
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/templatetags/cms_admin.py", line 9, in <module>
    from cms.utils.admin import get_admin_menu_item_context
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/utils/admin.py", line 13, in <module>
    from cms.utils import permissions
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/utils/permissions.py", line 9, in <module>
    from cms.plugin_pool import plugin_pool
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/plugin_pool.py", line 2, in <module>
    from cms.views import invalidate_cms_page_cache
  File "/home/env/mytestproject/local/lib/python2.7/site-packages/cms/views.py", line 29, in <module>
    from cms.utils.page_resolver import get_page_from_request
ImportError: cannot import name get_page_from_request

>>> import  cms.models
>>> from cms.utils.page_resolver import get_page_from_request
>>> print get_page_from_request.__module__
cms.utils.page_resolver
```


Resolving patch:
diff --git a/cms/middleware/page.py b/cms/middleware/page.py
--- a/cms/middleware/page.py
+++ b/cms/middleware/page.py
@@ -1,9 +1,9 @@
 # -*- coding: utf-8 -*-
-from cms.appresolver import applications_page_check
 from django.utils.functional import SimpleLazyObject
 
 
 def get_page(request):
+    from cms.appresolver import applications_page_check
     from cms.utils.page_resolver import get_page_from_request
 
     if not hasattr(request, '_current_page_cache'):
diff --git a/cms/plugin_pool.py b/cms/plugin_pool.py
--- a/cms/plugin_pool.py
+++ b/cms/plugin_pool.py
@@ -1,5 +1,4 @@
 # -*- coding: utf-8 -*-
-from cms.views import invalidate_cms_page_cache
 import warnings
 
 from django.conf import settings
@@ -34,6 +33,7 @@ def discover_plugins(self):
         if self.discovered:
             return
         self.discovered = True
+        from cms.views import invalidate_cms_page_cache
         invalidate_cms_page_cache()
         load('cms_plugins')
 


Test patch: