[trails] Add auto GPX and FIT file importing
This commit is contained in:
@ -299,6 +299,48 @@ class ScaleCSVImport(BaseFileImportMixin):
|
||||
self.mark_finished()
|
||||
|
||||
|
||||
class TrailGPXImport(BaseFileImportMixin):
|
||||
class Meta:
|
||||
verbose_name = "Trail GPX Import"
|
||||
|
||||
@property
|
||||
def import_type(self) -> str:
|
||||
return "Trail GPX"
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("scrobbles:trail-gpx-import-detail", kwargs={"slug": self.uuid})
|
||||
|
||||
def get_path(instance, filename):
|
||||
extension = filename.split(".")[-1]
|
||||
uuid = instance.uuid
|
||||
return f"trail-gpx-uploads/{uuid}.{extension}"
|
||||
|
||||
@property
|
||||
def upload_file_path(self):
|
||||
if getattr(settings, "USE_S3_STORAGE"):
|
||||
path = self.gpx_file.url
|
||||
else:
|
||||
path = self.gpx_file.path
|
||||
return path
|
||||
|
||||
gpx_file = models.FileField(upload_to=get_path, **BNULL)
|
||||
original_filename = models.CharField(max_length=255, **BNULL)
|
||||
|
||||
def process(self, force=False):
|
||||
from scrobbles.importers.trail_gpx import import_trail_gpx
|
||||
|
||||
if self.processed_finished and not force:
|
||||
logger.info(f"{self} already processed on {self.processed_finished}")
|
||||
return
|
||||
|
||||
self.mark_started()
|
||||
scrobbles = import_trail_gpx(
|
||||
self.upload_file_path, self.user.id, self.original_filename
|
||||
)
|
||||
self.record_log(scrobbles)
|
||||
self.mark_finished()
|
||||
|
||||
|
||||
class LastFmImport(BaseFileImportMixin):
|
||||
class Meta:
|
||||
verbose_name = "Last.FM Import"
|
||||
|
||||
Reference in New Issue
Block a user