diff options
author | Nico von Geyso <Nico.Geyso@FU-Berlin.de> | 2012-07-30 20:58:11 +0200 |
---|---|---|
committer | Nico von Geyso <Nico.Geyso@FU-Berlin.de> | 2012-07-30 20:58:11 +0200 |
commit | 847e9272ea2345e434054815e7d7ad3c3d4e104d (patch) | |
tree | e975fe66efc806a243a9262d687bc4724c7ffe2a /utils | |
parent | 85e937ad4dc3bdd4ef23b6c6f0de8d45bb692725 (diff) | |
download | www-847e9272ea2345e434054815e7d7ad3c3d4e104d.tar.gz www-847e9272ea2345e434054815e7d7ad3c3d4e104d.tar.bz2 www-847e9272ea2345e434054815e7d7ad3c3d4e104d.zip |
group blog posts by year
Diffstat (limited to 'utils')
-rw-r--r-- | utils/filters.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/utils/filters.py b/utils/filters.py index 2469419..22c9f7d 100644 --- a/utils/filters.py +++ b/utils/filters.py @@ -1,8 +1,20 @@ +def group_by_year(objs): + entries = {} + for obj in objs: + year = obj.date.strftime('%Y') + + try: + entries[year].append(obj) + except: + entries[year] = [obj] + + return entries + def filter_by_attr(objs, attr): return filter(lambda x: hasattr(x,attr), objs) def filter_by_path(objs, value): return filter(lambda page: page.path.startswith(value), objs) -filters = [filter_by_attr, filter_by_path] +filters = [filter_by_attr, filter_by_path, group_by_year] |