예제 #1
0
    def get_cache_key_tuple(self, request):
        # XXX to a certain extent, this is copied from
        # XXX channelguide/guide/views/channels.py:filtered_listing
        miro_version_pre_sites = miro_linux = False
        miro_version = util.get_miro_version(request.META.get("HTTP_USER_AGENT"))
        if miro_version and int(miro_version.split(".")[0]) < 2:
            miro_version_pre_sites = True
        if miro_version and "X11" in request.META.get("HTTP_USER_AGENT", ""):
            miro_linux = True

        geoip = request.GET.get("geoip", None)
        if geoip != "off":
            geoip = country_code(request)
        else:
            geoip = None

        return UserCacheMiddleware.get_cache_key_tuple(self, request) + (miro_version_pre_sites, miro_linux, geoip)
예제 #2
0
    def get_cache_key_tuple(self, request):
        # XXX to a certain extent, this is copied from
        # XXX channelguide/guide/views/channels.py:filtered_listing
        miro_version_pre_sites = miro_linux = False
        miro_version = util.get_miro_version(
            request.META.get('HTTP_USER_AGENT'))
        if miro_version and int(miro_version.split('.')[0]) < 2:
            miro_version_pre_sites = True
        if miro_version and 'X11' in request.META.get('HTTP_USER_AGENT', ''):
            miro_linux = True

        geoip = request.GET.get('geoip', None)
        if geoip != 'off':
            geoip = country_code(request)
        else:
            geoip = None

        return UserCacheMiddleware.get_cache_key_tuple(
            self, request) + (miro_version_pre_sites, miro_linux, geoip)
예제 #3
0
파일: views.py 프로젝트: kmshi/miroguide
def filtered_listing(request,
                     value=None,
                     filter=None,
                     limit=10,
                     title='Filtered Listing',
                     default_sort=None):
    if not filter:
        raise Http404
    page = request.GET.get('page', 1)
    try:
        page = int(page)
    except ValueError:
        raise Http404
    sort = request.GET.get('sort', default_sort)
    if default_sort is None and sort is None:
        sort = '-popular'
    geoip = request.GET.get('geoip', None)
    if geoip != 'off':
        geoip = country_code(request)
    else:
        geoip = None
    if isinstance(filter, basestring):
        filter = [filter]
        value = [value]
    if 'audio' not in filter:
        filter.append('audio')
        if request.path.startswith('/audio'):
            value.append(True)
        else:
            value.append(False)
    feed_object_list = FeedObjectList(request, filter, value, sort,
                                      ('stats', 'rating'), geoip)
    feed_paginator = Paginator(feed_object_list, limit)
    try:
        feed_page = feed_paginator.page(page)
    except InvalidPage:
        feed_page = None

    miro_version_pre_sites = miro_on_linux = False
    miro_version = util.get_miro_version(request.META.get('HTTP_USER_AGENT'))

    if miro_version:
        if int(miro_version.split('.')[0]) < 2:
            miro_version_pre_sites = True

    site_page = None
    site_paginator = None
    site_object_list = None
    # There are two cases where we don't generate a site object list:
    #  - If it's pre-miro 2.0 (doesn't support site object lists)
    #  - If it's Miro on Linux... because unfortunately most 'sites'
    #    are flash-based, and linux + flash == teh suck :\
    if not (miro_version_pre_sites or
            ('Miro' in request.META.get('HTTP_USER_AGENT', '')
             and 'X11' in request.META.get('HTTP_USER_AGENT', ''))):
        site_object_list = SiteObjectList(request, filter, value, sort,
                                          ('stats', 'rating'), geoip)
        site_paginator = Paginator(site_object_list, limit)

        try:
            site_page = site_paginator.page(page)
        except InvalidPage:
            site_page = None
    else:
        miro_on_linux = True

    # find the biggest paginator and use that page for calculating the links
    if not feed_paginator:
        biggest = site_page
    elif not site_paginator:
        biggest = feed_page
    elif feed_paginator.count > site_paginator.count:
        biggest = feed_page
    else:
        biggest = site_page

    if biggest is None:
        raise Http404

    geoip_filtered = False
    if geoip:
        if (feed_object_list.count_all() != feed_paginator.count
                or (site_object_list is not None
                    and site_object_list.count_all() != site_paginator.count)):
            args = request.GET.copy()
            args['geoip'] = 'off'
            geoip_filtered = util.make_absolute_url(request.path, args)

    video_count = audio_count = None

    if value[filter.index('audio')]:
        video_filter = filter[:]
        video_values = value[:]
        index = video_filter.index('audio')
        video_values[index] = False
        video_count = len(
            FeedObjectList(request, video_filter, video_values, sort, geoip))
    else:
        audio_filter = filter[:]
        audio_values = value[:]
        index = audio_filter.index('audio')
        audio_values[index] = True
        audio_count = len(
            FeedObjectList(request, audio_filter, audio_values, sort, geoip))

    return render_to_response('channels/listing.html', {
        'title': title % {
            'value': value[0]
        },
        'sort': sort,
        'filter': filter,
        'current_page': page,
        'feed_page': feed_page,
        'site_page': site_page,
        'biggest': biggest,
        'geoip_filtered': geoip_filtered,
        'miro_version_pre_sites': miro_version_pre_sites,
        'miro_on_linux': miro_on_linux,
        'search': 'search' in filter,
        'audio': value[filter.index('audio')],
        'video_count': video_count,
        'audio_count': audio_count
    },
                              context_instance=RequestContext(request))
예제 #4
0
파일: views.py 프로젝트: kmshi/miroguide
def show(request, id, featured_form=None):
    c = get_object_or_404(Channel, pk=id)
    try:
        c.rating
    except GeneratedRatings.DoesNotExist:
        c.rating = GeneratedRatings.objects.create(channel=c)
    # redirect old URLs to canonical ones
    if request.path != c.get_url():
        return util.redirect(c.get_absolute_url(), request.GET)

    item_paginator = Paginator(c.items.all(), 10)
    try:
        item_page = item_paginator.page(request.GET.get('page', 1))
    except InvalidPage:
        raise Http404
    for i in item_page.object_list:
        i.channel = c

    is_miro = bool(util.get_miro_version(request.META.get('HTTP_USER_AGENT')))

    share_links = share_url = None
    if request.GET.get('share') == 'true':
        share_url = urlparse.urljoin(settings.BASE_URL_FULL, '/feeds/%s' % id)
        share_links = util.get_share_links(share_url, c.name)

    country = country_code(request)
    context = {
        'channel': c,
        'item_page': item_page,
        'is_miro': is_miro,
        'show_edit_button': c.can_edit(request.user),
        'show_extra_info': c.can_edit(request.user),
        'link_to_channel': True,
        'BASE_URL': settings.BASE_URL,
        'feed_url': c.url,
        'share_url': share_url,
        'share_type': 'feed',
        'share_links': share_links,
        'country': country,
        'audio': c.state == c.AUDIO
    }

    if share_url:
        context['google_analytics_ua'] = None

    if country and c.geoip and country not in c.geoip.split(','):
        # restricted channel
        request.add_notification(
            None,
            _('This show may not be available to you, '
              'as it is restricted to certain countries.'))

    if request.user.has_perm('featured.change_featuredqueue'):
        try:
            featured_queue = c.featured_queue
        except FeaturedQueue.DoesNotExist:
            pass
        else:
            if featured_queue.state in (FeaturedQueue.IN_QUEUE,
                                        FeaturedQueue.CURRENT):
                c.featured = True
            if c.featured_emails.count():
                last_featured_email = c.featured_emails.all()[0]
            else:
                last_featured_email = None
            if featured_form is None:
                featured_form = FeaturedEmailForm(request, c)
            context['featured_email_form'] = featured_form
            context['last_featured_email'] = last_featured_email
    return render_to_response('channels/show-channel.html',
                              context,
                              context_instance=RequestContext(request))
예제 #5
0
파일: views.py 프로젝트: kmshi/miroguide
def filtered_listing(request, value=None, filter=None, limit=10,
                     title='Filtered Listing', default_sort=None):
    if not filter:
        raise Http404
    page = request.GET.get('page', 1)
    try:
        page = int(page)
    except ValueError:
        raise Http404
    sort = request.GET.get('sort', default_sort)
    if default_sort is None and sort is None:
        sort = '-popular'
    geoip = request.GET.get('geoip', None)
    if geoip != 'off':
        geoip = country_code(request)
    else:
        geoip = None
    if isinstance(filter, basestring):
        filter = [filter]
        value = [value]
    if 'audio' not in filter:
        filter.append('audio')
        if request.path.startswith('/audio'):
            value.append(True)
        else:
            value.append(False)
    feed_object_list = FeedObjectList(request,
                                      filter, value, sort,
                                      ('stats', 'rating'), geoip)
    feed_paginator = Paginator(feed_object_list, limit)
    try:
        feed_page = feed_paginator.page(page)
    except InvalidPage:
        feed_page = None

    miro_version_pre_sites = miro_on_linux = False
    miro_version = util.get_miro_version(request.META.get('HTTP_USER_AGENT'))

    if miro_version:
        if int(miro_version.split('.')[0]) < 2:
            miro_version_pre_sites = True

    site_page = None
    site_paginator = None
    site_object_list = None
    # There are two cases where we don't generate a site object list:
    #  - If it's pre-miro 2.0 (doesn't support site object lists)
    #  - If it's Miro on Linux... because unfortunately most 'sites'
    #    are flash-based, and linux + flash == teh suck :\
    if not (miro_version_pre_sites
            or ('Miro' in request.META.get('HTTP_USER_AGENT', '')
                and 'X11' in request.META.get('HTTP_USER_AGENT', ''))):
        site_object_list = SiteObjectList(
            request, filter, value, sort,
            ('stats', 'rating'),
            geoip)
        site_paginator = Paginator(site_object_list, limit)

        try:
            site_page = site_paginator.page(page)
        except InvalidPage:
            site_page = None
    else:
        miro_on_linux = True

    # find the biggest paginator and use that page for calculating the links
    if not feed_paginator:
        biggest = site_page
    elif not site_paginator:
        biggest = feed_page
    elif feed_paginator.count > site_paginator.count:
        biggest = feed_page
    else:
        biggest = site_page

    if biggest is None:
        raise Http404
    
    geoip_filtered = False
    if geoip:
        if (feed_object_list.count_all() != feed_paginator.count
            or (site_object_list is not None
                and site_object_list.count_all() != site_paginator.count)):
            args = request.GET.copy()
            args['geoip'] = 'off'
            geoip_filtered = util.make_absolute_url(request.path, args)

    video_count = audio_count = None

    if value[filter.index('audio')]:
        video_filter = filter[:]
        video_values = value[:]
        index = video_filter.index('audio')
        video_values[index] = False
        video_count = len(FeedObjectList(request, video_filter, video_values,
                                         sort, geoip))
    else:
        audio_filter = filter[:]
        audio_values = value[:]
        index = audio_filter.index('audio')
        audio_values[index] = True
        audio_count = len(FeedObjectList(request, audio_filter, audio_values,
                                         sort, geoip))

    return render_to_response('channels/listing.html', {
            'title': title % {'value': value[0]},
            'sort': sort,
            'filter': filter,
            'current_page': page,
            'feed_page': feed_page,
            'site_page': site_page,
            'biggest': biggest,
            'geoip_filtered': geoip_filtered,
            'miro_version_pre_sites': miro_version_pre_sites,
            'miro_on_linux': miro_on_linux,
            'search': 'search' in filter,
            'audio': value[filter.index('audio')],
            'video_count': video_count,
            'audio_count': audio_count
            }, context_instance=RequestContext(request))
예제 #6
0
파일: views.py 프로젝트: kmshi/miroguide
def show(request, id, featured_form=None):
    c = get_object_or_404(Channel, pk=id)
    try:
        c.rating
    except GeneratedRatings.DoesNotExist:
        c.rating = GeneratedRatings.objects.create(channel=c)
    # redirect old URLs to canonical ones
    if request.path != c.get_url():
        return util.redirect(c.get_absolute_url(), request.GET)

    item_paginator = Paginator(c.items.all(), 10)
    try:
        item_page = item_paginator.page(request.GET.get('page', 1))
    except InvalidPage:
        raise Http404
    for i in item_page.object_list:
        i.channel = c

    is_miro = bool(util.get_miro_version(request.META.get('HTTP_USER_AGENT')))

    share_links = share_url = None
    if request.GET.get('share') == 'true':
        share_url = urlparse.urljoin(
            settings.BASE_URL_FULL,
            '/feeds/%s' % id)
        share_links = util.get_share_links(share_url, c.name)

    country = country_code(request)
    context = {
        'channel': c,
        'item_page': item_page,
        'is_miro': is_miro,
        'show_edit_button': c.can_edit(request.user),
        'show_extra_info': c.can_edit(request.user),
        'link_to_channel': True,
        'BASE_URL': settings.BASE_URL,
        'feed_url': c.url,
        'share_url': share_url,
        'share_type': 'feed',
        'share_links': share_links,
        'country': country,
        'audio': c.state == c.AUDIO}

    if share_url:
        context['google_analytics_ua'] = None

    if country and c.geoip and country not in c.geoip.split(','):
        # restricted channel
        request.add_notification(None, _('This show may not be available to you, '
                                   'as it is restricted to certain countries.'))

    if request.user.has_perm('featured.change_featuredqueue'):
        try:
            featured_queue = c.featured_queue
        except FeaturedQueue.DoesNotExist:
            pass
        else:
            if featured_queue.state in (
                FeaturedQueue.IN_QUEUE, FeaturedQueue.CURRENT):
                c.featured = True
            if c.featured_emails.count():
                last_featured_email = c.featured_emails.all()[0]
            else:
                last_featured_email = None
            if featured_form is None:
                featured_form = FeaturedEmailForm(request, c)
            context['featured_email_form'] = featured_form
            context['last_featured_email'] = last_featured_email
    return render_to_response('channels/show-channel.html', context,
                              context_instance=RequestContext(request))