mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-19 15:31:35 +02:00
Handle panel title when object is not available
This commit is contained in:
@@ -106,9 +106,15 @@ class ObjectPanel(Panel):
|
|||||||
|
|
||||||
def get_context(self, context):
|
def get_context(self, context):
|
||||||
obj = resolve_attr_path(context, self.accessor)
|
obj = resolve_attr_path(context, self.accessor)
|
||||||
|
if self.title is not None:
|
||||||
|
title_ = self.title
|
||||||
|
elif obj is not None:
|
||||||
|
title_ = title(obj._meta.verbose_name)
|
||||||
|
else:
|
||||||
|
title_ = None
|
||||||
return {
|
return {
|
||||||
**super().get_context(context),
|
**super().get_context(context),
|
||||||
'title': self.title or title(obj._meta.verbose_name),
|
'title': title_,
|
||||||
'object': obj,
|
'object': obj,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
<!-- begin {{ panel_class|default:"panel" }} -->
|
<!-- begin {{ panel_class|default:"panel" }} -->
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h2 class="card-header">
|
{% if title or actions %}
|
||||||
{{ title }}
|
<h2 class="card-header">
|
||||||
{% if actions %}
|
{{ title|default:"" }}
|
||||||
<div class="card-actions">
|
{% if actions %}
|
||||||
{% for action in actions %}
|
<div class="card-actions">
|
||||||
{% render action %}
|
{% for action in actions %}
|
||||||
{% endfor %}
|
{% render action %}
|
||||||
</div>
|
{% endfor %}
|
||||||
{% endif %}
|
</div>
|
||||||
</h2>
|
{% endif %}
|
||||||
|
</h2>
|
||||||
|
{% endif %}
|
||||||
{% block panel_content %}{% endblock %}
|
{% block panel_content %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
<!-- end {{ panel_class|default:"panel" }} -->
|
<!-- end {{ panel_class|default:"panel" }} -->
|
||||||
|
|||||||
Reference in New Issue
Block a user