mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 22:12:22 +01:00
Multiupload revisited. Select multiple files at once for uploading.
This commit is contained in:
@ -12,7 +12,6 @@ from marietje.utils import song_to_dict, playlist_song_to_dict, send_to_bertha
|
||||
|
||||
from songs.models import Song
|
||||
from queues.models import PlaylistSong, Queue, QueueCommand
|
||||
from .forms import UploadForm
|
||||
|
||||
|
||||
@login_required
|
||||
@ -169,22 +168,27 @@ def request(request):
|
||||
@require_http_methods(["POST"])
|
||||
@login_required
|
||||
def upload(request):
|
||||
form = UploadForm(request.POST, request.FILES)
|
||||
if not form.is_valid():
|
||||
return JsonResponse({
|
||||
'success': False, 'errorMessage': 'File not uploaded correctly.'
|
||||
})
|
||||
files = request.FILES.getlist('file[]')
|
||||
artists = request.POST.getlist('artist[]')
|
||||
titles = request.POST.getlist('title[]')
|
||||
|
||||
file = request.FILES['file']
|
||||
for artist in artists:
|
||||
if not artist:
|
||||
return JsonResponse({'success': False, 'errorMessage': 'Please enter artists which are not empty.'})
|
||||
|
||||
duration = File(file).info.length
|
||||
hash = send_to_bertha(file)
|
||||
song = Song(user=request.user, artist=request.POST.get('artist'), title=request.POST.get('title'), hash=hash, duration=duration)
|
||||
song.save()
|
||||
for title in titles:
|
||||
if not title:
|
||||
return JsonResponse({'success': False, 'errorMessage': 'Please enter titles which are not empty.'})
|
||||
|
||||
return JsonResponse({
|
||||
'success': True
|
||||
})
|
||||
for i, file in enumerate(files):
|
||||
duration = File(file).info.length
|
||||
hash = send_to_bertha(file)
|
||||
if not hash:
|
||||
return JsonResponse({'success': False, 'errorMessage': 'Files not uploaded correctly.'})
|
||||
song = Song(user=request.user, artist=artists[i], title=titles[i], hash=hash, duration=duration)
|
||||
song.save()
|
||||
|
||||
return JsonResponse({'success': True})
|
||||
|
||||
|
||||
@require_http_methods(["POST"])
|
||||
|
||||
Reference in New Issue
Block a user