Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix admin #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions importd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,30 +409,38 @@ def _configure_django(self, **kw):
kw["MIDDLEWARE_CLASSES"].insert(
0, "importd.SmartReturnMiddleware"
)
if "TEMPLATE_CONTEXT_PROCESSORS" not in kw.keys():
kw["TEMPLATE_CONTEXT_PROCESSORS"] = list(
global_settings.TEMPLATE_CONTEXT_PROCESSORS)

installed = list(kw.setdefault("INSTALLED_APPS", []))

admin_url = kw.pop("admin", "^admin/")

if admin_url:
middlewares_list = []
context_processor_list = []
if "django.contrib.sessions" not in installed:
installed.append("django.contrib.sessions")
middlewares_list.append("django.contrib.sessions"
".middleware."
"SessionMiddleware")
if "django.contrib.auth" not in installed:
installed.append("django.contrib.auth")
middlewares_list.append("django.contrib.auth.middleware"
".AuthenticationMiddleware")
if "django.contrib.contenttypes" not in installed:
installed.append("django.contrib.contenttypes")
if "django.contrib.auth" not in installed:
installed.append("django.contrib.auth")
middlewares_list.append("django.contrib.auth.middleware"
".AuthenticationMiddleware")
if "django.contrib.messages" not in installed:
installed.append("django.contrib.messages")
if "django.contrib.sessions" not in installed:
installed.append("django.contrib.sessions")
# check session middleware installed
# https://docs.djangoproject.com/en/1.7/topics/http/sessions/#enabling-sessions
last_position = len(kw["MIDDLEWARE_CLASSES"])
kw["MIDDLEWARE_CLASSES"] = list(kw["MIDDLEWARE_CLASSES"])
kw["MIDDLEWARE_CLASSES"].insert(
last_position,
"django.contrib.sessions.middleware.SessionMiddleware"
)
middlewares_list.append("django.contrib.messages."
"middleware.MessageMiddleware")
context_processor_list.append("django.contrib.messages."
"context_processors.messages")
if "django.contrib.admin" not in installed:
installed.append("django.contrib.admin")
if "django.contrib.humanize" not in installed:
Expand Down Expand Up @@ -463,6 +471,16 @@ def _configure_django(self, **kw):
# This one gives 500 if its Enabled without previous syncdb
# 'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',

def _insert_setting(list_strings, django_settings_key):
for _str in list_strings:
if _str not in kw[django_settings_key]:
last_pos = len(kw[django_settings_key])
kw[django_settings_key].insert(last_pos, _str)

_insert_setting(middlewares_list, "MIDDLEWARE_CLASSES")
_insert_setting(context_processor_list,
"TEMPLATE_CONTEXT_PROCESSORS")

if django_extensions and werkzeug:
installed.append('django_extensions')

Expand Down