Beispiel #1
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}
Beispiel #2
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))
Beispiel #3
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)
Beispiel #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))