コード例 #1
0
def getvids(context):
    """
        returns all videos or videos by_user
        context may include:
            username - return user videos
            user_id - return user videos
            user - user object
            show_private - boolean includes private videos
            include_channels - boolean returns user vids including channel vids
            channel_only - boolean return ONLY channel videos for user
    """
    params = {}
    if 'username' in context:
        params['username'] = context['username']
    if 'user_id' in context:
        params['user_id'] = context['user_id']
    if 'user' in context:
        params['user'] = context['user']
    if 'show_private' in context:
        params['show_private'] = context['show_private']
    if 'include_channels' in context:
        params['include_channels'] = context['include_channels']
    if 'channel_only' in context:
        params['channel_only'] = context['channel_only']
    return get_videos(**params)
コード例 #2
0
ファイル: views.py プロジェクト: thanhhoangila/screenbird
def index(request, template):
    """Home view, Displays features and latest videos
    """
    """
    if request.user.is_authenticated() and not request.POST:
        return HttpResponseRedirect(reverse('my-videos'))
    """
    LIMIT = 10

    try:
        feature_section = CustomPage.objects.get(url='/')
    except CustomPage.DoesNotExist:
        feature_section = None

    videos_list = []
    all_videos = get_videos(show_private=False, include_channels=False)
    new_videos = all_videos.order_by('-created')[:LIMIT]
    videos_count = all_videos.count()
    ctype = ContentType.objects.get_for_model(Video)
    qn = connection.ops.quote_name

    #popular_videos = all_videos.extra(select={
    #    'votes': """
    #             SELECT COUNT(thumbs_up)
    #             FROM %s
    #             WHERE voted_object_type_id = %s
    #             AND voted_object_id = %s.id
    #             AND thumbs_up = 1
    #             """ % (qn(ThumbUp._meta.db_table), ctype.id, qn(Video._meta.db_table))
    #}, order_by=['-votes'])[:LIMIT]

    popular_videos = all_videos.extra(select={
        'hit_count':
        """
					 SELECT hits FROM hitcount_hit_count as h 
					 INNER JOIN django_content_type d on h.content_type_id = d.id 
					 WHERE d.model = 'video' 
					 AND h.object_pk = videos_video.id
					 """,
        'votes':
        """
                 SELECT COUNT(thumbs_up)
                 FROM %s
                 WHERE voted_object_type_id = %s
                 AND voted_object_id = %s.id
                 AND thumbs_up = 1
                 """ %
        (qn(ThumbUp._meta.db_table), ctype.id, qn(Video._meta.db_table))
    }, ).order_by('-hit_count', '-votes')[:LIMIT]

    all_videos = all_videos.extra(select={
        'votes':
        """
                 SELECT COUNT(thumbs_up)
                 FROM %s
                 WHERE voted_object_type_id = %s
                 AND voted_object_id = %s.id
                 AND thumbs_up = 1
                 """ %
        (qn(ThumbUp._meta.db_table), ctype.id, qn(Video._meta.db_table))
    },
                                  order_by=['-votes', '-created'])[:LIMIT]

    featured_videos = FeaturedVideo.objects.all()

    for video in all_videos:
        videos_list.append({
            'name': video.title,
            'slug': video.slug,
            'updated': video.updated
        })

    context = {
        'videos_list':
        videos_list,  # by decreasing popularity and creation time
        'new_videos': new_videos,  # by decreasing creation time
        'popular_videos': popular_videos,  # by decreasing popularity
        'videos_count': videos_count,
        'version': version,
        'featured_videos': featured_videos,
        'feature_section': feature_section,
        'limit': LIMIT
    }

    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: 465060874/screenbird
def index(request, template):
    """Home view, Displays features and latest videos
    """
    """
    if request.user.is_authenticated() and not request.POST:
        return HttpResponseRedirect(reverse('my-videos'))
    """    
    LIMIT = 10

    try:
        feature_section = CustomPage.objects.get(url='/')
    except CustomPage.DoesNotExist:
        feature_section = None

    videos_list = []
    all_videos = get_videos(show_private=False, include_channels = False)
    new_videos = all_videos.order_by('-created')[:LIMIT]
    videos_count = all_videos.count()
    ctype = ContentType.objects.get_for_model(Video)
    qn = connection.ops.quote_name

    
    #popular_videos = all_videos.extra(select={
    #    'votes': """
    #             SELECT COUNT(thumbs_up)
    #             FROM %s
    #             WHERE voted_object_type_id = %s
    #             AND voted_object_id = %s.id
    #             AND thumbs_up = 1
    #             """ % (qn(ThumbUp._meta.db_table), ctype.id, qn(Video._meta.db_table))
    #}, order_by=['-votes'])[:LIMIT]
    
    popular_videos = all_videos.extra(
		select={
		'hit_count': """
					 SELECT hits FROM hitcount_hit_count as h 
					 INNER JOIN django_content_type d on h.content_type_id = d.id 
					 WHERE d.model = 'video' 
					 AND h.object_pk = videos_video.id
					 """,
        'votes': """
                 SELECT COUNT(thumbs_up)
                 FROM %s
                 WHERE voted_object_type_id = %s
                 AND voted_object_id = %s.id
                 AND thumbs_up = 1
                 """ % (qn(ThumbUp._meta.db_table), ctype.id, qn(Video._meta.db_table))
		},).order_by('-hit_count','-votes')[:LIMIT]
		
    all_videos = all_videos.extra(select={
        'votes': """
                 SELECT COUNT(thumbs_up)
                 FROM %s
                 WHERE voted_object_type_id = %s
                 AND voted_object_id = %s.id
                 AND thumbs_up = 1
                 """ % (qn(ThumbUp._meta.db_table), ctype.id, qn(Video._meta.db_table))
    }, order_by=['-votes', '-created'])[:LIMIT]

    featured_videos = FeaturedVideo.objects.all()

    for video in all_videos:
        videos_list.append({
            'name': video.title,
            'slug': video.slug,
            'updated': video.updated
        })

    context = {
        'videos_list': videos_list, # by decreasing popularity and creation time
        'new_videos': new_videos, # by decreasing creation time
        'popular_videos': popular_videos, # by decreasing popularity
        'videos_count': videos_count,
        'version': version,
        'featured_videos': featured_videos,
        'feature_section': feature_section,
        'limit': LIMIT
    }
    
    return render_to_response(template, context,
                              context_instance=RequestContext(request))