Skip to content

Commit

Permalink
Fixing django-cms#1649 - NoReverseMatch raised if apphook doesn't exist
Browse files Browse the repository at this point in the history
Some apps, like cmsplugin-zinnia and cmsplugin_news will raise NoReverseMatch when trying to generate their menus before an apphook is installed. In sampleapp this is solved by adding a try-except like the one in this commit. Placing the try-except in django-cms instead of inside every app would simplify the process of writing plugins and avoid some confusing 500-errors for new users trying to install plugins.
  • Loading branch information
JakeHedman authored and Lacrymology committed Aug 21, 2014
1 parent a26f8cf commit 07b5d55
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion menus/menu_pool.py
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.core.urlresolvers import NoReverseMatch
from django.utils.translation import get_language
from menus.exceptions import NamespaceAllreadyRegistered
from menus.models import CacheKey
Expand Down Expand Up @@ -131,7 +132,12 @@ def _build_nodes(self, request, site_id):

final_nodes = []
for menu_class_name in self.menus:
nodes = self.menus[menu_class_name].get_nodes(request)
try:
nodes = self.menus[menu_class_name].get_nodes(request)
except NoReverseMatch:
# Apps might raise NoReverseMatch if an apphook does not yet
# exist, skip them instead of crashing
pass
# nodes is a list of navigation nodes (page tree in cms + others)
final_nodes += _build_nodes_inner_for_one_menu(nodes, menu_class_name)
cache.set(key, final_nodes, settings.CMS_CACHE_DURATIONS['menus'])
Expand Down

0 comments on commit 07b5d55

Please sign in to comment.