Esempio n. 1
0
def index(request):
    context = widget.add_onsite_js_files({})
    context['all_videos'] = Video.objects.count()
    context['popular_videos'] = VideoIndex.get_popular_videos("-today_views")[:VideoIndex.IN_ROW]
    context['featured_videos'] = VideoIndex.get_featured_videos()[:VideoIndex.IN_ROW]
    return render_to_response('index.html', context,
                              context_instance=RequestContext(request))
Esempio n. 2
0
def volunteer_page(request):
    # Get the user comfort languages list
    user_langs = get_user_languages_from_request(request)

    relevant = VideoIndex.public().filter(video_language_exact__in=user_langs) \
        .filter_or(languages_exact__in=user_langs) \
        .order_by('-requests_count')

    featured_videos =  relevant.filter(
        featured__gt=datetime.datetime(datetime.MINYEAR, 1, 1)) \
        .order_by('-featured')[:5]

    popular_videos = relevant.order_by('-week_views')[:5]

    latest_videos = relevant.order_by('-edited')[:15]

    requested_videos = relevant.filter(requests_exact__in=user_langs)[:5]

    context = {
        'featured_videos': featured_videos,
        'popular_videos': popular_videos,
        'latest_videos': latest_videos,
        'requested_videos': requested_videos,
        'user_langs':user_langs,
    }

    return render_to_response('videos/volunteer.html', context,
                              context_instance=RequestContext(request))
Esempio n. 3
0
    def load_popular_videos(self, sort, request, user):
        sort_types = {
            'today': 'today_views',
            'week': 'week_views',
            'month': 'month_views',
            'year': 'year_views',
            'total': 'total_views'
        }

        if sort in sort_types:
            display_views = sort
            sort_field = sort_types[sort]
        else:
            display_views = 'week'
            sort_field = 'week_views'

        popular_videos = VideoIndex.get_popular_videos(
            '-%s' % sort_field)[:VideoIndex.IN_ROW]

        context = {
            'display_views': display_views,
            'video_list': popular_videos
        }

        content = render_to_string('videos/_watch_page.html', context,
                                   RequestContext(request))

        return {'content': content}
Esempio n. 4
0
def watch_page(request):

    # Assume we're currently indexing if the number of public
    # indexed vids differs from the count of video objects by
    # more than 1000
    is_indexing = cache.get('is_indexing')
    if is_indexing is None:
        is_indexing = Video.objects.all().count() - VideoIndex.public().count() > 1000
        cache.set('is_indexing', is_indexing, 300)

    context = {
        'featured_videos': VideoIndex.get_featured_videos()[:VideoIndex.IN_ROW],
        'popular_videos': VideoIndex.get_popular_videos()[:VideoIndex.IN_ROW],
        'latest_videos': VideoIndex.get_latest_videos()[:VideoIndex.IN_ROW*3],
        'popular_display_views': 'week',
        'is_indexing': is_indexing
    }
    return render_to_response('videos/watch.html', context,
                              context_instance=RequestContext(request))
Esempio n. 5
0
    def load_popular_page(self, page, sort, request, user):
        sort_types = {
            'today': 'today_views',
            'week': 'week_views',
            'month': 'month_views',
            'year': 'year_views',
            'total': 'total_views'
        }

        sort_field = sort_types.get(sort, 'week_views')

        sqs = VideoIndex.get_popular_videos('-%s' % sort_field)

        return render_page(page, sqs, request=request, display_views=sort)
Esempio n. 6
0
    def save(self, *args, **kwargs):
        obj = super(EditTeamVideoForm, self).save(*args, **kwargs)

        video = obj.video

        author = self.cleaned_data['author'].strip()
        creation_date = VideoMetadata.date_to_string(self.cleaned_data['creation_date'])

        self._save_metadata(video, 'Author', author)
        self._save_metadata(video, 'Creation Date', creation_date)
        # store the uploaded thumb on the video itself
        # TODO: simply remove the teamvideo.thumbnail image
        if obj.thumbnail:
            content = ContentFile(obj.thumbnail.read())
            name = obj.thumbnail.url.split('/')[-1]
            video.s3_thumbnail.save(name, content)
            VideoIndex(Video).update_object(video)
Esempio n. 7
0
def index(request):
    if request.GET:
        site = current_site(request)
        query = {}
        for k,v in request.GET.items():
            query[k] = v
        # If we're at a URL with query params we just got here from a search
        # form on another page.  If that's the case, we'll redirect to the
        # AJAX-style URL with the params in the hash.  Then that page will take
        # the other branch of this if, and the search form will work its
        # frontend magic.
        url = '%s%s#/?%s' % (
            # Safari/WebKit seem to need this to work properly when redirecting
            # over HTTPS.  See commit 92de5dd6c4969c4c4a3d5d1422fb9caf5e42f345.
            site['BASE_URL'],
            reverse('search:index'),
            urlencode(query)
        )

        return HttpResponseRedirect(url)
    else:
        return {
            'form': SearchForm(sqs=VideoIndex.public())
        }
Esempio n. 8
0
    def load_latest_page(self, page, request, user):
        sqs = VideoIndex.public().order_by('-created')

        return render_page(page, sqs, request=request)
Esempio n. 9
0
    def load_featured_page(self, page, request, user):
        sqs = VideoIndex.get_featured_videos()

        return render_page(page, sqs, request=request)