Ejemplo 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
    })
Ejemplo 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
    })
Ejemplo n.º 3
0
    def test_get_new_ticket(self, _vimeo_request):
        _vimeo_request.return_value = {'stat': 'ok', 'ticket': 'returnvalue'}

        eq_(vimeo.get_new_ticket(), 'returnvalue')
        _vimeo_request.assert_called_with('vimeo.videos.upload.getTicket',
                                          'POST',
                                          upload_method='post')
Ejemplo n.º 4
0
    def test_get_new_ticket_fail(self, logger, _vimeo_request):
        """If retrieving a new ticket fails, return False."""
        _vimeo_request.return_value = {
            'stat': 'fail',
            'err': {'code': '701', 'msg': 'test msg', 'expl': 'test_expl'}
        }

        eq_(vimeo.get_new_ticket(), False)
        ok_(logger.error.called)
Ejemplo n.º 5
0
    def test_get_new_ticket_fail(self, logger, _vimeo_request):
        """If retrieving a new ticket fails, return False."""
        _vimeo_request.return_value = {
            'stat': 'fail',
            'err': {
                'code': '701',
                'msg': 'test msg',
                'expl': 'test_expl'
            }
        }

        eq_(vimeo.get_new_ticket(), False)
        ok_(logger.error.called)
Ejemplo n.º 6
0
    def test_get_new_ticket(self, _vimeo_request):
        _vimeo_request.return_value = {'stat': 'ok', 'ticket': 'returnvalue'}

        eq_(vimeo.get_new_ticket(), 'returnvalue')
        _vimeo_request.assert_called_with('vimeo.videos.upload.getTicket',
                                          'POST', upload_method='post')