예제 #1
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
예제 #2
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
예제 #3
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
예제 #4
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