summaryrefslogtreecommitdiffstats
path: root/utils/filters.py
blob: 22c9f7dfee0eb89f48808b925dc75c2667fc5755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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, group_by_year]