mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-22 01:36:33 +03:00
fixed music local file upload
This commit is contained in:
parent
ec120e5883
commit
b6260615d8
|
@ -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)
|
27
akarpov/music/migrations/0006_tempfileupload.py
Normal file
27
akarpov/music/migrations/0006_tempfileupload.py
Normal file
|
@ -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")),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user