Просмотр исходного кода

Replace model_name and model_name_verbose filters with meta

Jeremy Stretch 6 лет назад
Родитель
Сommit
15ab30d0c6

+ 1 - 1
netbox/templates/dcim/cable_connect.html

@@ -53,7 +53,7 @@
                             <div class="form-group">
                                 <label class="col-md-3 control-label required">Type</label>
                                 <div class="col-md-9">
-                                    <p class="form-control-static">{{ termination_a|model_name|capfirst }}</p>
+                                    <p class="form-control-static">{{ termination_a|meta:"verbose_name"|capfirst }}</p>
                                 </div>
                             </div>
                             <div class="form-group">

+ 1 - 1
netbox/templates/dcim/inc/cable_termination.html

@@ -11,7 +11,7 @@
         <tr>
             <td>Type</td>
             <td>
-                {{ termination|model_name|capfirst }}
+                {{ termination|meta:"verbose_name"|capfirst }}
             </td>
         </tr>
         <tr>

+ 1 - 1
netbox/templates/dcim/inc/cable_trace_end.html

@@ -17,7 +17,7 @@
     <div class="panel-body text-center">
         {% if end.device %}
             {# Device component #}
-            {% with model=end|model_name %}
+            {% with model=end|meta:"verbose_name" %}
                 <strong>{{ model|bettertitle }} {{ end }}</strong><br />
                 {% if model == 'interface' %}
                     {{ end.get_type_display }}

+ 1 - 1
netbox/templates/ipam/ipaddress_edit.html

@@ -35,7 +35,7 @@
             </div>
             <div class="panel-body">
                 <div class="form-group">
-                    <label class="col-md-3 control-label">{{ obj.interface.parent|model_name|bettertitle }}</label>
+                    <label class="col-md-3 control-label">{{ obj.interface.parent|meta:"verbose_name"|bettertitle }}</label>
                     <div class="col-md-9">
                         <p class="form-control-static">
                             <a href="{{ obj.interface.parent.get_absolute_url }}">{{ obj.interface.parent }}</a>

+ 1 - 1
netbox/templates/utilities/obj_list.html

@@ -15,7 +15,7 @@
         {% export_button content_type %}
     {% endif %}
 </div>
-<h1>{% block title %}{{ content_type.model_class|model_name_plural|bettertitle }}{% endblock %}</h1>
+<h1>{% block title %}{{ content_type.model_class|meta:"verbose_name_plural"|bettertitle }}{% endblock %}</h1>
 <div class="row">
     <div class="col-md-{% if filter_form %}9{% else %}12{% endif %}">
         {% with bulk_edit_url=content_type.model_class|url_name:"bulk_edit" bulk_delete_url=content_type.model_class|url_name:"bulk_delete" %}

+ 4 - 11
netbox/utilities/templatetags/helpers.py

@@ -62,19 +62,12 @@ def render_yaml(value):
 
 
 @register.filter()
-def model_name(obj):
+def meta(obj, attr):
     """
-    Return the name of the model of the given object
+    Return the specified Meta attribute of a model. This is needed because Django does not permit templates
+    to access attributes which begin with an underscore (e.g. _meta).
     """
-    return obj._meta.verbose_name
-
-
-@register.filter()
-def model_name_plural(obj):
-    """
-    Return the plural name of the model of the given object
-    """
-    return obj._meta.verbose_name_plural
+    return getattr(obj._meta, attr, '')
 
 
 @register.filter()