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
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
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
def prettyhtml(value, autoescape=None): 'Clean (and optionally escape) passed html of unsafe tags and attributes.' value = html_cleaner(value) return escape(value) if autoescape\ and not isinstance(value, SafeData) else mark_safe(value)
def prettyhtml(value, autoescape=None): value = html_cleaner(value) return escape(value) if autoescape\ and not isinstance(value, SafeData) else mark_safe(value)