From b6260615d876ae81f13d0590b815711e9ef8be98 Mon Sep 17 00:00:00 2001 From: Alexander-D-Karpov Date: Fri, 11 Aug 2023 18:12:01 +0300 Subject: [PATCH] fixed music local file upload --- akarpov/music/admin.py | 9 +++++++ .../music/migrations/0006_tempfileupload.py | 27 +++++++++++++++++++ akarpov/music/models.py | 4 +++ akarpov/music/views.py | 8 +++--- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 akarpov/music/migrations/0006_tempfileupload.py diff --git a/akarpov/music/admin.py b/akarpov/music/admin.py index e69de29..6383daf 100644 --- a/akarpov/music/admin.py +++ b/akarpov/music/admin.py @@ -0,0 +1,9 @@ +from django.contrib import admin + +from akarpov.music.models import Album, Author, Playlist, PlaylistSong, Song + +admin.site.register(Author) +admin.site.register(Album) +admin.site.register(Song) +admin.site.register(Playlist) +admin.site.register(PlaylistSong) diff --git a/akarpov/music/migrations/0006_tempfileupload.py b/akarpov/music/migrations/0006_tempfileupload.py new file mode 100644 index 0000000..7ae46ec --- /dev/null +++ b/akarpov/music/migrations/0006_tempfileupload.py @@ -0,0 +1,27 @@ +# Generated by Django 4.2.4 on 2023-08-11 15:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("music", "0005_radiosong_start"), + ] + + operations = [ + migrations.CreateModel( + name="TempFileUpload", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("file", models.FileField(upload_to="music_tmp")), + ], + ), + ] diff --git a/akarpov/music/models.py b/akarpov/music/models.py index 6a92a93..7294a79 100644 --- a/akarpov/music/models.py +++ b/akarpov/music/models.py @@ -85,6 +85,10 @@ class SongInQue(models.Model): error = models.BooleanField(default=False) +class TempFileUpload(models.Model): + file = models.FileField(upload_to="music_tmp") + + class RadioSong(models.Model): start = models.DateTimeField(auto_now=True) slug = models.SlugField(unique=True) diff --git a/akarpov/music/views.py b/akarpov/music/views.py index 9926398..22acfdb 100644 --- a/akarpov/music/views.py +++ b/akarpov/music/views.py @@ -2,7 +2,7 @@ from akarpov.common.views import SuperUserRequiredMixin from akarpov.music.forms import FileUploadForm, TracksLoadForm -from akarpov.music.models import Album, Author, Playlist, Song +from akarpov.music.models import Album, Author, Playlist, Song, TempFileUpload from akarpov.music.services.base import load_track_file, load_tracks @@ -64,14 +64,16 @@ def form_valid(self, form): class LoadTrackFileView(SuperUserRequiredMixin, generic.FormView): form_class = FileUploadForm + template_name = "music/upload.html" def get_success_url(self): # TODO: add room to see tracks load return "" def form_valid(self, form): - for path in [x.path for x in form.cleaned_data["file"]]: - load_track_file(path) + for file in form.cleaned_data["file"]: + t = TempFileUpload.objects.create(file=file) + load_track_file(t.file.path) return super().form_valid(form)