initial work, model works, layout doenst

This commit is contained in:
mcbloch 2022-05-20 19:04:32 +02:00 committed by Charlotte Van Petegem
parent f87f3c5446
commit 8a2b9247e1
No known key found for this signature in database
GPG key ID: 019E764B7184435A
4 changed files with 22 additions and 4 deletions

View file

@ -10,5 +10,5 @@ def add() -> None:
"""Add users as admin."""
for username in Configuration.HALDIS_ADMINS:
user = User()
user.configure(username, True, 0)
user.configure(username, True, 0, associations=["zeus"])
db.session.add(user)

View file

@ -1,4 +1,6 @@
"Script for everything User related in the database"
from typing import List
from models import db
@ -8,6 +10,10 @@ class User(db.Model):
username = db.Column(db.String(80), unique=True, nullable=False)
admin = db.Column(db.Boolean)
bias = db.Column(db.Integer)
# Assocation logic
associations = db.Column(db.String(120))
# Relations
runs = db.relation(
"Order",
backref="courier",
@ -16,11 +22,17 @@ class User(db.Model):
)
orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic")
def configure(self, username: str, admin: bool, bias: int) -> None:
"Configure the User"
def association_list(self) -> List[str]:
return self.associations.split(",")
def configure(self, username: str, admin: bool, bias: int, associations: List[str] = None) -> None:
"""Configure the User"""
if associations is None:
associations = []
self.username = username
self.admin = admin
self.bias = bias
self.associations = ",".join(associations)
# pylint: disable=C0111, R0201
def is_authenticated(self) -> bool:

View file

@ -14,6 +14,12 @@
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
{% endif -%}
{% if not current_user.is_anonymous() -%}
{% for association in current_user.association_list() %}
{% set navbar = navbar + [('general_bp.home', association)] -%}
{% endfor -%}
{% endif -%}
{% set active_page = active_page|default('index') -%}
{% block title %}

View file

@ -77,7 +77,7 @@ def login_and_redirect_user(user) -> Response:
def create_user(username) -> User:
"Create a temporary user if it is needed"
user = User()
user.configure(username, False, 1)
user.configure(username, False, 1, associations=["zeus"])
db.session.add(user)
db.session.commit()
return user