From 6612a84cd379af09373ffeaab7109696a4cdfa3a Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 18 Nov 2020 01:56:33 +0100 Subject: [PATCH] [System] avatar URL needs to be generated as path might change --- flaschengeist/config.py | 2 +- flaschengeist/models/user.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/flaschengeist/config.py b/flaschengeist/config.py index 100d6e3..1ae840f 100644 --- a/flaschengeist/config.py +++ b/flaschengeist/config.py @@ -47,7 +47,7 @@ def configure_app(app): logging.config.dictConfig(logger_config) if "secret_key" not in config["FLASCHENGEIST"]: - logger.warn("No secret key was configured, please configure one for production systems!") + logger.warning("No secret key was configured, please configure one for production systems!") app.config["SECRET_KEY"] = "0a657b97ef546da90b2db91862ad4e29" else: app.config["SECRET_KEY"] = config["FLASCHENGEIST"]["secret_key"] diff --git a/flaschengeist/models/user.py b/flaschengeist/models/user.py index 57ea213..cd1bfce 100644 --- a/flaschengeist/models/user.py +++ b/flaschengeist/models/user.py @@ -1,6 +1,7 @@ from datetime import date from typing import Optional +from flask import url_for from sqlalchemy.orm.collections import attribute_mapped_collection from . import ModelSerializeMixin @@ -54,9 +55,9 @@ class User(db.Model, ModelSerializeMixin): firstname: str = db.Column(db.String(50), nullable=False) lastname: str = db.Column(db.String(50), nullable=False) mail: str = db.Column(db.String(60), nullable=False) - avatar_url: Optional[str] = db.Column(db.String(60)) birthday: Optional[date] = db.Column(db.Date) roles: [str] = [] + avatar_url: Optional[str] = "" roles_: [Role] = db.relationship("Role", secondary=association_table, cascade="save-update, merge") _id = db.Column("id", db.Integer, primary_key=True) @@ -65,6 +66,10 @@ class User(db.Model, ModelSerializeMixin): "_UserAttribute", collection_class=attribute_mapped_collection("name"), cascade="all, delete" ) + @property + def avatar_url(self): + return url_for('users.get_avatar', userid=self.userid) + @property def roles(self): return [role.name for role in self.roles_]