Skip to content

Commit

Permalink
improve device detail template: log level
Browse files Browse the repository at this point in the history
  • Loading branch information
silvioheinze committed Jan 8, 2025
1 parent 1fdc5e1 commit 9ed6fd3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/devices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ def get_context_data(self, **kwargs):
4: 'bg-dark', # CRITICAL
}

context['level_map'] = {
0: 'debug',
1: 'info',
2: 'warning',
3: 'error',
4: 'critical',
}

sensors = defaultdict(list)
# add available sensors
for measurement in Measurement.objects.filter(device=device, time_measured=device.last_update).all():
Expand Down
4 changes: 2 additions & 2 deletions app/templates/devices/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ <h3 class="mt-4 mb-4">{% trans "Log" %}</h3>
<!-- Display log level with badge using the mapping -->
{% with badge_class=level_badge_map|get:log.level %}
{% if badge_class %}
<span class="badge {{ badge_class }}">{{ log.level }}</span>
<span class="badge {{ badge_class }}">{{ level_map|get:log.level }}</span>
{% else %}
<span class="badge bg-light text-dark">{{ log.level }}</span>
<span class="badge {{ badge_class }}">{{ level_map|get:log.level }}</span>
{% endif %}
{% endwith %}
</div>
Expand Down

0 comments on commit 9ed6fd3

Please sign in to comment.