示例#1
0
def blogroll(request, btype):
    """ View that handles the generation of blogrolls.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    # for some reason this isn't working:
    #
    #response = render_to_response('feedjack/%s.xml' % btype, \
    #  fjlib.get_extra_content(site, sfeeds_ids))
    #response.mimetype = 'text/xml; charset=utf-8'
    #
    # so we must use this:

    template = loader.get_template('feedjack/%s.xml' % btype)
    ctx = {}
    fjlib.get_extra_content(site, sfeeds_ids, ctx)
    ctx = Context(ctx)
    response = HttpResponse(template.render(ctx) , \
      mimetype='text/xml; charset=utf-8')


    patch_vary_headers(response, ['Host'])
    fjcache.cache_set(site, cachekey, response)
    return response
示例#2
0
def buildfeed(request, feedclass, tag=None, user=None):
    """ View that handles the feeds.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    object_list = fjlib.get_paginator(site, sfeeds_ids, page=0, tag=tag, \
      user=user)[1]

    feed = feedclass(\
        title=site.title,
        link=site.url,
        description=site.description,
        feed_url='%s/%s' % (site.url, '/feed/rss/'))
    for post in object_list:
        feed.add_item( \
          title = '%s: %s' % (post.feed.name, post.title), \
          link = post.link, \
          description = post.content, \
          author_email = post.author_email, \
          author_name = post.author, \
          pubdate = post.date_modified, \
          unique_id = post.link, \
          categories = [tag.name for tag in post.tags.all()])
    response = HttpResponse(mimetype=feed.mime_type)

    # per host caching
    patch_vary_headers(response, ['Host'])

    feed.write(response, 'utf-8')
    if site.use_internal_cache:
        fjcache.cache_set(site, cachekey, response)
    return response
示例#3
0
def blogroll(request, btype):
    """ View that handles the generation of blogrolls.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    # for some reason this isn't working:
    #
    #response = render_to_response('feedjack/%s.xml' % btype, \
    #  fjlib.get_extra_content(site, sfeeds_ids))
    #response.mimetype = 'text/xml; charset=utf-8'
    #
    # so we must use this:

    template = loader.get_template('feedjack/%s.xml' % btype)
    ctx = {}
    fjlib.get_extra_content(site, sfeeds_ids, ctx)
    ctx = RequestContext(request, ctx)
    response = HttpResponse(template.render(ctx) , \
      mimetype='text/xml; charset=utf-8')

    patch_vary_headers(response, ['Host'])
    fjcache.cache_set(site, cachekey, response)
    return response
示例#4
0
def buildfeed(request, feedclass, tag=None, subscription=None):
    """ View that handles the feeds.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    object_list = fjlib.get_paginator(site, sfeeds_ids, page=0, tag=tag, \
      subscription=subscription)[1]

    feed = feedclass(\
        title=site.title,
        link=site.url,
        description=site.description,
        feed_url='%s/%s' % (site.url, '/feed/rss/'))
    for post in object_list:
        feed.add_item( \
          title = '%s: %s' % (post.feed.name, post.title), \
          link = post.link, \
          description = post.content, \
          author_email = post.author_email, \
          author_name = post.author, \
          pubdate = post.date_modified, \
          unique_id = post.link, \
          categories = [tag.name for tag in post.tags.all()])
    response = HttpResponse(mimetype=feed.mime_type)

    # per host caching
    patch_vary_headers(response, ['Host'])

    feed.write(response, 'utf-8')
    if site.use_internal_cache:
        fjcache.cache_set(site, cachekey, response)
    return response
示例#5
0
文件: views.py 项目: mk-fg/feedjack
def _mainview(request, view_data, **criterias):
	response, site, cachekey = view_data
	if not response:
		ctx = fjlib.page_context(request, site, **criterias)
		response = render_to_response(
			u'feedjack/{0}/post_list.html'.format(site.template),
			ctx, context_instance=RequestContext(request) )
		# per host caching, in case the cache middleware is enabled
		patch_vary_headers(response, ['Host'])
		if site.use_internal_cache:
			fjcache.cache_set( site, cachekey,
				(response, ctx_get(ctx, 'last_modified')) )
	else: response = response[0]
	return response
示例#6
0
文件: views.py 项目: vinodyk/feedjack
def blogroll(request, btype):
    'View that handles the generation of blogrolls.'
    response, site, cachekey = initview(request)
    if response: return response[0]

    template = loader.get_template('feedjack/{0}.xml'.format(btype))
    ctx = fjlib.get_extra_context(request)
    ctx = Context(ctx)
    response = HttpResponse(
        template.render(ctx), content_type='text/xml; charset=utf-8' )

    patch_vary_headers(response, ['Host'])
    fjcache.cache_set(site, cachekey, (response, ctx_get(ctx, 'last_modified')))
    return response
示例#7
0
文件: views.py 项目: mk-fg/feedjack
def blogroll(request, btype):
	'View that handles the generation of blogrolls.'
	response, site, cachekey = initview(request)
	if response: return response[0]

	template = loader.get_template('feedjack/{0}.xml'.format(btype))
	ctx = dict()
	fjlib.get_extra_context(site, ctx)
	ctx = Context(ctx)
	response = HttpResponse(
		template.render(ctx), content_type='text/xml; charset=utf-8' )

	patch_vary_headers(response, ['Host'])
	fjcache.cache_set(site, cachekey, (response, ctx_get(ctx, 'last_modified')))
	return response
示例#8
0
def _mainview(request, view_data, **criterias):
    response, site, cachekey = view_data
    if not response:
        ctx = fjlib.page_context(request, site, **criterias)
        response = render_to_response(u'feedjack/{0}/post_list.html'.format(
            site.template),
                                      ctx,
                                      context_instance=RequestContext(request))
        # per host caching, in case the cache middleware is enabled
        patch_vary_headers(response, ['Host'])
        if site.use_internal_cache:
            fjcache.cache_set(site, cachekey,
                              (response, ctx_get(ctx, 'last_modified')))
    else:
        response = response[0]
    return response
示例#9
0
def getcloud(site, feed_id=None):
	""" Returns the tag cloud for a site or a site's subscriber.
	"""

	cloudict = fjcache.cache_get(site.id, 'tagclouds')
	if not cloudict:
		cloudict = cloudata(site)
		fjcache.cache_set(site, 'tagclouds', cloudict)

	# A subscriber's tag cloud has been requested.
	if feed_id:
		feed_id = int(feed_id)
		if feed_id in cloudict:
			return cloudict[feed_id]
		return []
	# The site tagcloud has been requested.
	return cloudict[0]
示例#10
0
文件: views.py 项目: vinodyk/feedjack
def buildfeed(request, feedclass, view_data):
    # TODO: quite a mess, can't it be handled with a default feed-views?
    response, site, cachekey = view_data
    if response: return response[0]

    feed_title = site.title
    if request.GET.get('feed_id'):
        try:
            feed_id = request.GET.get('feed_id')
            feed_title = u'{0} - {1}'.format(
                models.Feed.objects.get(id=feed_id).title, feed_title )
        except ObjectDoesNotExist:
            raise Http404("no such feed") # no such feed
        except ValueError: # id not numeric
            raise Http404("non-numeric feed_id")
    object_list = fjlib.get_page(request, site)['posts']

    feed = feedclass( title=feed_title, link=site.url,
        description=site.description, feed_url=u'{0}/{1}'.format(site.url, '/feed/rss/') )
    last_modified = datetime(1970, 1, 1, 0, 0, 0, 0, timezone.utc)
    for post in object_list:
        # Enclosures are not created here, as these have somewhat unpredictable format,
        #  and don't always fit Django's url+length+type style - href+title links, for instance.
        feed.add_item(
            title = u'{0}: {1}'.format(post.feed.name, post.title),
            link = post.link,
            description = fjlib.html_cleaner(post.content),
            author_email = post.author_email,
            author_name = post.author,
            pubdate = post.date_created,
            updateddate = post.date_modified,
            unique_id = post.link,
            categories = [tag.name for tag in post.tags.all()] )
        if post.date_updated > last_modified: last_modified = post.date_updated

    response = HttpResponse(content_type=feed.mime_type)

    # Per-host caching
    patch_vary_headers(response, ['Host'])

    feed.write(response, 'utf-8')
    if site.use_internal_cache:
        fjcache.cache_set(
            site, cachekey, (response, last_modified) )
    return response
示例#11
0
def blogroll(request, btype):
    """ View that handles the generation of blogrolls.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    template = loader.get_template('feedjack/%s.xml' % btype)
    ctx = {}
    fjlib.get_extra_content(site, sfeeds_ids, ctx)
    ctx = Context(ctx)
    response = HttpResponse(template.render(ctx) , \
      content_type='text/xml; charset=utf-8')

    patch_vary_headers(response, ['Host'])
    fjcache.cache_set(site, cachekey, response)
    return response
示例#12
0
def mainview(request, tag=None, subscription=None, group=None, newer=None, asc=None):
    """ View that handles all page requests.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    ctx = RequestContext(request, fjlib.page_context(request, site, tag, subscription, group, newer, asc, (sfeeds_obj, \
      sfeeds_ids)))

    response = render_to_response('feedjack/post_list.html', ctx)
    
    # per host caching, in case the cache middleware is enabled
    patch_vary_headers(response, ['Host'])

    if site.use_internal_cache:
        fjcache.cache_set(site, cachekey, response)
    return response
示例#13
0
def mainview(request, tag=None, user=None):
    """ View that handles all page requests.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    ctx = fjlib.page_context(request, site, tag, user, (sfeeds_obj, \
      sfeeds_ids))

    response = render_to_response('feedjack/%s/post_list.html' % \
      (site.template), ctx, context_instance=RequestContext(request))
    
    # per host caching, in case the cache middleware is enabled
    patch_vary_headers(response, ['Host'])

    if site.use_internal_cache:
        fjcache.cache_set(site, cachekey, response)
    return response
示例#14
0
def mainview(request, tag=None, user=None):
    """ View that handles all page requests.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    ctx = fjlib.page_context(request, site, tag, user, (sfeeds_obj, \
      sfeeds_ids))

    response = render_to_response('feedjack/%s/post_list.html' % \
      (site.template), ctx)

    # per host caching, in case the cache middleware is enabled
    patch_vary_headers(response, ['Host'])

    if site.use_internal_cache:
        fjcache.cache_set(site, cachekey, response)
    return response
示例#15
0
文件: views.py 项目: mk-fg/feedjack
def _buildfeed(request, feedclass, view_data, **criterias):
	# TODO: quite a mess, can't it be handled with a default feed-views?
	response, site, cachekey = view_data
	if response: return response[0]

	feed_title = site.title
	if criterias.get('feed_id'):
		try:
			feed_title = u'{0} - {1}'.format(
				models.Feed.objects.get(id=criterias['feed_id']).title, feed_title )
		except ObjectDoesNotExist: raise Http404 # no such feed
	object_list = fjlib.get_page(site, page=1, **criterias).object_list

	feed = feedclass( title=feed_title, link=site.url,
		description=site.description, feed_url=u'{0}/{1}'.format(site.url, '/feed/rss/') )
	last_modified = datetime(1970, 1, 1, 0, 0, 0, 0, timezone.utc)
	for post in object_list:
		# Enclosures are not created here, as these have somewhat unpredictable format,
		#  and don't always fit Django's url+length+type style - href+title links, for instance.
		feed.add_item(
			title = u'{0}: {1}'.format(post.feed.name, post.title),
			link = post.link,
			description = fjlib.html_cleaner(post.content),
			author_email = post.author_email,
			author_name = post.author,
			pubdate = post.date_created,
			updateddate = post.date_modified,
			unique_id = post.link,
			categories = [tag.name for tag in post.tags.all()] )
		if post.date_updated > last_modified: last_modified = post.date_updated

	response = HttpResponse(content_type=feed.mime_type)

	# Per-host caching
	patch_vary_headers(response, ['Host'])

	feed.write(response, 'utf-8')
	if site.use_internal_cache:
		fjcache.cache_set(
			site, cachekey, (response, last_modified) )
	return response
示例#16
0
文件: views.py 项目: chrisv2/feedjack
def buildfeed(request, feedclass, **criterias):
	'View that handles the feeds.'
	# TODO: quite a mess, can't it be handled with a default feed-vews?
	response, site, cachekey = initview(request)
	if response: return response[0]

	feed_title = site.title
	if criterias.get('feed_id'):
		try:
			feed_title = u'{0} - {1}'.format(
				models.Feed.objects.get(id=criterias['feed_id']).title, feed_title )
		except ObjectDoesNotExist: raise Http404 # no such feed
	object_list = fjlib.get_page(site, page=1, **criterias).object_list

	feed = feedclass( title=feed_title, link=site.url,
		description=site.description, feed_url=u'{0}/{1}'.format(site.url, '/feed/rss/') )
	last_modified = datetime(1970, 1, 1)
	for post in object_list:
		feed.add_item(
			title = u'{0}: {1}'.format(post.feed.name, post.title),
			link = post.link,
			description = fjlib.html_cleaner(post.content),
			author_email = post.author_email,
			author_name = post.author,
			pubdate = post.date_modified,
			unique_id = post.link,
			categories = [tag.name for tag in post.tags.all()] )
		if post.date_updated > last_modified: last_modified = post.date_updated

	response = HttpResponse(mimetype=feed.mime_type)

	# Per-host caching
	patch_vary_headers(response, ['Host'])

	feed.write(response, 'utf-8')
	if site.use_internal_cache:
		fjcache.cache_set(
			site, cachekey, (response, last_modified) )
	return response
示例#17
0
文件: views.py 项目: chrisv2/feedjack
def mainview(request, **criterias):
	'View that handles all page requests.'
	response, site, cachekey = initview(request)

	if not response:
		ctx = fjlib.page_context(request, site, **criterias)
		response = render_to_response(
			u'feedjack/{0}/post_list.html'.format(site.template),
			ctx, context_instance=RequestContext(request) )
		# per host caching, in case the cache middleware is enabled
		patch_vary_headers(response, ['Host'])
		if site.use_internal_cache:
			fjcache.cache_set(
				site, cachekey, (response, ctx['last_modified']) )
	else: response = response[0]

	fj_track_header = request.META.get('HTTP_X_FEEDJACK_TRACKING')\
		or request.COOKIES.get('feedjack.tracking')
	if fj_track_header:
		response['X-Feedjack-Tracking'] = fj_track_header
		response.set_cookie('feedjack.tracking', fj_track_header)

	return response
示例#18
0
def mainview(request,
             tag=None,
             subscription=None,
             group=None,
             newer=None,
             asc=None):
    """ View that handles all page requests.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    ctx = RequestContext(request, fjlib.page_context(request, site, tag, subscription, group, newer, asc, (sfeeds_obj, \
      sfeeds_ids)))

    response = render_to_response('feedjack/post_list.html', ctx)

    # per host caching, in case the cache middleware is enabled
    patch_vary_headers(response, ['Host'])

    if site.use_internal_cache:
        fjcache.cache_set(site, cachekey, response)
    return response
示例#19
0
def mainview(request, tag=None, user=None):
    """ View that handles all page requests.
    """

    response, site, cachekey, sfeeds_obj, sfeeds_ids = initview(request)
    if response:
        return response

    ctx = fjlib.page_context(request, site, tag, user, (sfeeds_obj, \
      sfeeds_ids))

    # we need a request context to apply the context template
    # processors (i.e. static files)
    # ctx = RequestContext(request, ctx)

    response = render(request, 'feedjack/%s/post_list.html' % site.template,
                      ctx)

    # per host caching, in case the cache middleware is enabled
    patch_vary_headers(response, ['Host'])

    if site.use_internal_cache:
        fjcache.cache_set(site, cachekey, response)
    return response
示例#20
0
文件: views.py 项目: vinodyk/feedjack
def mainview(request, view_data):
    response, site, cachekey = view_data
    if not response:
        site = models.Site.objects.get(django_site=get_current_site(request))
        feed, tag = request.GET.get('feed'), request.GET.get('tag')

        if feed:
            try:
                feed = models.Feed.objects.get(pk=feed)
            except ObjectDoesNotExist:
                raise Http404
        page = fjlib.get_page(request, site)
        object_list = page['posts']
        subscribers = site.active_subscribers

        # TODO: remove all remaining tag cloud stuff
        tag_obj, tag_cloud = None, tuple()
        try:
            user_obj = None
            if feed:
                user_obj = models.Subscriber.objects.get(site=site, feed=feed)
        except ObjectDoesNotExist:
            raise Http404

        site_proc_tags = site.processing_tags.strip()
        if site_proc_tags != 'none':
            site_proc_tags = filter( None, map(op.methodcaller('strip'), site.processing_tags.split(',')) )
            # XXX: database hit that can be cached
            for site_feed, posts in it.groupby(object_list, key=op.attrgetter('feed')):
                proc = site_feed.processor_for_tags(site_proc_tags)
                if proc:
                    proc.apply_overlay_to_posts(posts)
        # TODO: cleanup
        ctx = {
            'last_modified': max(it.imap(
                    op.attrgetter('date_updated'), object_list ))\
                if len(object_list) else datetime(1970, 1, 1, 0, 0, 0, 0, timezone.utc),
            'object_list': object_list,
            'subscribers':  subscribers.select_related('feed'),
            'tag': tag_obj,
            'feed': feed,
            'url_suffixi': ''.join((
                '/feed/{0}'.format(feed.id) if feed else '',
                '/tag/{0}'.format(escape(tag)) if tag else '' )),

            ## DEPRECATED:
            # Totally misnamed and inconsistent b/w user/user_obj,
            #  use "feed" and "subscribers" instead.
            'user_id': feed and feed.id,
            'user': user_obj,

            'num_next': page['num_next'],
            'num_previous': page['num_previous'],
            'previous_since_date': page['previous_since_date'],
            'previous_until_date': page['previous_until_date'],
            'next_since_date': page['next_since_date'],
            'next_until_date': page['next_until_date'],
            'subscriber_filter': page['subscriber_filter'],
            'url_parameters': request.GET,
        }
        ctx2 = fjlib.get_extra_context(request)
        for key in ctx2:
            ctx[key] = ctx2[key]
        response = render(request, u'feedjack/{0}/post_list.html'.format(site.template), ctx)
        # per host caching, in case the cache middleware is enabled
        patch_vary_headers(response, ['Host'])
        if site.use_internal_cache:
            fjcache.cache_set( site, cachekey,
                (response, ctx_get(ctx, 'last_modified')) )
    else:
        response = response[0]
    return response