Exemplo n.º 1
0
    def form_valid(self, form):
        video = form.video_cache
        url = form.cleaned_data['url']
        # This bit essentially just preserves the old behavior; really, the
        # views that are redirected to are all instances of SubmitVideoView.

        if video is not None and (video.embed_code or
                                  (video.file_url
                                   and not video.file_url_expires)):
            success_url = self.scraped_url
        elif is_video_url(url):
            success_url = self.direct_url
        else:
            success_url = self.embed_url

        self.success_url = "%s?%s" % (success_url,
                                      self.request.GET.urlencode())

        key = self.get_session_key()
        self.request.session[key] = {'video': video, 'url': url}
        return super(SubmitURLView, self).form_valid(form)
Exemplo n.º 2
0
    def form_valid(self, form):
        video = form.video_cache
        url = form.cleaned_data['url']
        # This bit essentially just preserves the old behavior; really, the
        # views that are redirected to are all instances of SubmitVideoView.

        if video is not None and (video.embed_code or
                (video.file_url and not video.file_url_expires)):
            success_url = self.scraped_url
        elif is_video_url(url):
            success_url = self.direct_url
        else:
            success_url = self.embed_url

        self.success_url = "%s?%s" % (success_url, self.request.GET.urlencode())

        key = self.get_session_key()
        self.request.session[key] = {
            'video': video,
            'url': url
        }
        return super(SubmitURLView, self).form_valid(form)
Exemplo n.º 3
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.º 4
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))