Beispiel #1
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))
Beispiel #2
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))
Beispiel #3
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())
        }
Beispiel #4
0
    def load_latest_page(self, page, request, user):
        sqs = VideoIndex.public().order_by('-created')

        return render_page(page, sqs, request=request)