Skip to content

Commit

Permalink
Display a more helpful error when room is missing
Browse files Browse the repository at this point in the history
Fixes #2178
  • Loading branch information
lunkwill42 committed Aug 27, 2020
1 parent fa8391b commit 3670933
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion python/nav/web/navlets/pdu.py
Expand Up @@ -48,7 +48,12 @@ def get_context_data_view(self, context):
if not roomid:
return context

room = Room.objects.get(pk=roomid)
try:
room = Room.objects.get(pk=roomid)
except Room.DoesNotExist:
context["doesnotexist"] = roomid
return context

pdus = room.netbox_set.filter(category='POWER').filter(
sensor__internal_name__startswith='rPDULoadStatusLoad'
).prefetch_related('sensor_set').distinct()
Expand Down
14 changes: 10 additions & 4 deletions python/nav/web/templates/navlets/pdu_view.html
Expand Up @@ -44,10 +44,16 @@
</script>

{% else %}
<div class="alert-box">
<a href="#" class="configure-link">Choose which room</a> to show pdu status for
</div>

{% if doesnotexist %}
<div class="alert-box error">
The room <q>{{ doesnotexist }}</q> no longer exists.
<a href="#" class="configure-link">Choose a new room</a> to show pdu status for.
</div>
{% else %}
<div class="alert-box">
<a href="#" class="configure-link">Choose which room</a> to show pdu status for
</div>
{% endif %}
<script>
(function(){
var $navlet = $('[data-id=' + {{ navlet.navlet_id }}+ ']');
Expand Down

0 comments on commit 3670933

Please sign in to comment.