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

Error: Django Suit was unable to retrieve apps list for menu #633

Closed
gamesbook opened this issue Aug 8, 2017 · 2 comments
Closed

Error: Django Suit was unable to retrieve apps list for menu #633

gamesbook opened this issue Aug 8, 2017 · 2 comments

Comments

@gamesbook
Copy link

If this is a bug please specify versions you're using first.

Django version: 1.10.7
Django Suit version: 2.0a1
Python version: 3.5.3

Issue:

I am trying to show the user an intermediate page, containing a form, as part of a new admin action.

I have copied the base.html and the base_site.html templates from the Django Suit code base into my own templates/admin directory and then my form's template inherits from those.

When Django tries to display the page, the log shows the following warning/error:

2017-08-08T06:38:19 [root:36] WARNING - Django Suit was unable to retrieve apps list for menu.

The full stack trace:

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/samples/request/

Django Version: 1.10.7
Python Version: 3.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.humanize',
 'django.contrib.staticfiles',
 'crispy_forms',
 'authtools',
 'easy_thumbnails',
 'myproject.settings.apps.SuitConfig',
 'django.contrib.admin',
 'myproject.apps.accounts',
 'users',
 'methodology',
 'projects',
 'samples',
 'home',
 'debug_toolbar']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware']


Template error:
In template /home/gamesbook/dev/myproject/code/myproject/templates/admin/actions/project_register.html, error at line 0
   'NoneType' object is not iterable   1 : {% extends "admin/actions/base.html" %}
   2 : {% load i18n admin_static admin_modify %}
   3 : {% load crispy_forms_tags %}
   4 : 
   5 : {% block content %}
   6 :   <div id="content-main" class="inner-two-columns">
   7 :     <div class="inner-center-column">
   8 :       <h2>{{ action_name }}</h2>
   9 :       {% crispy project_register_form %}
   10 :       <fieldset class="module aligned with-legend ">


Traceback:

File "lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
  42.             response = get_response(request)

File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/core/handlers/base.py" in _legacy_get_response
  249.             response = self._get_response(request)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/contrib/admin/options.py" in wrapper
  544.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/contrib/admin/sites.py" in inner
  211.             return view(request, *args, **kwargs)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/contrib/admin/options.py" in changelist_view
  1569.                 response = self.response_action(request, queryset=cl.get_queryset(request))
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/contrib/admin/options.py" in response_action
  1305.             response = func(self, request, queryset)
File "/home/gamesbook/dev/myproject/code/myproject/apps/samples/admin.py" in register_new_project
  260.             RequestContext(request))
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/shortcuts.py" in render_to_response
  21.     content = loader.render_to_string(template_name, context, using=using)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/loader.py" in render_to_string
  68.     return template.render(context, request)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/backends/django.py" in render
  66.             return self.template.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  208.                     return self._render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  94.     return self.nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  174.         return compiled_parent._render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  94.     return self.nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  174.         return compiled_parent._render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  94.     return self.nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  174.         return compiled_parent._render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  94.     return self.nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  174.         return compiled_parent._render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  94.     return self.nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  174.         return compiled_parent._render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  94.     return self.nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/defaulttags.py" in render
  315.                 return nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  70.                 result = block.nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  210.                 return template.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  210.                 return self._render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  94.     return self.nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/defaulttags.py" in render
  510.             return self.nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/defaulttags.py" in render
  315.                 return nodelist.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render
  994.                 bit = node.render_annotated(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/base.py" in render_annotated
  961.             return self.render(context)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/django/template/defaulttags.py" in render
  165.                 values = list(values)
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/suit/menu.py" in __iter__
  59.         for each in self.get_menu_items():
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/suit/menu.py" in get_menu_items
  64.             self.menu_items = self.build_menu()
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/suit/menu.py" in build_menu
  78.         self.map_native_apps()
File "/home/gamesbook/.venvs/myproject/lib/python3.5/site-packages/suit/menu.py" in map_native_apps
  116.         for native_app in self.available_apps:

Exception Type: TypeError at /admin/samples/analysisbatchrequest/
Exception Value: 'NoneType' object is not iterable
@darklow
Copy link
Owner

darklow commented Aug 8, 2017

There is a special way how you need to create/wrap custom admin views using each_context function:

Here is an example:
https://github.com/darklow/django-suit/blob/v2/demo/demo/views.py#L14

Here are the official docs:
https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.AdminSite.each_context https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_urls

Todo: #564

@gamesbook
Copy link
Author

Thanks; now that I see your example, I recognise that code. My mistake was in using a pattern from a much earlier version of Django.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants