Exemplo n.º 1
0
def scraped_submit_video(request):
    if not (request.REQUEST.get('url') and \
                url_re.match(request.REQUEST['url'])):
        return HttpResponseRedirect(reverse('localtv_submit_video'))

    vidscraper_video = utils.get_vidscraper_video(request.REQUEST['url'])

    url = vidscraper_video.link or request.REQUEST['url']
    sitelocation = SiteLocation.objects.get_current()
    existing =  Video.objects.filter(site=sitelocation.site,
                                     website_url=url)
    existing.filter(status=Video.REJECTED).delete()
    if existing.count():
        return HttpResponseRedirect(reverse('localtv_submit_thanks',
                                                args=[existing[0].id]))
    initial = dict(request.GET.items())
    # Backwards-compatible context variable
    data = {
        'link': vidscraper_video.link,
        'publish_date': vidscraper_video.publish_datetime,
        'tags': vidscraper_video.tags,
        'title': vidscraper_video.title,
        'description': vidscraper_video.description,
        'thumbnail_url': vidscraper_video.thumbnail_url,
        'user': vidscraper_video.user,
        'user_url': vidscraper_video.user_url,
    }
    if request.method == "GET":
        scraped_form = forms.ScrapedSubmitVideoForm(
            initial=initial,
            vidscraper_video=vidscraper_video)

        return render_to_response(
            'localtv/submit_video/scraped.html',
            {'video': vidscraper_video,
             'form': scraped_form,
             'data': data},
            context_instance=RequestContext(request))

    scraped_form = forms.ScrapedSubmitVideoForm(
        request.POST,
        sitelocation=sitelocation,
        user=request.user,
        vidscraper_video=vidscraper_video)
    return _submit_finish(scraped_form,
            'localtv/submit_video/scraped.html',
            {'video': vidscraper_video,
             'form': scraped_form,
             'data': data},
            context_instance=RequestContext(request))
Exemplo n.º 2
0
def embedrequest_submit_video(request):
    if not (request.REQUEST.get('url') and \
                url_re.match(request.REQUEST['url'])):
        return HttpResponseRedirect(reverse('localtv_submit_video'))

    url = request.REQUEST['url']
    sitelocation = SiteLocation.objects.get_current()
    existing =  Video.objects.filter(site=sitelocation.site,
                                            website_url=url)
    existing.filter(status=Video.REJECTED).delete()
    if existing.count():
        return HttpResponseRedirect(reverse('localtv_submit_thanks',
                                                args=[existing[0].id]))

    vidscraper_video = utils.get_vidscraper_video(request.REQUEST['url']) or {}
    initial = {
        'url': url,
        'name': vidscraper_video.title or '',
        'description': vidscraper_video.description or '',
        'thumbnail': vidscraper_video.thumbnail_url or '',
        }
    if request.method == "GET":
        embed_form = forms.EmbedSubmitVideoForm(initial=initial)

        return render_to_response(
            'localtv/submit_video/embed.html',
            {'form': embed_form},
            context_instance=RequestContext(request))

    embed_form = forms.EmbedSubmitVideoForm(request.POST, request.FILES,
                                            sitelocation=sitelocation,
                                            user=request.user)

    return _submit_finish(embed_form,
                          'localtv/submit_video/embed.html',
                          {'form': embed_form},
                          context_instance=RequestContext(request))
Exemplo n.º 3
0
def scraped_submit_video(request):
    if not (request.REQUEST.get('url') and \
                url_re.match(request.REQUEST['url'])):
        return HttpResponseRedirect(reverse('localtv_submit_video'))

    vidscraper_video = utils.get_vidscraper_video(request.REQUEST['url'])

    url = vidscraper_video.link or request.REQUEST['url']
    sitelocation = SiteLocation.objects.get_current()
    existing =  Video.objects.filter(site=sitelocation.site,
                                     website_url=url)
    existing.filter(status=Video.REJECTED).delete()
    if existing.count():
        return HttpResponseRedirect(reverse('localtv_submit_thanks',
                                                args=[existing[0].id]))
    initial = dict(request.GET.items())
    if request.method == "GET":
        scraped_form = forms.ScrapedSubmitVideoForm(
            initial=initial,
            vidscraper_video=vidscraper_video)

        return render_to_response(
            'localtv/submit_video/scraped.html',
            {'video': vidscraper_video,
             'form': scraped_form},
            context_instance=RequestContext(request))

    scraped_form = forms.ScrapedSubmitVideoForm(
        request.POST,
        sitelocation=sitelocation,
        user=request.user,
        vidscraper_video=vidscraper_video)
    return _submit_finish(scraped_form,
            'localtv/submit_video/scraped.html',
            {'video': vidscraper_video,
             'form': scraped_form},
            context_instance=RequestContext(request))
Exemplo n.º 4
0
def embedrequest_submit_video(request):
    if not (request.REQUEST.get('url') and \
                url_re.match(request.REQUEST['url'])):
        return HttpResponseRedirect(reverse('localtv_submit_video'))

    url = request.REQUEST['url']
    sitelocation = SiteLocation.objects.get_current()
    existing =  Video.objects.filter(site=sitelocation.site,
                                            website_url=url)
    existing.filter(status=Video.REJECTED).delete()
    if existing.count():
        return HttpResponseRedirect(reverse('localtv_submit_thanks',
                                                args=[existing[0].id]))

    vidscraper_video = utils.get_vidscraper_video(request.REQUEST['url']) or {}
    initial = {
        'url': url,
        'name': vidscraper_video.title or '',
        'description': vidscraper_video.description or '',
        'thumbnail': vidscraper_video.thumbnail_url or '',
        }
    if request.method == "GET":
        embed_form = forms.EmbedSubmitVideoForm(initial=initial)

        return render_to_response(
            'localtv/submit_video/embed.html',
            {'form': embed_form},
            context_instance=RequestContext(request))

    embed_form = forms.EmbedSubmitVideoForm(request.POST, request.FILES,
                                            sitelocation=sitelocation,
                                            user=request.user)

    return _submit_finish(embed_form,
                          'localtv/submit_video/embed.html',
                          {'form': embed_form},
                          context_instance=RequestContext(request))
Exemplo n.º 5
0
def submit_video(request):
    sitelocation = SiteLocation.objects.get_current()
    if not (request.user_is_admin() or sitelocation.display_submit_button):
        raise Http404

    # Extract construction hint, if it exists.
    # This is a hint that plugins can use to slightly change the behavior
    # of the video submission forms.
    construction_hint = (request.POST.get('construction_hint', None) or
                         request.GET.get('construction_hint', None))

    url = request.POST.get('url') or request.GET.get('url', '')

    if request.method == "GET" and not url:
        submit_form = forms.SubmitVideoForm(
            construction_hint=construction_hint)
        return render_to_response(
            'localtv/submit_video/submit.html',
            {'form': submit_form},
            context_instance=RequestContext(request))
    else:
        url = urlparse.urldefrag(url)[0]
        submit_form = forms.SubmitVideoForm({'url': url or ''})
        if submit_form.is_valid():
            existing = Video.objects.filter(
                Q(website_url=submit_form.cleaned_data['url']) |
                Q(file_url=submit_form.cleaned_data['url']),
                site=sitelocation.site)
            existing.filter(status=Video.REJECTED).delete()
            if existing.count():
                if request.user_is_admin():
                    # even if the video was rejected, an admin submitting it
                    # should make it approved
                    # FIXME: This initiates a new query against the database -
                    # so the rejected videos which were deleted will not be
                    # marked approved.
                    for v in existing.exclude(
                        status=Video.ACTIVE):
                        v.user = request.user
                        v.status = Video.ACTIVE
                        v.when_approved = datetime.datetime.now()
                        v.save()
                    return HttpResponseRedirect(
                        reverse('localtv_submit_thanks',
                                args=[existing[0].pk]))
                else:
                    # pick the first approved video to point the user at
                    videos = existing.filter(status=Video.ACTIVE)
                    if videos.count():
                        video = videos[0]
                    else:
                        video = None
                    return render_to_response(
                        'localtv/submit_video/submit.html',
                        {'form': forms.SubmitVideoForm(
                                construction_hint=construction_hint),
                         'was_duplicate': True,
                         'video': video},
                        context_instance=RequestContext(request))

            vidscraper_video = utils.get_vidscraper_video(
                submit_form.cleaned_data['url'])

            get_dict = {'url': submit_form.cleaned_data['url']}
            if 'construction_hint' in request.GET:
                get_dict['construction_hint'] = construction_hint
            if 'bookmarklet' in request.GET:
                get_dict['bookmarklet'] = '1'
            get_params = urllib.urlencode(get_dict)
            if vidscraper_video:
                if (vidscraper_video.link and
                    vidscraper_video.link != get_dict['url']):
                    request.POST = {
                        'url': vidscraper_video.link.encode('utf8')}
                    # rerun the view, but with the canonical URL
                    return submit_video(request)

                if (vidscraper_video.embed_code
                    or (vidscraper_video.file_url
                        and not vidscraper_video.file_url_expires)):
                    return HttpResponseRedirect(
                        reverse('localtv_submit_scraped_video') + '?' +
                        get_params)

            # otherwise if it looks like a video file
            if is_video_url(submit_form.cleaned_data['url']):
                return HttpResponseRedirect(
                    reverse('localtv_submit_directlink_video')
                    + '?' + get_params)
            else:
                return HttpResponseRedirect(
                    reverse('localtv_submit_embedrequest_video')
                    + '?' + get_params)

        else:
            return render_to_response(
                'localtv/submit_video/submit.html',
                {'form': submit_form},
                context_instance=RequestContext(request))
Exemplo n.º 6
0
def submit_video(request):
    sitelocation = SiteLocation.objects.get_current()
    if not (request.user_is_admin() or sitelocation.display_submit_button):
        raise Http404

    # Extract construction hint, if it exists.
    # This is a hint that plugins can use to slightly change the behavior
    # of the video submission forms.
    construction_hint = (request.POST.get('construction_hint', None) or
                         request.GET.get('construction_hint', None))

    url = request.POST.get('url') or request.GET.get('url', '')

    if request.method == "GET" and not url:
        submit_form = forms.SubmitVideoForm(
            construction_hint=construction_hint)
        return render_to_response(
            'localtv/submit_video/submit.html',
            {'form': submit_form},
            context_instance=RequestContext(request))
    else:
        url = urlparse.urldefrag(url)[0]
        submit_form = forms.SubmitVideoForm({'url': url or ''})
        if submit_form.is_valid():
            existing = Video.objects.filter(
                Q(website_url=submit_form.cleaned_data['url']) |
                Q(file_url=submit_form.cleaned_data['url']),
                site=sitelocation.site)
            existing.filter(status=Video.REJECTED).delete()
            if existing.count():
                if request.user_is_admin():
                    # even if the video was rejected, an admin submitting it
                    # should make it approved
                    # FIXME: This initiates a new query against the database -
                    # so the rejected videos which were deleted will not be
                    # marked approved.
                    for v in existing.exclude(
                        status=Video.ACTIVE):
                        v.user = request.user
                        v.status = Video.ACTIVE
                        v.when_approved = datetime.datetime.now()
                        v.save()
                    return HttpResponseRedirect(
                        reverse('localtv_submit_thanks',
                                args=[existing[0].pk]))
                else:
                    # pick the first approved video to point the user at
                    videos = existing.filter(status=Video.ACTIVE)
                    if videos.count():
                        video = videos[0]
                    else:
                        video = None
                    return render_to_response(
                        'localtv/submit_video/submit.html',
                        {'form': forms.SubmitVideoForm(
                                construction_hint=construction_hint),
                         'was_duplicate': True,
                         'video': video},
                        context_instance=RequestContext(request))

            vidscraper_video = utils.get_vidscraper_video(
                submit_form.cleaned_data['url'])

            get_dict = {'url': submit_form.cleaned_data['url']}
            if 'construction_hint' in request.GET:
                get_dict['construction_hint'] = construction_hint
            if 'bookmarklet' in request.GET:
                get_dict['bookmarklet'] = '1'
            get_params = urllib.urlencode(get_dict)
            if vidscraper_video:
                if (vidscraper_video.link and
                    vidscraper_video.link != get_dict['url']):
                    request.POST = {
                        'url': vidscraper_video.link.encode('utf8')}
                    # rerun the view, but with the canonical URL
                    return submit_video(request)

                if (vidscraper_video.embed_code
                    or (vidscraper_video.file_url
                        and not vidscraper_video.file_url_expires)):
                    return HttpResponseRedirect(
                        reverse('localtv_submit_scraped_video') + '?' +
                        get_params)

            # otherwise if it looks like a video file
            if is_video_url(submit_form.cleaned_data['url']):
                return HttpResponseRedirect(
                    reverse('localtv_submit_directlink_video')
                    + '?' + get_params)
            else:
                return HttpResponseRedirect(
                    reverse('localtv_submit_embedrequest_video')
                    + '?' + get_params)

        else:
            return render_to_response(
                'localtv/submit_video/submit.html',
                {'form': submit_form},
                context_instance=RequestContext(request))