Beispiel #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
    })
Beispiel #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
    })
Beispiel #3
0
def redirects_(response, to, request=None, permanent=False, locale=None):
    """
    Asserts that the given response redirects to the location specified by to.

    :param response:
        Response that should be redirecting.
    :param to:
        Path that the response should redirect to. Accepts a view name or url.
    :param request:
        Request that generated the response being tested. Required in cases
        where the redirect was generated by a request, which affects the value
        of the Location header.

        If none is given, a sample request will be generated and used. This
        should handle the common case of testing a response from the test
        client.
    :param permanent:
        If true, check for a 301 redirect instead of a 302 redirect. Defaults to
        False.
    """
    # We're going to cheat and piggyback on redirect's lovely handling of the
    # `to` argument.
    with lang_activate(locale):
        expected = redirect(to, permanent=permanent)

    # Fix location header for both requests so we can compare.
    if not request:
        request = RequestFactory().get(expected['Location'])
    expected = fix_location_header(request, expected)
    response = fix_location_header(request, response)

    eq_(expected.status_code, response.status_code)
    eq_(expected['Location'], response['Location'])
Beispiel #4
0
def winners(request):
    """Winners page."""
    if not waffle.flag_is_active(request, 'winners_page'):
        return redirect('flicks.videos.recent')

    d = dict(
        awards={},
        category_choices=WINNER_CATEGORIES,
        page_type='winners'
    )

    # Add awards to template context
    grand_prize_awards = Award.objects.filter(award_type='grand_winner')
    for a in grand_prize_awards:
        key = '{0}__{1}'.format(a.award_type, a.region)
        d['awards'][key] = a

    awards = Award.objects.filter(award_type__in=['category_winner',
                                                  'runner_up'])
    for a in awards:
        key = '{0}__{1}__{2}'.format(a.award_type, a.region, a.category)
        d['awards'][key] = a

    d['awards']['panavision'] = Award.objects.filter(award_type='panavision')
    d['awards']['bavc'] = Award.objects.get(award_type='bavc')

    return render(request, 'videos/winners.html', d)
Beispiel #5
0
def redirects_(response, to, request=None, permanent=False, locale=None):
    """
    Asserts that the given response redirects to the location specified by to.

    :param response:
        Response that should be redirecting.
    :param to:
        Path that the response should redirect to. Accepts a view name or url.
    :param request:
        Request that generated the response being tested. Required in cases
        where the redirect was generated by a request, which affects the value
        of the Location header.

        If none is given, a sample request will be generated and used. This
        should handle the common case of testing a response from the test
        client.
    :param permanent:
        If true, check for a 301 redirect instead of a 302 redirect. Defaults to
        False.
    """
    # We're going to cheat and piggyback on redirect's lovely handling of the
    # `to` argument.
    with lang_activate(locale):
        expected = redirect(to, permanent=permanent)

    # Fix location header for both requests so we can compare.
    if not request:
        request = RequestFactory().get(expected['Location'])
    expected = fix_location_header(request, expected)
    response = fix_location_header(request, response)

    eq_(expected.status_code, response.status_code)
    eq_(expected['Location'], response['Location'])
Beispiel #6
0
def verify(request):
    """Process login."""
    form = BrowserIDForm(request.POST)
    if form.is_valid():
        assertion = form.cleaned_data['assertion']
        user = auth.authenticate(assertion=assertion,
                                 audience=get_audience(request))
        if user is not None and user.is_active:
            auth.login(request, user)

            # Redirect to edit profile page if user has no profile.
            if UserProfile.objects.filter(pk=user.pk).exists():
                return redirect(settings.LOGIN_REDIRECT)
            else:
                return redirect('flicks.users.edit_profile')

    # TODO: Determine how to convey login failure.
    return redirect(settings.LOGIN_REDIRECT_FAILURE)
Beispiel #7
0
def home(request):
    """Landing page for Flicks. Displays only the promo videos."""
    # Redirect logged in users to the recent videos page.
    if request.user.is_active:
        return redirect('flicks.videos.recent')

    d = dict(promo_dance=promo_video_shortlink('dance'),
             promo_noir=promo_video_shortlink('noir'),
             promo_twilight=promo_video_shortlink('twilight'),
             page_type='home')

    return render(request, 'home.html', d)
Beispiel #8
0
def profile(request):
    """Display and process the profile creation form."""
    form = UserProfileForm(request.POST or None)
    if request.method == 'POST' and form.is_valid():
        profile = form.save(commit=False)
        profile.user = request.user
        profile.locale = get_language()
        profile.save()

        if form.cleaned_data['mailing_list_signup']:
            format = form.cleaned_data['mailing_list_format']
            newsletter_subscribe.delay(request.user.email,
                                       source_url=request.build_absolute_uri(),
                                       format=format)

        return redirect('flicks.videos.upload')

    return render(request, 'users/profile.html', {
        'form': form,
        'regions': regions,
    })
Beispiel #9
0
def edit_profile(request):
    """Create and/or edit a user profile."""
    profile = get_object_or_none(UserProfile, pk=request.user.pk)
    if request.method == 'POST':
        if profile:
            form = UserProfileEditForm(request.POST, instance=profile)
        else:
            form = UserProfileCreateForm(request.POST, instance=profile)
        if form.is_valid():
            profile = form.save(commit=False)
            profile.user = request.user
            profile.save()
            return redirect('flicks.users.my_profile')
    else:
        if profile:
            form = UserProfileEditForm(instance=profile)
        else:
            form = UserProfileCreateForm(instance=profile)

    d = dict(profile=profile,
             edit_form=form,
             page_type='secondary form')

    return render(request, 'users/edit_profile.html', d)
Beispiel #10
0
def redirect_to(name):
    return lambda request: redirect(name)
Beispiel #11
0
def my_profile(request):
    """Quick link to your profile that avoids referring by user_id."""
    return redirect('flicks.users.details', args=[request.user.pk])
Beispiel #12
0
 def wrapped(request, *args, **kwargs):
     if not request.user.profile:
         return redirect('flicks.users.profile')
     return func(request, *args, **kwargs)
 def wrapped(request, *args, **kwargs):
     if not request.user.profile:
         return redirect('flicks.users.profile')
     return func(request, *args, **kwargs)
Beispiel #14
0
 def test_url(self):
     with self.activate('en-US'):
         response = redirect('/some/url')
     eq_(response.status_code, 302)
     eq_(response['Location'], '/some/url')
Beispiel #15
0
 def test_permanent(self):
     with self.activate('en-US'):
         response = redirect('mock_view', permanent=True)
     eq_(response.status_code, 301)
     eq_(response['Location'], '/en-US/mock_view')
Beispiel #16
0
 def test_basic(self):
     with self.activate('en-US'):
         response = redirect('mock_view')
     eq_(response.status_code, 302)
     eq_(response['Location'], '/en-US/mock_view')