Commits

Frank Becker committed 9b17189

added border effect

Comments (0)

Files changed (3)

src/hosts/templates/hosts/host_detail.html

                 <button class="btn btn-large btn-success">Book host now</button>
                 </button>
             </div>
-        <div class="row-fluid frame">
-            <div class="span4">
-                {% gencal queryset 2012 06 %}
+            <div class="row-fluid">
+                <div class="frame">
+                    <div class="span4">
+                        {% gencal queryset 2012 06 %}
+                    </div>
+                    <div class="span4">
+                        {% gencal queryset 2012 07 %}
+                    </div>
+                    <div class="span4">
+                        {% gencal queryset 2012 08 %}
+                    </div>
+                </div>
             </div>
-            <div class="span4">
-                {% gencal queryset 2012 07 %}
+            <div class="row-fluid">
+                <div class="span12 frame status status-{{ status_last_ping }}">
+                    <h1>Host Details</h1>
+                    <p></p>
+                    <ul>
+                        <li>
+                            last update: {{ host.time_change }}
+                        </li>
+                        <li>
+                            Hardwaredb ID:
+                            <a href="http://quecksilber.amd.com/hardwaredb/index.php?head=systems&rev_id={{ host.hardware_db_id }}">
+                                {{ host.hardware_db_id }}
+                            </a>
+                        </li>
+                        <li>
+                            CPUs: {{ host.cpu_number }}x {{ host.cpu_type.name }}
+                        </li>
+                        <li>
+                            location: {{ host.location }}
+                        </li>
+                        <li>
+                            Last ping: {{ host.time_last_ping|date:"r" }}
+                        </li>
+                    </ul>
+                </div>
             </div>
-            <div class="span4">
-                {% gencal queryset 2012 08 %}
-            </div>
-        </div>
-    <div class="row-fluid frame">
-        <h1>Host Details</h1>
-        <p></p>
-        <ul>
-            <li>
-                last update: {{ host.time_change }}
-            </li>
-            <li>
-                Hardwaredb ID:
-                <a href="http://quecksilber.amd.com/hardwaredb/index.php?head=systems&rev_id={{ host.hardware_db_id }}">
-                 {{ host.hardware_db_id }}
-                </a>
-            </li>
-            <li>
-                CPUs: {{ host.cpu_number }}x {{ host.cpu_type.name }}
-            </li>
-            <li>
-                location: {{ host.location }}
-            </li>
-            <li>
-                Last ping: {{ host.time_last_ping|date:"r" }}
-            </li>
-        </ul>
-    </div>
-            <div class="row-fluid frame">
-                <h1>Tapper Details</h1>
-                <p></p>
-                {% if host.in_tapper %}
-                    {% with host.tapper as t %}
-                <ul>
-                    <li>
-                         Tapper ID: <a href="http://tapper/tapper/testruns/host/{{ host.name }}">{{ t.tapper_id }}</a>
-                    </li>
-                    <li>
-                        {% if t.tapper_status != 'free' %}
-                        Current testrun id: <a href="http://tapper/tapper/testruns/id/{{ t.tapper_status }}">{{ t.tapper_status }}</a>
-                        {% else %}
-                            Host is not running any tapper testrun right now
-                        {% endif %}
-                    </li>
-                    <li>
-                        Comment: {{ t.comment }}
-                    </li>
-                    <li>
-                        Queues: {{ t.queues }}
-                    </li>
-                    <li>
-                        last update: {{ t.time_last_update|date:"jS F Y H:i" }}
-                    </li>
-                </ul>
-                    {% endwith %}
-                {% else %}
-                    This host is not registered in Tapper.
-                {% endif %}
+            <div class="row-fluid">
+                <div class="span12 frame status status-{{ status_tapper }}">
+                    <h1>Tapper Details</h1>
+                    <p></p>
+                    {% if host.in_tapper %}
+                        {% with host.tapper as t %}
+                            <ul>
+                                <li>
+                                    Tapper ID: <a href="http://tapper/tapper/testruns/host/{{ host.name }}">{{ t.tapper_id }}</a>
+                                </li>
+                                <li>
+                                    {% if t.tapper_status != 'free' %}
+                                        Current testrun id: <a href="http://tapper/tapper/testruns/id/{{ t.tapper_status }}">{{ t.tapper_status }}</a>
+                                    {% else %}
+                                        Host is not running any tapper testrun right now
+                                    {% endif %}
+                                </li>
+                                <li>
+                                    Comment: {{ t.comment }}
+                                </li>
+                                <li>
+                                    Queues: {{ t.queues }}
+                                </li>
+                                <li>
+                                    last update: {{ t.time_last_update|date:"jS F Y H:i" }}
+                                </li>
+                            </ul>
+                        {% endwith %}
+                    {% else %}
+                        This host is not registered in Tapper.
+                    {% endif %}
+                </div>
             </div>
         </div>
 {% endblock %}

src/hosts/views.py

 # -*- coding: utf-8 -*-
 
 """views"""
+from datetime import timedelta
 import json
 from django.http import HttpResponse, HttpResponseRedirect
 from django.template.context import RequestContext
     model = Host
     context_object_name = 'host'
 
+
     def get_slug_field(self):
         return 'name'
 
         context = super(HostDetails, self).get_context_data(**kwargs)
         context['now'] = timezone.now()
         context['hosts'] = [e[0] for e in Host.objects.all().values_list('name')]
+        context['status_last_ping'] = get_currentness(self.object.time_last_ping)
+        if self.object.tapper:
+            context['status_tapper'] = get_currentness(self.object.tapper.time_last_update)
+        else:
+            context['status_tapper'] = 'no-tapper'
         return context
 
 
+def get_currentness(date, delta_warning=60, delta_alarm=240):
+    """
+    Return the currentness of the given date compared to the current time
+    :param date:  date object that is going to be compared,
+                  has to be time zone aware
+    :param delta_warning: timedelta in minutes for state warning
+    :param delta_alarm: timedelta in minutes for state alarm
+    :return: one of 'ok', 'warning', 'alarm' Note, 'alarm' is returned
+             if date is None (That is if the host has never been updated.)
+    """
+    if not date:
+        return 'alarm'
+    status = 'ok'
+    time_diff = timezone.now() - date
+    if time_diff > (timedelta(minutes=delta_warning)):
+        status = "warning"
+    if time_diff > (timedelta(minutes=delta_alarm)):
+        status = "alarm"
+    return status
+
+
 def get_host_names_as_json(request):
     """return active Sponsors as json
     """
     #      "alt=''></div>" % (settings.MEDIA_URL + str(s.picture))} \
     #    for s in pictures
     #]
-    #response_data = [
+    #response_daa = [
     #    {"src": "{0}".format(settings.MEDIA_URL + str(s.picture))} \
     #        for s in pictures
     #]

src/templates/css/custom.scss

+$color_status_ok: #5bb75b;
+$color_status_warining: #faa732;
+$color_status_alarm: #bd362f;
+
 body {
   padding-top: 60px;
   padding-bottom: 40px;
   padding: 15px;
   border-radius: 5px;
   margin-bottom: 15px;
+  overflow: hidden;
 }
+
+.status {
+  box-shadow: 0 0 1em black;
+}
+
+.status-ok {
+   box-shadow: 0 0 1em green;
+ }
+
+.status-warning {
+  box-shadow: 0 0 1em yellow;
+}
+
+.status-alarm {
+  box-shadow: 0 0 1em red;
+}
+