Commits

Anonymous committed 6168eaf

Fix urls IndexError

  • Participants
  • Parent commits 15adbbe

Comments (0)

Files changed (3)

     def get_info(self, request):
         return render_to_response('some_template.html')
 
+IMPORTANT: also you must decorate your method with @staticmethod or @classmethod if you use this feture in InlineModelAdmin
+NOTE: if you use this feature in InlineModelAdmin, "model_name" still be name of model registred with ModelAdmin which contains inline (so as "app_label").
+To prevent it set "use_inline_data" arg to True in register_url decorator
+
+
+
 At client side you could use:
 - autoinlines.js (a tool to create dynamic inlines, by clicking on checkboxes controllers)
 Usage: $.autoInline({
 
 - searchline.js (a tool to filter checkboxes)
 Usage: $("fieldset .field-fieldname").addSearchLine();
-
-
-IMPORTANT: also you must decorate your method with @staticmethod or @classmethod if you use this feture in InlineModelAdmin
-NOTE: if you use this feature in InlineModelAdmin, "model_name" still be name of model registred with ModelAdmin which contains inline (so as "app_label").
-To prevent it set "use_inline_data" arg to True in register_url decorator
-

admin_extended/__init__.py

-__version__ = '1.0.3'
+__version__ = '1.0.4'

admin_extended/urls.py

 
 
 def get_site_registered_info(cls):
-    return [(k, v) for k, v in admin.site._registry.items() if isinstance(v, cls)][0]
+    try:
+        return [(k, v) for k, v in admin.site._registry.items() if isinstance(v, cls)][0]
+    except IndexError:
+        return (None, None)
 
 
 def get_link(method, model):
         admin_classes = get_admin_classes(app)
         for admin_cls in admin_classes:
             model, admin_inst = get_site_registered_info(admin_cls)
-            methods = get_signed_methods(admin_cls, admin_inst)
-            for method in methods:
-                urls.append(url(get_link(method, model), method))
+            if model:
+                methods = get_signed_methods(admin_cls, admin_inst)
+                for method in methods:
+                    urls.append(url(get_link(method, model), method))
 
-            for inline in getattr(admin_cls, 'inlines', []):
-                methods = get_signed_methods(inline)
-                for method in methods:
-                    model = inline.model if method.use_inline_data else model
-                    urls.append(url(get_link(method, model), method))
+                for inline in getattr(admin_cls, 'inlines', []):
+                    methods = get_signed_methods(inline)
+                    for method in methods:
+                        model = inline.model if method.use_inline_data else model
+                        urls.append(url(get_link(method, model), method))
     return patterns(*urls)