hswaw/checkinator: implement unclaimed devices listing

Change-Id: Ieecaf44927b7949c6e16dabea3a84e3bd80d3b7f
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1785
Reviewed-by: vuko <vuko@hackerspace.pl>
Reviewed-by: implr <implr@hackerspace.pl>
diff --git a/hswaw/checkinator/at/templates/invalid_ip.html b/hswaw/checkinator/at/templates/invalid_ip.html
index 98b33c2..9f28de3 100644
--- a/hswaw/checkinator/at/templates/invalid_ip.html
+++ b/hswaw/checkinator/at/templates/invalid_ip.html
@@ -12,5 +12,5 @@
     </ul>
   </p>
 
-  <p> your IP: {{ ip_address }} </p>
+  <p>Your IP: {{ ip_address }} </p>
 {% endblock %}
diff --git a/hswaw/checkinator/at/templates/main.html b/hswaw/checkinator/at/templates/main.html
index 36ab1cd..f8e266e 100644
--- a/hswaw/checkinator/at/templates/main.html
+++ b/hswaw/checkinator/at/templates/main.html
@@ -15,9 +15,9 @@
   {% endfor %}
   </ul>
   {% trans n_unk=unknown|length %}
-  <p>There is {{ n_unk }} unknown device operating. </p>
+  <p>There is <a href="/unclaimed">{{ n_unk }} unknown device</a> operating. </p>
   {% pluralize %}
-  <p>There are {{ n_unk }} unknown devices operating.</p> 
+  <p>There are <a href="/unclaimed">{{ n_unk }} unknown devices</a> operating.</p> 
   {% endtrans %}
   {% trans n_kek=kektops|length %}
   <p>There is {{ n_kek }} unknown kektop operating.</p>
diff --git a/hswaw/checkinator/at/templates/unclaimed.html b/hswaw/checkinator/at/templates/unclaimed.html
new file mode 100644
index 0000000..fa0ce1e
--- /dev/null
+++ b/hswaw/checkinator/at/templates/unclaimed.html
@@ -0,0 +1,13 @@
+{% extends "basic.html" %}
+{% block content %}
+<table class="devices">
+  <tr>
+      <th>MAC</th>
+      <th>IP</th>
+      <th>Hostname</th>
+      <th>Last seen</th>
+  </tr>
+  {% for dev in data %}
+      <tr><td><code>{{ dev.hwaddr }}</code></td><td>{{ dev.ip }}</td><td>{{ dev.name }}</td><td>{{ dev.atime | strfts }}</td></tr>
+  {% endfor %}
+{% endblock %}
diff --git a/hswaw/checkinator/at/web.py b/hswaw/checkinator/at/web.py
index f85aa25..e3d4450 100644
--- a/hswaw/checkinator/at/web.py
+++ b/hswaw/checkinator/at/web.py
@@ -295,8 +295,21 @@
         return redirect(url_for('account'))
     
     
-    @app.route('/admin')
-    @cap_required('staff')
+    @app.route("/unclaimed")
+    @auth_login_required
+    @restrict_to_hs
+    def unclaimed():
+        devices = app.updater.get_active_devices()
+        macs = list(devices.keys())
+        identified_macs = {dev.hwaddr for dev in list(get_device_infos(g.db, macs))}
+        filtered_devices = [
+            d for d in devices.values() if d.hwaddr not in identified_macs
+        ]
+        filtered_devices.sort(key=lambda v: -v.atime)
+        return render_template("unclaimed.html", data=filtered_devices)
+
+    @app.route("/admin")
+    @cap_required("staff")
     def admin():
         data = now_at()
         return render_template('admin.html', data=data)