Skip to content

Commit

Permalink
Implemented the 'nearby' template filter, which filters an entryset b…
Browse files Browse the repository at this point in the history
…ased on selecting 2 objects before and 2 objects after the specified object. (For example, you could order by published date, and then get the previous two chronological and next two chronological objects.)
  • Loading branch information
lethain committed Jan 18, 2009
1 parent dd62705 commit d2625f7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions templatetags/lifeflow.py
Expand Up @@ -18,3 +18,22 @@ def boundary(value, arg):

register.filter('boundary', boundary)

def nearby(lst, obj, count=5):
lst = list(lst)
l = len(lst)
print l
try:
pos = lst.index(obj)
except ValueError:
pos = 0
dist = count / 2
print pos
print dist
if pos <= dist:
return lst[:count]
if pos >= l - dist:
return lst[l-count:]
else:
return lst[pos-dist:pos+dist+1]

register.filter('nearby', nearby)

0 comments on commit d2625f7

Please sign in to comment.