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

#6732: Fix rendering of stats on home page when not authenticated

checktheroads 4 лет назад
Родитель
Сommit
03a1014714
2 измененных файлов с 14 добавлено и 7 удалено
  1. 6 5
      netbox/netbox/views/__init__.py
  2. 8 2
      netbox/templates/home.html

+ 6 - 5
netbox/netbox/views/__init__.py

@@ -109,12 +109,13 @@ class HomeView(View):
             for section_label, section_items in sections:
                 stat = {"label": section_label, "items": []}
                 for perm, item_label, description, get_count in section_items:
+                    app, scope = perm.split(".")
+                    url = ":".join((app, scope.replace("view_", "") + "_list"))
+                    item = {"label": item_label, "description": description, "count": None, "url": url, "disabled": True}
                     if perm in perms:
-                        app, scope = perm.split(".")
-                        url = ":".join((app, scope.replace("view_", "") + "_list"))
-                        stat["items"].append(
-                            {"label": item_label, "description": description, "count": get_count(), "url": url}
-                        )
+                        item["count"] = get_count()
+                        item["disabled"] = False
+                    stat["items"].append(item)
                 stats.append(stat)
             return stats
 

+ 8 - 2
netbox/templates/home.html

@@ -13,7 +13,7 @@
         <div class="card-body">
           <div class="list-group list-group-flush">
             {% for item in section.items %}
-            <a href="{% url item.url %}" class="list-group-item list-group-item-action">
+            <a href="{% url item.url %}" class="list-group-item list-group-item-action{% if item.disabled %} disabled{% endif %}">
               <div class="d-flex w-100 justify-content-between align-items-center">
                 <div class="d-flex flex-column align-items-start">
                   <h6 class="mb-1">{{ item.label }}</h6>
@@ -21,7 +21,13 @@
                   <small class="mb-1 text-muted">{{ item.description }}</small>
                   {% endif %}
                 </div>
-                <span class="badge bg-secondary rounded-pill">{{ item.count }}</span>
+                <span class="badge bg-secondary rounded-pill">
+                  {% if item.count == None %}
+                    <i class="mdi mdi-lock"></i>
+                  {% else %}
+                    {{ item.count }}
+                  {% endif %}
+                </span>
               </div>
             </a>
             {% endfor %}