initial work, model works, layout doenst
This commit is contained in:
parent
f87f3c5446
commit
8a2b9247e1
4 changed files with 22 additions and 4 deletions
|
@ -10,5 +10,5 @@ def add() -> None:
|
||||||
"""Add users as admin."""
|
"""Add users as admin."""
|
||||||
for username in Configuration.HALDIS_ADMINS:
|
for username in Configuration.HALDIS_ADMINS:
|
||||||
user = User()
|
user = User()
|
||||||
user.configure(username, True, 0)
|
user.configure(username, True, 0, associations=["zeus"])
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"Script for everything User related in the database"
|
"Script for everything User related in the database"
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from models import db
|
from models import db
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +10,10 @@ class User(db.Model):
|
||||||
username = db.Column(db.String(80), unique=True, nullable=False)
|
username = db.Column(db.String(80), unique=True, nullable=False)
|
||||||
admin = db.Column(db.Boolean)
|
admin = db.Column(db.Boolean)
|
||||||
bias = db.Column(db.Integer)
|
bias = db.Column(db.Integer)
|
||||||
|
# Assocation logic
|
||||||
|
associations = db.Column(db.String(120))
|
||||||
|
|
||||||
|
# Relations
|
||||||
runs = db.relation(
|
runs = db.relation(
|
||||||
"Order",
|
"Order",
|
||||||
backref="courier",
|
backref="courier",
|
||||||
|
@ -16,11 +22,17 @@ class User(db.Model):
|
||||||
)
|
)
|
||||||
orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic")
|
orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic")
|
||||||
|
|
||||||
def configure(self, username: str, admin: bool, bias: int) -> None:
|
def association_list(self) -> List[str]:
|
||||||
"Configure the User"
|
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.username = username
|
||||||
self.admin = admin
|
self.admin = admin
|
||||||
self.bias = bias
|
self.bias = bias
|
||||||
|
self.associations = ",".join(associations)
|
||||||
|
|
||||||
# pylint: disable=C0111, R0201
|
# pylint: disable=C0111, R0201
|
||||||
def is_authenticated(self) -> bool:
|
def is_authenticated(self) -> bool:
|
||||||
|
|
|
@ -14,6 +14,12 @@
|
||||||
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
|
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
|
||||||
{% endif -%}
|
{% 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') -%}
|
{% set active_page = active_page|default('index') -%}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
|
|
|
@ -77,7 +77,7 @@ def login_and_redirect_user(user) -> Response:
|
||||||
def create_user(username) -> User:
|
def create_user(username) -> User:
|
||||||
"Create a temporary user if it is needed"
|
"Create a temporary user if it is needed"
|
||||||
user = User()
|
user = User()
|
||||||
user.configure(username, False, 1)
|
user.configure(username, False, 1, associations=["zeus"])
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return user
|
return user
|
||||||
|
|
Loading…
Reference in a new issue