Ver código fonte

Enable specifying column grid width

Jeremy Stretch 1 dia atrás
pai
commit
1ccab930ef

+ 8 - 1
netbox/netbox/ui/layout.py

@@ -58,12 +58,19 @@ class Column:
 
 
     Parameters:
     Parameters:
         *panels: One or more Panel instances
         *panels: One or more Panel instances
+        width: Bootstrap grid column width (1-12). If unset, the column will expand to fill available space.
     """
     """
-    def __init__(self, *panels):
+    def __init__(self, *panels, width=None):
         for i, panel in enumerate(panels):
         for i, panel in enumerate(panels):
             if not isinstance(panel, Panel):
             if not isinstance(panel, Panel):
                 raise TypeError(f"Panel {i} must be an instance of a Panel, not {type(panel)}.")
                 raise TypeError(f"Panel {i} must be an instance of a Panel, not {type(panel)}.")
+        if width is not None:
+            if type(width) is not int:
+                raise ValueError(f"Column width must be an integer, not {type(width)}")
+            if width not in range(1, 13):
+                raise ValueError(f"Column width must be an integer between 1 and 12 (got {width}).")
         self.panels = panels
         self.panels = panels
+        self.width = width
 
 
     def __iter__(self):
     def __iter__(self):
         return iter(self.panels)
         return iter(self.panels)

+ 1 - 1
netbox/templates/generic/object.html

@@ -127,7 +127,7 @@ Context:
   {% for row in layout %}
   {% for row in layout %}
     <div class="row">
     <div class="row">
       {% for column in row %}
       {% for column in row %}
-        <div class="col">
+        <div class="col{% if column.width %}-{{ column.width }}{% endif %}">
           {% for panel in column %}
           {% for panel in column %}
             {% render panel %}
             {% render panel %}
           {% endfor %}
           {% endfor %}