muizenval

Observe mouse traps remotely
Log | Files | Refs

commit 5a786e21cac2f84fb3c51ce8ea4b65a4cecd1f3b
parent 4da06d89df895377e56478db7470932cd719dd09
Author: Friedel Schön <[email protected]>
Date:   Wed, 11 May 2022 18:46:17 +0200

adding traps dashboard

Diffstat:
Mserver/models.py | 6+++++-
Mserver/routes.py | 12+++++++++++-
Mserver/site.db | 0
Aserver/site.db-journal | 0
Mserver/static/main.css | 1+
Aserver/templates/dashboard.html | 33+++++++++++++++++++++++++++++++++
Mserver/templates/layout.html | 3+--
7 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/server/models.py b/server/models.py @@ -22,11 +22,15 @@ class Home(db.Model): id = db.Column(db.Integer, primary_key=True) owner = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) catcher = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) - adress = db.Column(db.Text, nullable=False) + street = db.Column(db.Text, nullable=False) + number = db.Column(db.Integer, nullable=False) + zipcode = db.Column(db.Text, nullable=False) + place = db.Column(db.Text, nullable=False) class Trap(db.Model): id = db.Column(db.Integer, primary_key=True) mac = db.Column(db.String(16), unique=True, nullable=False) + name = db.Column(db.Text) home = db.Column(db.Integer, db.ForeignKey('home.id'), nullable=False) last_heartbeat = db.Column(db.Integer, nullable=True, default=0) caught = db.Column(db.Boolean, nullable=False, default=False) diff --git a/server/routes.py b/server/routes.py @@ -1,3 +1,4 @@ +from operator import or_ import os import secrets @@ -9,7 +10,7 @@ from datetime import datetime from .app import app, bcrypt, db from .forms import LoginForm, RegistrationForm, UpdateAccountForm -from .models import User +from .models import Home, Trap, User """ index.html (home-page) route """ @@ -99,6 +100,15 @@ def account(): image_file = url_for('static', filename='profile_pics/' + current_user.image_file) return render_template('account.html', title='Profiel', image_file=image_file, form=form) [email protected]('/dashboard') +@login_required +def dashboard(): + traps = [] + for home in Home.query.filter((Home.owner == current_user.id) | (Home.catcher == current_user.id)): + for trap in Trap.query.filter_by(home=home.id): + traps.append((home, trap)) + print(traps) + return render_template('dashboard.html', title='Dashboard', traps=traps) """ 404 not found handler """ @app.errorhandler(404) diff --git a/server/site.db b/server/site.db Binary files differ. diff --git a/server/site.db-journal b/server/site.db-journal Binary files differ. diff --git a/server/static/main.css b/server/static/main.css @@ -8,6 +8,7 @@ body { code { font-family: 'Source Code Pro'; + color: inherit; } h1, h2, h3, h4, h5, h6 { diff --git a/server/templates/dashboard.html b/server/templates/dashboard.html @@ -0,0 +1,32 @@ +{% extends "layout.html" %} +{% block content %} +<article class="media content-section"> + <div class="media-body"> + <h2>Dit zijn uw muizenvallen</h2> + <p> + Klik op de titel van een muizenval om de instellingen in te zien! + </p> + </div> +</article> +{% for home, trap in traps %} +<article class="media content-section"> + <div class="media-body"> + <h3><a class="article-title" href="#"> + {% if trap.name %} + {{ trap.name }} <sub><code>{{ trap.mac }}</code></sub> + {% else %} + <code>{{ trap.mac }}</code> + {% endif %} + </a></h3> + <p> + {{ home.adress }} + </p> + <p> + {% if trap.caught %} + <b>(geactiveerd)</b> + {% endif %} + </p> + </div> +</article> +{% endfor %} +{% endblock content %} +\ No newline at end of file diff --git a/server/templates/layout.html b/server/templates/layout.html @@ -9,7 +9,6 @@ integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}"> - <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='openmoji/openmoji.css') }}"> <!-- Google Font: Source Sans Pro --> <link rel="preconnect" href="https://fonts.googleapis.com"> @@ -86,7 +85,7 @@ </li> {% if current_user.type in [ 'client', 'catcher' ] %} <li class="list-group-item list-group-item-light"> - <a href="#">Uw muizenvallen</a> + <a href="{{ url_for('dashboard') }}">Uw muizenvallen</a> </li> {% endif %} {% if current_user.type == 'catcher' %}