Revision f46c95c4 snf-astakos-app/astakos/im/templatetags/filters.py
b/snf-astakos-app/astakos/im/templatetags/filters.py | ||
---|---|---|
46 | 46 |
|
47 | 47 |
DELIM = ',' |
48 | 48 |
|
49 |
|
|
49 | 50 |
@register.filter |
50 | 51 |
def monthssince(joined_date): |
51 | 52 |
now = datetime.datetime.now() |
52 |
date = datetime.datetime(year=joined_date.year, month=joined_date.month, day=1) |
|
53 |
date = datetime.datetime( |
|
54 |
year=joined_date.year, month=joined_date.month, day=1) |
|
53 | 55 |
months = [] |
54 |
|
|
56 |
|
|
55 | 57 |
month = date.month |
56 | 58 |
year = date.year |
57 |
timestamp=calendar.timegm( date.utctimetuple() )
|
|
58 |
|
|
59 |
timestamp = calendar.timegm(date.utctimetuple())
|
|
60 |
|
|
59 | 61 |
while date < now: |
60 | 62 |
months.append((year, month, timestamp)) |
61 |
|
|
63 |
|
|
62 | 64 |
if date.month < 12: |
63 | 65 |
month = date.month + 1 |
64 | 66 |
year = date.year |
65 | 67 |
else: |
66 | 68 |
month = 1 |
67 | 69 |
year = date.year + 1 |
68 |
|
|
70 |
|
|
69 | 71 |
date = datetime.datetime(year=year, month=month, day=1) |
70 |
timestamp=calendar.timegm( date.utctimetuple() )
|
|
71 |
|
|
72 |
timestamp = calendar.timegm(date.utctimetuple())
|
|
73 |
|
|
72 | 74 |
return months |
73 |
|
|
75 |
|
|
76 |
|
|
74 | 77 |
@register.filter |
75 | 78 |
def lookup(d, key): |
76 | 79 |
return d.get(key) |
... | ... | |
84 | 87 |
@register.filter |
85 | 88 |
def month_name(month_number): |
86 | 89 |
return calendar.month_name[month_number] |
87 |
|
|
90 |
|
|
88 | 91 |
|
89 | 92 |
@register.filter |
90 |
def todate(value, arg = ''):
|
|
93 |
def todate(value, arg=''):
|
|
91 | 94 |
secs = int(value) / 1000 |
92 | 95 |
return datetime.datetime.fromtimestamp(secs) |
93 | 96 |
|
94 | 97 |
|
95 | 98 |
@register.filter |
96 |
def rcut(value, chars = '/'):
|
|
99 |
def rcut(value, chars='/'):
|
|
97 | 100 |
return value.rstrip(chars) |
98 | 101 |
|
102 |
|
|
99 | 103 |
@register.filter |
100 | 104 |
def paginate(l, args): |
101 | 105 |
page, delim, sorting = args.partition(DELIM) |
... | ... | |
106 | 110 |
default = '' |
107 | 111 |
if sorting.endswith('_date'): |
108 | 112 |
default = datetime.datetime.utcfromtimestamp(0) |
109 |
l.sort(key=lambda i: getattr(i, sorting) \
|
|
110 |
if getattr(i, sorting) else default)
|
|
111 |
|
|
113 |
l.sort(key=lambda i: getattr(i, sorting) |
|
114 |
if getattr(i, sorting) else default) |
|
115 |
|
|
112 | 116 |
paginator = Paginator(l, PAGINATE_BY) |
113 |
|
|
117 |
|
|
114 | 118 |
try: |
115 | 119 |
page_number = int(page) |
116 | 120 |
except ValueError: |
... | ... | |
124 | 128 |
page = paginator.page(1) |
125 | 129 |
return page |
126 | 130 |
|
131 |
|
|
127 | 132 |
@register.filter |
128 | 133 |
def concat(str1, str2): |
129 | 134 |
if not str2: |
130 | 135 |
return str(str1) |
131 | 136 |
return '%s%s%s' % (str1, DELIM, str2) |
132 | 137 |
|
138 |
|
|
133 | 139 |
@register.filter |
134 | 140 |
def items(d): |
135 | 141 |
if isinstance(d, defaultdict): |
136 | 142 |
return d.iteritems() |
137 |
return d |
|
143 |
return d |
Also available in: Unified diff