Beispiel #1
0
def describe(request):
    file_structure, files = generate_tree(os.path.join(settings.UPLOADS_PATH, str(request.user.id)))
    file_structure.name = ''

    if request.method == 'POST':
        form = FileChoiceForm(files, request.POST)
        if form.is_valid():
            if "delete" in request.POST:
                filenames = [files[x].name for x in form.cleaned_data["files"]]
                tvars = {'form': form, 'filenames': filenames}
                return render(request, 'accounts/confirm_delete_undescribed_files.html', tvars)
            elif "delete_confirm" in request.POST:
                for f in form.cleaned_data["files"]:
                    os.remove(files[f].full_path)
                return HttpResponseRedirect(reverse('accounts-describe'))
            elif "describe" in request.POST:
                request.session['describe_sounds'] = [files[x] for x in form.cleaned_data["files"]]
                # If only one file is choosen, go straight to the last step of the describe process,
                # otherwise go to license selection step
                if len(request.session['describe_sounds']) > 1:
                    return HttpResponseRedirect(reverse('accounts-describe-license'))
                else:
                    return HttpResponseRedirect(reverse('accounts-describe-sounds'))
            else:
                form = FileChoiceForm(files)
                tvars = {'form': form, 'file_structure': file_structure}
                return render(request, 'accounts/describe.html', tvars)
    else:
        form = FileChoiceForm(files)
    tvars = {'form': form, 'file_structure': file_structure}
    return render(request, 'accounts/describe.html', tvars)
Beispiel #2
0
def describe(request):

    file_structure, files = generate_tree(os.path.join(settings.UPLOADS_PATH, str(request.user.id)))
    file_structure.name = 'Your uploaded files'

    if request.method == 'POST':
        form = FileChoiceForm(files, request.POST)
        
        if form.is_valid():
            if "delete" in request.POST: # If delete button is pressed
                filenames = [files[x].name for x in form.cleaned_data["files"]]
                return render_to_response('accounts/confirm_delete_undescribed_files.html', locals(), context_instance=RequestContext(request))
            elif "delete_confirm" in request.POST: # If confirmation delete button is pressed
                for file in form.cleaned_data["files"]:
                    os.remove(files[file].full_path)
                return HttpResponseRedirect(reverse('accounts-describe'))
            elif "describe" in request.POST: # If describe button is pressed
                # If only one file is choosen, go straight to the last step of the describe process, otherwise go to license selection step
                if len(form.cleaned_data["files"]) > 1 :
                    request.session['describe_sounds'] = [files[x] for x in form.cleaned_data["files"]]
                    return HttpResponseRedirect(reverse('accounts-describe-license'))
                else :
                    request.session['describe_sounds'] = [files[x] for x in form.cleaned_data["files"]]
                    return HttpResponseRedirect(reverse('accounts-describe-sounds'))
            else:
                form = FileChoiceForm(files) # Reset form
                return render_to_response('accounts/describe.html', locals(), context_instance=RequestContext(request))
    else:
        form = FileChoiceForm(files)
    return render_to_response('accounts/describe.html', locals(), context_instance=RequestContext(request))