Преглед изворни кода

Pass the value returned by get_context() to should_render()

Jeremy Stretch пре 1 дан
родитељ
комит
7042844930
2 измењених фајлова са 5 додато и 9 уклоњено
  1. 2 6
      netbox/extras/ui/panels.py
  2. 3 3
      netbox/netbox/ui/panels.py

+ 2 - 6
netbox/extras/ui/panels.py

@@ -64,12 +64,8 @@ class CustomFieldsPanel(panels.ObjectPanel):
             'custom_fields': obj.get_custom_fields_by_group(),
         }
 
-    def render(self, context):
-        ctx = self.get_context(context)
-        # Hide the panel if no custom fields exist
-        if not ctx['custom_fields']:
-            return ''
-        return super().render(context)
+    def should_render(self, context):
+        return bool(context['custom_fields'])
 
 
 class ImageAttachmentsPanel(panels.ObjectsTablePanel):

+ 3 - 3
netbox/netbox/ui/panels.py

@@ -89,9 +89,9 @@ class Panel:
         Parameters:
             context (dict): The template context
         """
-        if not self.should_render(context):
-            return ''
         ctx = self.get_context(context)
+        if not self.should_render(ctx):
+            return ''
         return render_to_string(self.template_name, ctx, request=ctx.get('request'))
 
 
@@ -427,4 +427,4 @@ class ContextTablePanel(ObjectPanel):
         }
 
     def should_render(self, context):
-        return self._resolve_table(context) is not None
+        return context.get('table') is not None