[tasks] Add weigh-in task importer
All checks were successful
build & deploy / test (push) Successful in 1m48s
build & deploy / build-and-deploy (push) Successful in 33s

This commit is contained in:
2026-05-21 09:09:41 -04:00
parent 2b88f89794
commit 9d3f7f434f
9 changed files with 307 additions and 0 deletions

View File

@ -260,6 +260,45 @@ class AudioScrobblerTSVImport(BaseFileImportMixin):
self.mark_finished()
class ScaleCSVImport(BaseFileImportMixin):
class Meta:
verbose_name = "Scale CSV Import"
@property
def import_type(self) -> str:
return "Scale"
def get_absolute_url(self):
return reverse("scrobbles:scale-csv-import-detail", kwargs={"slug": self.uuid})
def get_path(instance, filename):
extension = filename.split(".")[-1]
uuid = instance.uuid
return f"scale-csv-uploads/{uuid}.{extension}"
@property
def upload_file_path(self):
if getattr(settings, "USE_S3_STORAGE"):
path = self.csv_file.url
else:
path = self.csv_file.path
return path
csv_file = models.FileField(upload_to=get_path, **BNULL)
def process(self, force=False):
from scrobbles.importers.scale import import_scale_csv
if self.processed_finished and not force:
logger.info(f"{self} already processed on {self.processed_finished}")
return
self.mark_started()
scrobbles = import_scale_csv(self.upload_file_path, self.user.id)
self.record_log(scrobbles)
self.mark_finished()
class LastFmImport(BaseFileImportMixin):
class Meta:
verbose_name = "Last.FM Import"