commit 7866f895d3859966e92093c8e5ed926f749f8379
parent fe28aedca6a4a836553dbf1d27080ee2c2723d11
Author: Dan Callaghan <djc@djc.id.au>
Date: Fri, 19 Sep 2008 01:55:02 +1000
handle boundary cases for offset arg
Diffstat:
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/TODO b/TODO
@@ -18,7 +18,6 @@
- something better for viewutils.tag_list (at least fix URL quoting)
- have almost completely ditched colubrid, just need to replace StaticExports for testing then rm it
- use encoding from config for blog.py instead of hard-coding utf8
-- invalid offsets (displays every entry at max and 500's on invalid such as alpha)
- config option to add next/prev links to page (as well as the link rels)
- markdown typography/smartypants
- or even just, better markdown
diff --git a/app.py b/app.py
@@ -112,9 +112,14 @@ class Constance(object):
urls = [(re.compile(patt), method) for patt, method in urls]
def index(self):
- offset = int(self.args.get('offset', 0))
+ try:
+ offset = int(self.args.get('offset', 0))
+ except ValueError:
+ raise NotFoundError('Invalid offset %r' % self.args['offset'])
sorted_entries = sorted(chain(self.blog_entries, self.readinglog_entries),
key=lambda e: e.publication_date, reverse=True)
+ if offset >= len(sorted_entries):
+ raise NotFoundError('Offset beyond end of entries')
format = self.args.get('format', 'html')
if format == 'html':
rendered = template_loader.load('multiple.xml').generate(
@@ -200,8 +205,13 @@ class Constance(object):
with_tag = [e for e in self.blog_entries if tag in e.tags]
if not with_tag:
raise NotFoundError()
- offset = int(self.args.get('offset', 0))
+ try:
+ offset = int(self.args.get('offset', 0))
+ except ValueError:
+ raise NotFoundError('Invalid offset %r' % self.args['offset'])
sorted_entries = sorted(with_tag, key=lambda e: e.publication_date, reverse=True)
+ if offset >= len(sorted_entries):
+ raise NotFoundError('Offset beyond end of entries')
format = self.args.get('format', 'html')
if format == 'html':
rendered = template_loader.load('multiple.xml').generate(