示例#1
0
文件: tests.py 项目: kmshi/miroguide
 def _feed_data(self):
     return {
         'feed_url': test_data_path('feed.xml'),
         'share_url': util.make_absolute_url('/share/feed/?feed_url=foo'),
         'share_type': 'feed',
         'from_email': '*****@*****.**',
         'comment': 'this is my comment',
         'recipients': '[email protected], [email protected]'}
示例#2
0
 def _feed_data(self):
     return {
         'feed_url': test_data_path('feed.xml'),
         'share_url': util.make_absolute_url('/share/feed/?feed_url=foo'),
         'share_type': 'feed',
         'from_email': '*****@*****.**',
         'comment': 'this is my comment',
         'recipients': '[email protected], [email protected]'
     }
示例#3
0
 def assertRedirect(self, response, redirect_url):
     """
     Asserts that the given response is a redirect to the given URL.
     """
     self.assertEquals(
         response.status_code, 302,
         "Not redirected:\nHeader: %i\nContent: %s" %
         (response.status_code, response.content))
     location_path = response['Location'].split('?')[0]
     self.assertEqual(location_path, util.make_absolute_url(redirect_url))
示例#4
0
文件: tests.py 项目: kmshi/miroguide
 def _item_data(self):
     return {
         'feed_url': test_data_path('feed.xml'),
         'file_url': 'http://www.rocketboom.net/video/rb_06_dec_13.mov',
         'share_url': util.make_absolute_url(
             '/share/item/?feed_url=foo&item_url=bar'),
         'share_type': 'item',
         'from_email': '*****@*****.**',
         'comment': 'this is my comment',
         'recipients': '[email protected], [email protected]'}
示例#5
0
文件: views.py 项目: kmshi/miroguide
def data_for_item(item):
    default_keys = ('id', 'name', 'description', 'url', 'size', 'channel_id',
                    'mime_type')
    data = {}
    for key in default_keys:
        data[key] = getattr(item, key)
    data['playback_url'] = util.make_absolute_url(item.get_url())
    if item.date is not None:
        data['date'] = item.date.isoformat()
    if item.thumbnail_exists():
        data['thumbnail_url'] = item.thumb_url(200, 133)
    return data
示例#6
0
文件: views.py 项目: kmshi/miroguide
def data_for_item(item):
    default_keys = ('id', 'name', 'description', 'url', 'size', 'channel_id',
                    'mime_type')
    data = {}
    for key in default_keys:
        data[key] = getattr(item, key)
    data['playback_url'] = util.make_absolute_url(item.get_url())
    if item.date is not None:
        data['date'] = item.date.isoformat()
    if item.thumbnail_exists():
        data['thumbnail_url'] = item.thumb_url(200, 133)
    return data
示例#7
0
    def test_item_url_in_database(self):
        self.channel.url = test_data_path('feed.xml')
        self.channel.save()
        self.channel.update_items(feedparser_input=open(self.channel.url))

        response = self.get_item(
            test_data_path('feed.xml'), 'http://www.rocketboom.net/video/'
            'rb_06_dec_13.mov')
        self.assertEquals(response.status_code, 302)
        self.assertEquals(
            response['Location'],
            util.make_absolute_url(self.channel.items.all()[0].get_url(),
                                   {'share': 'true'}))
示例#8
0
文件: tests.py 项目: kmshi/miroguide
    def test_item_url_in_database(self):
        self.channel.url = test_data_path('feed.xml')
        self.channel.save()
        self.channel.update_items(
            feedparser_input=open(self.channel.url))

        response = self.get_item(test_data_path('feed.xml'),
                                 'http://www.rocketboom.net/video/'
                                 'rb_06_dec_13.mov')
        self.assertEquals(response.status_code, 302)
        self.assertEquals(response['Location'],
                          util.make_absolute_url(
                self.channel.items.all()[0].get_url(), {'share': 'true'}))
示例#9
0
 def assertCanAccess(self, response_or_url, login_as=None):
     if isinstance(response_or_url, basestring):
         response = self.get_page(response_or_url, login_as)
     else:
         response = response_or_url
     if response.status_code == 200:
         return
     elif response.status_code == 302:
         location_path = response['Location'].split('?')[0]
         self.assertNotEquals(
             location_path, util.make_absolute_url(settings.LOGIN_URL),
             '%s could not access %s' % (login_as, response_or_url))
     else:
         raise AssertionError("Bad status code: %s" % response.status_code)
示例#10
0
 def _item_data(self):
     return {
         'feed_url':
         test_data_path('feed.xml'),
         'file_url':
         'http://www.rocketboom.net/video/rb_06_dec_13.mov',
         'share_url':
         util.make_absolute_url('/share/item/?feed_url=foo&item_url=bar'),
         'share_type':
         'item',
         'from_email':
         '*****@*****.**',
         'comment':
         'this is my comment',
         'recipients':
         '[email protected], [email protected]'
     }
示例#11
0
文件: tests.py 项目: kmshi/miroguide
    def check_submit_worked(self, response, url=None,
            thumb_name='thumbnail.jpg'):
        """
        Check that submitting the channel did not cause an error, and that
        it correctly redirected the user to the after submit page.
        """
        if response.status_code != 302:
            try:
                errors = response.context[0]['form'].errors.items()
            except:
                errors = "Unknown"
            msg = """\
Submit failed!
Status code: %s
Errors: %s""" % (response.status_code, errors)
            raise AssertionError(msg)
        self.assertEquals(response['Location'],
                          util.make_absolute_url('submit/after'))
        self.check_last_channel_thumbnail(thumb_name)
        return response
示例#12
0
文件: feeds.py 项目: kmshi/miroguide
 def item_extra_kwargs(self, item):
     return {
         'thumbnail': util.make_absolute_url(item.thumb_url_200_134())
         }
示例#13
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))
示例#14
0
文件: views.py 项目: kmshi/miroguide
def email(request):
    share_form = ShareForm(request.POST)

    if not share_form.is_valid():
        return render_to_response(
            'sharing/form.html',
            {'share_form': share_form,
             'share_type': share_form.data.get('share_type'),
             'feed_url': share_form.data.get('feed_url'),
             'file_url': share_form.data.get('file_url'),
             'share_url': share_form.data.get('share_url'),
             'item_url': share_form.data.get('item_url')},
            context_instance=RequestContext(request))

    # construct the email to send out from a template
    if share_form.cleaned_data['share_type'] == 'feed':
        subject = _(u'%(from_email)s wants to share a video feed with you') % {
            'from_email': share_form.cleaned_data['from_email']}
        try:
            channel, channel_items = get_channels_and_items(
                share_form.cleaned_data['feed_url'])
        except FeedFetchingError:
            title = description = thumbnail =None
        else:
            title = channel.name
            description = channel.description
            if hasattr(channel, 'thumbnail_url'):
                thumbnail = channel.thumbnail_url
            else:
                thumbnail = channel.thumb_url_200_134()
    else:
        subject = _(u'%(from_email)s wants to share a video with you') % {
            'from_email': share_form.cleaned_data['from_email']}
        if share_form.cleaned_data['feed_url']:
            try:
                channel, channel_items = get_channels_and_items(
                    share_form.cleaned_data['feed_url'])
            except FeedFetchingError:
                channel = channel_items = None
        else:
            channel = channel_items = None
        previous, item, next = get_item(share_form.cleaned_data['file_url'],
                                        channel, channel_items, None)
        title = item.name
        description = item.description
        if item:
            if hasattr(item, 'thumbnail_url'):
                thumbnail = item.thumbnail_url
            else:
                thumbnail = item.thumb_200_134()
        elif channel:
            if hasattr(channel, 'thumbnail_url'):
                thumbnail = channel.thumbnail_url
            else:
                thumbnail = channel.thumb_url_200_134()
        else:
            thumbnail = None

    if description:
        description = strip_tags(description)
        if len(description) > 170:
            description = description[:167] + '...'

    context = share_form.cleaned_data
    context.update({'title': title,
                    'description': description})
    if thumbnail:
        context['thumbnail'] = util.make_absolute_url(thumbnail)

    email_template = loader.get_template('sharing/email-body.txt')
    email_body = email_template.render(Context(context))

    html_template = loader.get_template('sharing/email-body.html')
    html_body = html_template.render(Context(context))

    for recipient in share_form.cleaned_data['recipients']:
        message = EmailMultiAlternatives(
            subject, email_body, to=[recipient])
        message.attach_alternative(html_body, 'text/html')
        message.send()

    return render_to_response(
        'sharing/email-success.html', {},
        context_instance=RequestContext(request))
示例#15
0
 def item_extra_kwargs(self, item):
     return {'thumbnail': util.make_absolute_url(item.thumb_url_200_134())}
示例#16
0
def email(request):
    share_form = ShareForm(request.POST)

    if not share_form.is_valid():
        return render_to_response(
            'sharing/form.html', {
                'share_form': share_form,
                'share_type': share_form.data.get('share_type'),
                'feed_url': share_form.data.get('feed_url'),
                'file_url': share_form.data.get('file_url'),
                'share_url': share_form.data.get('share_url'),
                'item_url': share_form.data.get('item_url')
            },
            context_instance=RequestContext(request))

    # construct the email to send out from a template
    if share_form.cleaned_data['share_type'] == 'feed':
        subject = _(u'%(from_email)s wants to share a video feed with you') % {
            'from_email': share_form.cleaned_data['from_email']
        }
        try:
            channel, channel_items = get_channels_and_items(
                share_form.cleaned_data['feed_url'])
        except FeedFetchingError:
            title = description = thumbnail = None
        else:
            title = channel.name
            description = channel.description
            if hasattr(channel, 'thumbnail_url'):
                thumbnail = channel.thumbnail_url
            else:
                thumbnail = channel.thumb_url_200_134()
    else:
        subject = _(u'%(from_email)s wants to share a video with you') % {
            'from_email': share_form.cleaned_data['from_email']
        }
        if share_form.cleaned_data['feed_url']:
            try:
                channel, channel_items = get_channels_and_items(
                    share_form.cleaned_data['feed_url'])
            except FeedFetchingError:
                channel = channel_items = None
        else:
            channel = channel_items = None
        previous, item, next = get_item(share_form.cleaned_data['file_url'],
                                        channel, channel_items, None)
        title = item.name
        description = item.description
        if item:
            if hasattr(item, 'thumbnail_url'):
                thumbnail = item.thumbnail_url
            else:
                thumbnail = item.thumb_200_134()
        elif channel:
            if hasattr(channel, 'thumbnail_url'):
                thumbnail = channel.thumbnail_url
            else:
                thumbnail = channel.thumb_url_200_134()
        else:
            thumbnail = None

    if description:
        description = strip_tags(description)
        if len(description) > 170:
            description = description[:167] + '...'

    context = share_form.cleaned_data
    context.update({'title': title, 'description': description})
    if thumbnail:
        context['thumbnail'] = util.make_absolute_url(thumbnail)

    email_template = loader.get_template('sharing/email-body.txt')
    email_body = email_template.render(Context(context))

    html_template = loader.get_template('sharing/email-body.html')
    html_body = html_template.render(Context(context))

    for recipient in share_form.cleaned_data['recipients']:
        message = EmailMultiAlternatives(subject, email_body, to=[recipient])
        message.attach_alternative(html_body, 'text/html')
        message.send()

    return render_to_response('sharing/email-success.html', {},
                              context_instance=RequestContext(request))
示例#17
0
文件: models.py 项目: kmshi/miroguide
 def get_absolute_url(self):
     return util.make_absolute_url(self.get_url())
示例#18
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))