Beispiel #1
0
def vidly_media_resubmit(request):
    if request.POST.get('cancel'):
        return redirect(reverse('manage:vidly_media') + '?status=Error')

    form = forms.VidlyResubmitForm(data=request.POST)
    if not form.is_valid():
        return http.HttpResponse(str(form.errors))
    event = get_object_or_404(Event, pk=form.cleaned_data['id'])
    environment = event.template_environment or {}
    if not environment.get('tag') or environment.get('tag') == 'None':
        raise ValueError("Not a valid tag in template")

    if event.privacy != Event.PRIVACY_PUBLIC:
        token_protection = True  # no choice
    else:
        token_protection = form.cleaned_data['token_protection']

    base_url = get_base_url(request)
    webhook_url = base_url + reverse('manage:vidly_media_webhook')

    old_tag = environment['tag']
    url = prepare_vidly_video_url(form.cleaned_data['url'])
    shortcode, error = vidly.add_media(
        url=url,
        hd=form.cleaned_data['hd'],
        token_protection=token_protection,
        notify_url=webhook_url,
    )
    VidlySubmission.objects.create(
        event=event,
        url=url,
        token_protection=token_protection,
        hd=form.cleaned_data['hd'],
        tag=shortcode,
        submission_error=error
    )

    if error:
        messages.warning(
            request,
            "Media could not be re-submitted:\n<br>\n%s" % error
        )
    else:
        messages.success(
            request,
            "Event re-submitted to use tag '%s'" % shortcode
        )
        vidly.delete_media(old_tag)
        event.template_environment['tag'] = shortcode
        event.status = Event.STATUS_PROCESSING
        event.save()

        cache_key = 'vidly-query-%s' % old_tag
        cache.delete(cache_key)

    return redirect(reverse('manage:vidly_media') + '?status=Error')
Beispiel #2
0
def vidly_media_resubmit(request):
    if request.POST.get('cancel'):
        return redirect(reverse('manage:vidly_media') + '?status=Error')

    form = forms.VidlyResubmitForm(data=request.POST)
    if not form.is_valid():
        return http.HttpResponse(str(form.errors))
    event = get_object_or_404(Event, pk=form.cleaned_data['id'])
    environment = event.template_environment or {}
    if not environment.get('tag') or environment.get('tag') == 'None':
        raise ValueError("Not a valid tag in template")

    if event.privacy != Event.PRIVACY_PUBLIC:
        token_protection = True  # no choice
    else:
        token_protection = form.cleaned_data['token_protection']

    base_url = get_base_url(request)
    webhook_url = base_url + reverse('manage:vidly_media_webhook')

    old_tag = environment['tag']
    url = prepare_vidly_video_url(form.cleaned_data['url'])
    shortcode, error = vidly.add_media(
        url=url,
        hd=form.cleaned_data['hd'],
        token_protection=token_protection,
        notify_url=webhook_url,
    )
    VidlySubmission.objects.create(
        event=event,
        url=url,
        token_protection=token_protection,
        hd=form.cleaned_data['hd'],
        tag=shortcode,
        submission_error=error
    )

    if error:
        messages.warning(
            request,
            "Media could not be re-submitted:\n<br>\n%s" % error
        )
    else:
        messages.success(
            request,
            "Event re-submitted to use tag '%s'" % shortcode
        )
        vidly.delete_media(old_tag)
        event.template_environment['tag'] = shortcode
        event.save()

        cache_key = 'vidly-query-%s' % old_tag
        cache.delete(cache_key)

    return redirect(reverse('manage:vidly_media') + '?status=Error')
Beispiel #3
0
 def test_delete_media_failure(self, p_urllib2, p_logging):
     def mocked_urlopen(request):
         # I don't actually know what it would say
         return StringIO("""
         <?xml version="1.0"?>
         <Response>
           <Message>Success</Message>
           <MessageCode>0.0</MessageCode>
           <Errors>
             <Error>
               <SourceFile>http://www.com</SourceFile>
               <ErrorCode>1.1</ErrorCode>
               <Description>ErrorDescriptionK</Description>
               <Suggestion>ErrorSuggestionK</Suggestion>
             </Error>
           </Errors>
         </Response>
         """)
     p_urllib2.urlopen = mocked_urlopen
     shortcode, error = vidly.delete_media(
         '8oxv6x',
         email='*****@*****.**'
     )
     ok_(not shortcode)
     ok_('1.1' in error)
Beispiel #4
0
 def test_delete_media(self, p_urllib2, p_logging):
     def mocked_urlopen(request):
         return StringIO("""
         <?xml version="1.0"?>
         <Response>
           <Message>Success</Message>
           <MessageCode>0.0</MessageCode>
           <Success>
             <MediaShortLink>8oxv6x</MediaShortLink>
           </Success>
           <Errors>
             <Error>
               <SourceFile>http://www.com</SourceFile>
               <ErrorCode>1</ErrorCode>
               <Description>ErrorDescriptionK</Description>
               <Suggestion>ErrorSuggestionK</Suggestion>
             </Error>
           </Errors>
         </Response>
         """)
     p_urllib2.urlopen = mocked_urlopen
     shortcode, error = vidly.delete_media(
         '8oxv6x',
         email='*****@*****.**'
     )
     eq_(shortcode, '8oxv6x')
     ok_(not error)
Beispiel #5
0
def event_vidly_submissions(request, id):
    event = get_object_or_404(Event, id=id)
    submissions = (
        VidlySubmission.objects
        .filter(event=event)
        .order_by('submission_time')
    )

    if request.method == 'POST':
        ids = request.POST.getlist('id')
        forced = request.POST.get('forced')
        submissions = submissions.filter(id__in=ids)
        if not forced:
            submissions = submissions.filter(tag__isnull=False)
        # if any of those have tag that we're currently using, raise a 400
        current_tag = event.template_environment.get('tag')
        if current_tag and submissions.filter(tag=current_tag):
            return http.HttpResponseBadRequest(
                "Can not delete because it's in use"
            )
        deletions = failures = 0
        for submission in submissions:
            if submission.tag:
                results = vidly.delete_media(submission.tag)
            else:
                assert forced
                results = ''
            if forced or submission.tag in results:
                submission.delete()
                deletions += 1
            else:
                failures += 1
        messages.success(
            request,
            "%s vidly submissions deleted. %s failures" % (
                deletions,
                failures
            )
        )
        return redirect('manage:event_vidly_submissions', event.id)

    paged = paginate(submissions, request.GET.get('page'), 20)

    active_submission = None
    try:
        te = event.template_environment
        if te and te.get('tag'):
            active_submission = submissions.get(
                tag=te['tag']
            )
    except VidlySubmission.DoesNotExist:  # pragma: no cover
        pass

    data = {
        'paginate': paged,
        'event': event,
        'active_submission': active_submission,
    }
    return render(request, 'manage/event_vidly_submissions.html', data)