[trails] Add auto GPX and FIT file importing
This commit is contained in:
@ -74,11 +74,13 @@ from scrobbles.models import (
|
||||
RetroarchImport,
|
||||
ScaleCSVImport,
|
||||
Scrobble,
|
||||
TrailGPXImport,
|
||||
)
|
||||
from scrobbles.scrobblers import *
|
||||
from scrobbles.tasks import (
|
||||
process_koreader_import,
|
||||
process_lastfm_import,
|
||||
process_trail_gpx_import,
|
||||
process_tsv_import,
|
||||
)
|
||||
from scrobbles.utils import (
|
||||
@ -465,6 +467,9 @@ class ScrobbleImportListView(TemplateView):
|
||||
context_data["scale_csv_imports"] = ScaleCSVImport.objects.filter(
|
||||
user=self.request.user,
|
||||
).order_by("-processing_started")[:10]
|
||||
context_data["trail_gpx_imports"] = TrailGPXImport.objects.filter(
|
||||
user=self.request.user,
|
||||
).order_by("-processing_started")[:10]
|
||||
return context_data
|
||||
|
||||
|
||||
@ -488,6 +493,8 @@ class BaseScrobbleImportDetailView(DetailView):
|
||||
title = "Retroarch Import"
|
||||
if self.model == ScaleCSVImport:
|
||||
title = "Scale CSV Import"
|
||||
if self.model == TrailGPXImport:
|
||||
title = "Trail GPX Import"
|
||||
context_data["title"] = title
|
||||
return context_data
|
||||
|
||||
@ -512,6 +519,10 @@ class ScrobbleScaleCSVImportDetailView(BaseScrobbleImportDetailView):
|
||||
model = ScaleCSVImport
|
||||
|
||||
|
||||
class ScrobbleTrailGPXImportDetailView(BaseScrobbleImportDetailView):
|
||||
model = TrailGPXImport
|
||||
|
||||
|
||||
class ManualScrobbleView(FormView):
|
||||
form_class = ScrobbleForm
|
||||
template_name = "scrobbles/manual_form.html"
|
||||
@ -600,6 +611,23 @@ class ScaleCSVImportCreateView(
|
||||
return HttpResponseRedirect(self.request.META.get("HTTP_REFERER"))
|
||||
|
||||
|
||||
class TrailGPXImportCreateView(
|
||||
LoginRequiredMixin, JsonableResponseMixin, CreateView
|
||||
):
|
||||
model = TrailGPXImport
|
||||
fields = ["gpx_file"]
|
||||
template_name = "scrobbles/upload_form.html"
|
||||
success_url = reverse_lazy("vrobbler-home")
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save(commit=False)
|
||||
self.object.user = self.request.user
|
||||
self.object.original_filename = form.cleaned_data["gpx_file"].name
|
||||
self.object.save()
|
||||
process_trail_gpx_import.delay(self.object.id)
|
||||
return HttpResponseRedirect(self.request.META.get("HTTP_REFERER"))
|
||||
|
||||
|
||||
@api_view(["GET"])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def lastfm_import(request):
|
||||
|
||||
Reference in New Issue
Block a user