Skip to content

Commit

Permalink
fix: safely check for MenuContent in result tree (#156)
Browse files Browse the repository at this point in the history
* fix: safely check for MenuContent in result tree

* fix: update changelog

Co-authored-by: Michael Collins <[email protected]>
  • Loading branch information
michaeljcollinsuk and michaeljcollinsuk authored Oct 21, 2022
1 parent c158255 commit ab9c0ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog

Unreleased
==========
* fix: safely checks for a MenuContent object in the context provided to the results tree templatetag, rather than
assume there is always one, to guard against 500 errors

1.8.0 (2022-10-13)
==================
Expand Down
9 changes: 8 additions & 1 deletion djangocms_navigation/templatetags/navigation_admin_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,21 @@ def result_tree(context, cl, request):
# Message defined here so that it is translatable. The title of the menu item is appended to the message in the JS
move_node_message = _("Are you sure you want to move menu item")

# The ID is used when storing the menu tree state in the client session object, but as this templatetag can be used
# outside of djangocms-navigation, check safely if a MenuContent object is in the current context object
try:
menu_content_id = context["menu_content"].pk
except KeyError:
menu_content_id = ""

return {
'filtered': not check_empty_dict(request.GET),
'result_hidden_fields': list(result_hidden_fields(cl)),
'result_headers': headers,
'results': list(results(cl)),
'disable_drag_drop': disable_drag_drop,
'move_node_message': move_node_message,
'menu_content_id': context["menu_content"].pk
'menu_content_id': menu_content_id,
}


Expand Down

0 comments on commit ab9c0ce

Please sign in to comment.