Workout With Friends
Stay fit with a little motivation
 All Classes Namespaces Files Functions Variables Properties
filters.py
Go to the documentation of this file.
1 ##
2 #
3 # Custom Jinja2 template filters.
4 #
5 
6 import itertools
7 import pretty
8 from webhelpers import text
9 from wowf.lib.utils import to_user_timezone
10 
11 
12 ##
13 #
14 # Format the given datetime according to the given format.
15 #
16 # @param value datetime instance
17 # @param timezone Timezone to convert to before rendering
18 #
19 def datetimeformat(value, format='%I:%M %p on %b %d', timezone=None):
20  if timezone:
21  value = to_user_timezone(value, timezone)
22  return value.strftime(format)
23 
24 
25 ##
26 #
27 # Show the elapsed time since the given datetime.
28 #
29 # @param value datetime instance
30 #
31 def timesince(value, asdays=False, short=True):
32  return pretty.date(value, asdays, short)
33 
34 
35 ##
36 #
37 # @param value Number of items
38 # @param singular Singular form of items
39 # @param plural Plural form of items
40 #
41 def pluralize(value, singular, plural, with_number=True):
42  return text.plural(value, singular, plural, with_number)
43 
44 
45 ##
46 #
47 # Group items by date.
48 #
49 def groupbydate(value):
50  return itertools.groupby(value,
51  lambda item: (item.created_at.year, item.created_at.month, item.created_at.day))
52