コード例 #1
0
def list_saved_files(request):
    # Handle file upload
    if request.method == 'POST':

        # https://docs.djangoproject.com/en/dev/ref/request-response
        #
        # request.POST: A dictionary-like object containing all given
        # HTTP POST parameters, providing that the request contains form data.
        # Note: POST does *not* include file-upload information.
        #
        # request.FILES: A dictionary-like object containing all uploaded files.
        # Each key in FILES is the name from the <input type="file" name="" />.
        # Each value in FILES is an UploadedFile.
        # Note: This only has data if the <form> that POSTed had enctype="multipart/form-data"
        form = RecordingForm(request.POST, request.FILES)
        if form.is_valid():
            newrec = Recording(audiofile=request.FILES['audiofile'])
            newrec.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('Conversation.v1.views.list'))
    else:
        form = RecordingForm()  # An empty, unbound form

    # Load documents for the list page
    recordings = Recording.objects.all()

    # Render list page with the documents and the form
    return render_to_response('v1/list.html', {
        'recordings': recordings,
        'form': form
    },
                              context_instance=RequestContext(request))
コード例 #2
0
def list_saved_files(request):
    # Handle file upload
    if request.method == 'POST':

        # https://docs.djangoproject.com/en/dev/ref/request-response
        #
        # request.POST: A dictionary-like object containing all given
        # HTTP POST parameters, providing that the request contains form data.
        # Note: POST does *not* include file-upload information.
        #
        # request.FILES: A dictionary-like object containing all uploaded files.
        # Each key in FILES is the name from the <input type="file" name="" />.
        # Each value in FILES is an UploadedFile.
        # Note: This only has data if the <form> that POSTed had enctype="multipart/form-data"
        form = RecordingForm(request.POST, request.FILES)
        if form.is_valid():
            newrec = Recording(audiofile=request.FILES['audiofile'])
            newrec.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('Conversation.v1.views.list'))
    else:
        form = RecordingForm()  # An empty, unbound form

    # Load documents for the list page
    recordings = Recording.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'v1/list.html',
        {'recordings': recordings, 'form': form},
        context_instance=RequestContext(request)
    )
コード例 #3
0
ファイル: spa_api.py プロジェクト: halfvector/quips-python
def save_new_recording():
    parser = reqparse.RequestParser()
    parser.add_argument('audio-blob', type=FileStorage, location='files')
    parser.add_argument('description')
    form = parser.parse_args()

    file = form['audio-blob']
    current_app.logger.debug("file: '%s' type: '%s'" % (file.filename, file.content_type))

    if file and file.content_type == 'audio/ogg':
        user = User.objects.get(id=g.user['id'])

        recording = Recording()
        recording.description = form['description']
        recording.isPublic = True
        recording.user = user
        recording.save()

        recording_id = str(recording.id)
        recording_path = os.path.join(current_app.config['RECORDINGS_PATH'], recording_id + '.ogg')
        current_app.logger.debug('saving recording to: ' + recording_path)
        file.save(recording_path)

        tiny_id = tinyurl.encode(str(recording_id))

        url = url_for('spa_web.single_recording', recording_id=tiny_id)
        return {'status': 'success', 'url': url}

    # else file upload failed, show an error page
    return {'status': 'failed'}
コード例 #4
0
def recorder_screen(request):
    if request.method == 'POST':
        newrec = Recording(audiofile=request.FILES['recording'])
        newrec.save()
        return HttpResponseRedirect(
            reverse('Conversation.v1.views.recorder_screen'))
    else:
        form = RecordingForm()

    return render_to_response('v1/Audio Recorder.html', {'form': form},
                              context_instance=RequestContext(request))
コード例 #5
0
def recorder_screen(request):
    if request.method == 'POST':
        newrec = Recording(audiofile=request.FILES['recording'])
        newrec.save()
        return HttpResponseRedirect(reverse('Conversation.v1.views.recorder_screen'))
    else:
        form = RecordingForm()

    return render_to_response(
        'v1/Audio Recorder.html',
        {'form' : form},
        context_instance=RequestContext(request)
    )