Use pathlib where possible

This commit is contained in:
Patrick Jentsch
2024-03-07 15:49:04 +01:00
parent ec23bd94ee
commit 9da74c1c6f
21 changed files with 164 additions and 167 deletions

View File

@ -1,6 +1,6 @@
from flask import current_app
from flask_hashids import HashidMixin
import os
from pathlib import Path
from app import db
from .file_mixin import FileMixin
@ -15,14 +15,16 @@ class Avatar(HashidMixin, FileMixin, db.Model):
user = db.relationship('User', back_populates='avatar')
@property
def path(self):
return os.path.join(self.user.path, 'avatar')
def path(self) -> Path:
return self.user.path / 'avatar'
# return os.path.join(self.user.path, 'avatar')
def delete(self):
try:
os.remove(self.path)
self.path.unlink(missing_ok=True)
except OSError as e:
current_app.logger.error(e)
raise
db.session.delete(self)
def to_json_serializeable(self, backrefs=False, relationships=False):