API - allow deleting workout when gpx or map files missing - fix #193

This commit is contained in:
Sam
2022-06-22 14:30:58 +02:00
parent 9c2ba31b96
commit 111bfb725f
2 changed files with 45 additions and 18 deletions

View File

@ -12,7 +12,7 @@ from sqlalchemy.orm.mapper import Mapper
from sqlalchemy.orm.session import Session, object_session
from sqlalchemy.types import JSON, Enum
from fittrackee import db
from fittrackee import appLog, db
from fittrackee.files import get_absolute_file_path
from .utils.convert import convert_in_duration, convert_value_to_integer
@ -379,9 +379,15 @@ def on_workout_delete(
@listens_for(db.Session, 'after_flush', once=True)
def receive_after_flush(session: Session, context: Any) -> None:
if old_record.map:
os.remove(get_absolute_file_path(old_record.map))
try:
os.remove(get_absolute_file_path(old_record.map))
except OSError:
appLog.error('map file not find when deleting workout')
if old_record.gpx:
os.remove(get_absolute_file_path(old_record.gpx))
try:
os.remove(get_absolute_file_path(old_record.gpx))
except OSError:
appLog.error('gpx file not find when deleting workout')
class WorkoutSegment(BaseModel):