hanze/muizenval

pre-merge (a798858f7bd5a8cace08d61c9eb69e9cbb9623ca)
Repositories

commit a798858f7bd5a8cace08d61c9eb69e9cbb9623ca
parent 5f2198f05cf0c851519a4f455925ff0c5d86fdb7
Author: Friedel Schön <[email protected]>
Date:   Thu, 12 May 2022 19:10:44 +0200

pre-merge

Diffstat:
Aadd-user.py34++++++++++++++++++++++++++++++++++
Mserver/forms.py5++---
Mserver/models.py7++++---
Mserver/routes.py5++---
Mserver/site.db0
Mserver/static/main.css13++++++++-----
Mserver/templates/layout.html28+++++++++++++++++++++-------
7 files changed, 71 insertions(+), 21 deletions(-)

diff --git a/add-user.py b/add-user.py @@ -0,0 +1,34 @@ +from random import randint +from server.app import db, bcrypt +from server.models import User, UserType + +#name = input('Naam? ') +#email = input('E-Mail? ') +#typ = input('Type [admin,manager,technician,catcher,client]? ') + +users = [ + (UserType.CLIENT, 'Boer Herman', '[email protected]'), + (UserType.CATCHER, 'Vanger Kees', '[email protected]'), + (UserType.TECHNICIAN, 'Technicus Jos', '[email protected]'), + (UserType.MANAGER, 'Manager Peter', '[email protected]'), + (UserType.ADMIN, 'Administrator Ralf', '[email protected]'), +] + +address = 'Kerklaan 69\n9876XY Groningen' + +hashed_password = bcrypt.generate_password_hash('hallo').decode('utf-8') + +for typ, name, email in users: + phone = '06-' + str(randint(10000000, 99999999)) + user = User( + type=typ, + name=name, + email=email, + password=hashed_password, + phone=phone, + address = address + ) + db.session.add(user) + +db.session.commit() +print('Added') diff --git a/server/forms.py b/server/forms.py @@ -4,7 +4,7 @@ from flask_wtf.file import FileAllowed, FileField from wtforms import BooleanField, HiddenField, PasswordField, SelectField, StringField, SubmitField, IntegerField from wtforms.validators import DataRequired, Email, EqualTo, Length, ValidationError -from .models import User, UserType +from .models import User """ registration form for register.html """ class RegistrationForm(FlaskForm): @@ -32,14 +32,13 @@ class RegistrationForm(FlaskForm): def validate_phone(self, phone): for c in phone.data: - if c not in '0123456789 -': + if c not in '0123456789- ': raise ValidationError('Dit belnummer is niet geldig.') def validate_postcode(self, code): if len(code.data) != 6 or not code.data[0:4].isnumeric() or not code.data[4:6].isalpha(): raise ValidationError('De postcode is niet geldig.') - def validate_catcher_code(self, code): pass #if not User.query.filter_by(type=UserType.CATCHER, catcher_code=code.data).first(): diff --git a/server/models.py b/server/models.py @@ -9,7 +9,6 @@ from .app import db, login_manager def load_user(user_id): return User.query.get(int(user_id)) - class UserType(Enum): ADMIN = 0 MANAGER = 1 @@ -27,9 +26,11 @@ class User(db.Model, UserMixin): phone = db.Column(db.Text, nullable=False) address = db.Column(db.Text) - manager = db.Column(db.Integer, db.ForeignKey('user.id')) # set if technician, catcher, user + contact = db.Column(db.Integer, db.ForeignKey('user.id')) # set if technician, catcher, user catcher_code = db.Column(db.String(5)) # set if catcher - catcher = db.Column(db.Integer, db.ForeignKey('user.id')) # set if user + + def contact_class(self): + return User.query.filter_by(id=self.contact).first() class Trap(db.Model): diff --git a/server/routes.py b/server/routes.py @@ -5,8 +5,6 @@ import secrets from flask import flash, redirect, render_template, request, url_for, abort, request, jsonify from flask_login import current_user, login_required, login_user, logout_user from PIL import Image -from calendar import Calendar as Month -from datetime import datetime from .app import app, bcrypt, db from .forms import LoginForm, RegistrationForm, UpdateAccountForm @@ -132,6 +130,7 @@ def account(): db.session.commit() flash('Uw profiel is bewerkt!', 'success') return redirect(url_for('account')) + elif request.method == 'GET': form.name.data = current_user.name form.email.data = current_user.email @@ -143,7 +142,7 @@ def account(): def dashboard(): query = [ current_user ] if current_user.type == UserType.CATCHER: - query += list(User.query.filter_by(catcher=current_user.id)) + query += list(User.query.filter_by(contact=current_user.id)) traps = [ trap for user in query for trap in Trap.query.filter_by(owner=user.id) ] diff --git a/server/site.db b/server/site.db Binary files differ. diff --git a/server/static/main.css b/server/static/main.css @@ -16,13 +16,16 @@ h1, h2, h3, h4, h5, h6 { } nav { -/* background-color: #33bc85; */ + /*2a4b98, 2a4583 + 2a9a6d, 2a825f + h: 156*/ + background: repeating-linear-gradient( 45deg, - #33bc85, - #33bc85 10px, - #2a825f 10px, - #2a825f 20px + hsl(156, 57%, 38%), + hsl(156, 57%, 38%) 10px, + hsl(156, 51%, 34%) 10px, + hsl(156, 51%, 34%) 20px ); color: #fff; font-size: 15pt; diff --git a/server/templates/layout.html b/server/templates/layout.html @@ -10,7 +10,7 @@ <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}"> - <!-- Google Font: Source Sans Pro --> + <!-- Google Font: Source Sans Pro, Source Code Pro --> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link @@ -32,7 +32,6 @@ </a> <div class="collapse navbar-collapse" id="navbarToggle"> <div class="navbar-nav mr-auto"> - <a class="nav-item nav-link" href="#">Shop</a> <a class="nav-item nav-link" href="{{ url_for('about') }}">Over ons</a> <a class="nav-item nav-link" href="{{ url_for('producten') }}">Producten</a> </div> @@ -52,15 +51,11 @@ <main role="main" class="container"> <div class="row"> <div class="col-md-8"> - {% with messages = get_flashed_messages(with_categories=true) %} - {% if messages %} - {% for category, message in messages %} + {% for category, message in get_flashed_messages(with_categories=true) %} <div class="alert alert-{{ category }}"> {{ message }} </div> {% endfor %} - {% endif %} - {% endwith %} {% block content %}{% endblock %} </div> <div class="col-md-4"> @@ -107,6 +102,25 @@ </p> {% endif %} </div> + <div class="content-section"> + <h3>Contact</h3> + {% if current_user.type.name == 'CLIENT' %} + {% with contact = current_user.contact_class() %} + <h5> + <b>{{ contact.name }}</b> + </h5> + <p> + E-Mail: <a href="mailto:{{ contact.email }}">{{ contact.email }}</a><br> + Tel.: {{ contact.phone }} + </p> + <p> + {% autoescape false %} + {{ contact.address | replace('\n', '<br>') }}<br> + {% endautoescape %} + </p> + {% endwith %} + {% endif %} + </div> </div> </div> </main>