Explorar o código

Add singlings urls resolving checks

Denis K %!s(int64=8) %!d(string=hai) anos
pai
achega
7c83aa6a64
Modificáronse 2 ficheiros con 16 adicións e 5 borrados
  1. 7 0
      jet/templatetags/jet_tags.py
  2. 9 5
      jet/utils.py

+ 7 - 0
jet/templatetags/jet_tags.py

@@ -221,9 +221,16 @@ def jet_sibling_object_url(context, next):
     preserved_filters_plain = context.get('preserved_filters', '')
     preserved_filters = dict(parse_qsl(preserved_filters_plain))
     admin_site = get_admin_site(context)
+
+    if admin_site is None:
+        return
+
     request = context.get('request')
     queryset = get_model_queryset(admin_site, model, request, preserved_filters=preserved_filters)
 
+    if queryset is None:
+        return
+
     sibling_object = None
     object_pks = list(queryset.values_list('pk', flat=True))
 

+ 9 - 5
jet/utils.py

@@ -166,11 +166,15 @@ class SuccessMessageMixin(object):
 def get_model_queryset(admin_site, model, request, preserved_filters=None):
     model_admin = admin_site._registry.get(model)
 
-    changelist_url = urlresolvers.reverse('%s:%s_%s_changelist' % (
-        admin_site.name,
-        model._meta.app_label,
-        model._meta.model_name
-    ))
+    try:
+        changelist_url = urlresolvers.reverse('%s:%s_%s_changelist' % (
+            admin_site.name,
+            model._meta.app_label,
+            model._meta.model_name
+        ))
+    except NoReverseMatch:
+        return
+
     changelist_filters = None
 
     if preserved_filters: