Пример #1
0
def vidly_url_to_shortcode(request, id):
    event = get_object_or_404(Event, id=id)
    form = forms.VidlyURLForm(data=request.POST)
    if form.is_valid():
        url = form.cleaned_data['url']
        if event.privacy != Event.PRIVACY_PUBLIC:
            # forced
            token_protection = True
        else:
            token_protection = form.cleaned_data['token_protection']
        hd = form.cleaned_data['hd']

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

        shortcode, error = vidly.add_media(
            url,
            token_protection=token_protection,
            hd=hd,
            notify_url=webhook_url,
        )
        VidlySubmission.objects.create(
            event=event,
            url=url,
            token_protection=token_protection,
            hd=hd,
            tag=shortcode,
            submission_error=error
        )
        url_scrubbed = scrub_transform_passwords(url)
        if shortcode:
            return {'shortcode': shortcode, 'url': url_scrubbed}
        else:
            return http.HttpResponseBadRequest(error)
    return http.HttpResponseBadRequest(str(form.errors))
Пример #2
0
def vidly_url_to_shortcode(request, id):
    get_object_or_404(Event, id=id)
    form = forms.VidlyURLForm(data=request.POST)
    if form.is_valid():
        url = form.cleaned_data['url']
        email = form.cleaned_data['email']
        token_protection = form.cleaned_data['token_protection']
        shortcode, error = vidly_add_media(url,
                                           email=email,
                                           token_protection=token_protection)
        if shortcode:
            return {'shortcode': shortcode}
        else:
            return HttpResponseBadRequest(error)
    return HttpResponseBadRequest(str(form.errors))
Пример #3
0
def event_archive(request, id):
    """Dedicated page for setting page template (archive) and archive time."""
    event = Event.objects.get(id=id)
    if request.method == 'POST':
        form = forms.EventArchiveForm(request.POST, instance=event)
        if form.is_valid():
            event = form.save(commit=False)
            minutes = form.cleaned_data['archive_time']
            now = (datetime.datetime.utcnow().replace(tzinfo=utc,
                                                      microsecond=0))
            event.archive_time = (now + datetime.timedelta(minutes=minutes))
            event.save()
            messages.info(request, 'Event "%s" saved.' % event.title)
            return redirect('manage:events')
    else:
        form = forms.EventArchiveForm(instance=event)
    vidly_shortcut_form = forms.VidlyURLForm(initial=dict(
        email=request.user.email))
    return render(request, 'manage/event_archive.html', {
        'form': form,
        'event': event,
        'vidly_shortcut_form': vidly_shortcut_form
    })
Пример #4
0
def event_archive(request, id):
    """Dedicated page for setting page template (archive) and archive time."""
    event = Event.objects.get(id=id)
    if request.method == 'POST':
        form = forms.EventArchiveForm(request.POST, instance=event)
        if form.is_valid():
            event = form.save(commit=False)

            def has_successful_vidly_submission(event):
                submissions = VidlySubmission.objects.filter(event=event)
                for submission in submissions.order_by('-submission_time')[:1]:
                    tag = submission.tag
                    results = vidly.query(tag).get(tag, {})
                    return results.get('Status') == 'Finished'

                return False

            if (
                event.has_vidly_template() and
                not has_successful_vidly_submission(event)
            ):
                event.status = Event.STATUS_PENDING
            else:
                event.status = Event.STATUS_SCHEDULED
                now = (
                    timezone.now()
                )
                # add one second otherwise, it will not appear on the
                # event manager immediately after the redirect
                event.archive_time = now - datetime.timedelta(seconds=1)
            event.save()
            messages.info(request, 'Event "%s" saved.' % event.title)
            return redirect('manage:events')
    else:
        form = forms.EventArchiveForm(instance=event)

    initial = {'hd': True}
    if event.privacy != Event.PRIVACY_PUBLIC:
        initial['token_protection'] = True
    if event.upload:
        initial['url'] = event.upload.url
    else:
        try:
            suggested_event = SuggestedEvent.objects.get(accepted=event)
            if suggested_event.upload:
                initial['url'] = suggested_event.upload.url
        except SuggestedEvent.DoesNotExist:
            pass

    vidly_shortcut_form = forms.VidlyURLForm(
        initial=initial,
        disable_token_protection=event.privacy != Event.PRIVACY_PUBLIC
    )

    for template in Template.objects.filter(default_archive_template=True):
        default_archive_template = template
        break
    else:
        default_archive_template = None

    context = {
        'form': form,
        'event': event,
        'vidly_shortcut_form': vidly_shortcut_form,
        'default_archive_template': default_archive_template,
    }
    return render(request, 'manage/event_archive.html', context)