Exemplo n.º 1
0
def upload(request):
    ticket = request.session.get('vimeo_ticket', None)
    form = VideoForm(request.POST or None)
    if ticket and request.method == 'POST' and form.is_valid():
        # Verify that the filesize from the client matches what vimeo received.
        # Some browsers don't provide this number, so we can't really verify.
        filesize = form.cleaned_data['filesize']
        if filesize and not vimeo.verify_chunks(ticket['id'], filesize):
            return upload_error(request)

        ticket = vimeo.complete_upload(ticket['id'],
                                       form.cleaned_data['filename'])

        # Create video and schedule it for processing.
        video = form.save(commit=False)
        video.user = request.user
        video.vimeo_id = ticket['video_id']
        video.save()
        tasks.process_video.delay(video.id)

        del request.session['vimeo_ticket']
        return redirect('flicks.videos.upload_complete')

    # Generate an upload token if one doesn't exist or isn't valid.
    if not ticket or not vimeo.is_ticket_valid(ticket['id']):
        ticket = vimeo.get_new_ticket()
        request.session['vimeo_ticket'] = ticket

    return render(request, 'videos/upload.html', {
        'ticket': ticket,
        'form': form
    })
Exemplo n.º 2
0
def upload(request):
    ticket = request.session.get('vimeo_ticket', None)
    form = VideoForm(request.POST or None)
    if ticket and request.method == 'POST' and form.is_valid():
        # Verify that the filesize from the client matches what vimeo received.
        # Some browsers don't provide this number, so we can't really verify.
        filesize = form.cleaned_data['filesize']
        if filesize and not vimeo.verify_chunks(ticket['id'], filesize):
            return upload_error(request)

        ticket = vimeo.complete_upload(ticket['id'],
                                       form.cleaned_data['filename'])

        # Create video and schedule it for processing.
        video = form.save(commit=False)
        video.user = request.user
        video.vimeo_id = ticket['video_id']
        video.save()
        tasks.process_video.delay(video.id)

        del request.session['vimeo_ticket']
        return redirect('flicks.videos.upload_complete')

    # Generate an upload token if one doesn't exist or isn't valid.
    if not ticket or not vimeo.is_ticket_valid(ticket['id']):
        ticket = vimeo.get_new_ticket()
        request.session['vimeo_ticket'] = ticket

    return render(request, 'videos/upload.html', {
        'ticket': ticket,
        'form': form
    })
Exemplo n.º 3
0
 def test_is_ticket_valid_failure(self, _ticket_request):
     """If VimeoTicketInvalid is thrown, return False."""
     _ticket_request.side_effect = vimeo.VimeoTicketInvalid
     eq_(vimeo.is_ticket_valid('id'), False)
Exemplo n.º 4
0
 def test_is_ticket_valid(self, _ticket_request):
     """If VimeoTicketInvalid is not thrown, return True."""
     _ticket_request.return_value = {'stat': 'ok'}
     eq_(vimeo.is_ticket_valid('id'), True)
Exemplo n.º 5
0
 def test_is_ticket_valid_failure(self, _ticket_request):
     """If VimeoTicketInvalid is thrown, return False."""
     _ticket_request.side_effect = vimeo.VimeoTicketInvalid
     eq_(vimeo.is_ticket_valid('id'), False)
Exemplo n.º 6
0
 def test_is_ticket_valid(self, _ticket_request):
     """If VimeoTicketInvalid is not thrown, return True."""
     _ticket_request.return_value = {'stat': 'ok'}
     eq_(vimeo.is_ticket_valid('id'), True)