Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/templateFilters.py

Issue 11481051: Update stats processing (Closed)
Patch Set: Fixed two presentation issues Created Aug. 24, 2013, 1:11 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sitescripts/templateFilters.py
===================================================================
--- a/sitescripts/templateFilters.py
+++ b/sitescripts/templateFilters.py
@@ -17,17 +17,17 @@
import re, email.header, urllib, time, json
from datetime import date
from jinja2.utils import Markup
from urlparse import urlparse
def formattime(value):
try:
- return time.strftime('%Y-%m-%d %H:%M GMT', time.gmtime(int(value)))
+ return time.strftime('%Y-%m-%d %H:%M UTC', time.gmtime(int(value)))
except Exception, e:
return 'unknown'
def formatrelativetime(value, baseTime):
try:
value = float(value)
params = {'title': formattime(baseTime + value), 'number': value, 'prefix': 'in ', 'suffix': '', 'unit': 'second(s)'}
if params['number'] < 0:
@@ -135,19 +135,16 @@ def rjust(value, width=80):
return unicode(value).rjust(width)
def ltruncate(value, length=255, end='...'):
value = unicode(value)
if len(value) <= length:
return value
return end + value[len(value) - length:len(value)]
-def formatmonthname(value, format='%b %Y'):
- return date(int(value[0:4]), int(value[4:]), 1).strftime(format)
-
def formatweekday(value):
return time.strftime('%a', (0, 0, 0, 0, 0, 0, value, 0, 0))
def formatbytes(value):
if value == 0:
return '0'
value = float(value)
@@ -158,33 +155,16 @@ def formatbytes(value):
if value > 1024:
value /= 1024
unit = 'MB'
if value > 1024:
value /= 1024
unit = 'GB'
return '%.2f %s' % (value, unit)
-def getsum(iterable, attribute=None):
- if attribute == None:
- return sum(iterable)
- else:
- return sum(item[attribute] for item in iterable)
-
-def getmax(iterable, attribute=None):
- if len(iterable) == 0:
- return 0
- elif attribute == None:
- return max(iterable)
- else:
- return max(iterable, key=lambda item: item[attribute])[attribute]
-
-def ensuremin(value, minvalue=1):
- return max(value, minvalue)
-
def toJSON(value, **args):
return re.sub(r'</script>', r'<\/script>', json.dumps(value, **args))
filters = {
'formattime': formattime,
'timerelative': formatrelativetime,
'url': formaturl,
'keepnewlines': formatnewlines,
@@ -192,15 +172,11 @@ filters = {
'buglinks': formatBugLinks,
'urlencode': urlencode,
'subscriptionSort': subscriptionSort,
'mime': formatmime,
'ljust': ljust,
'rjust': rjust,
'ltruncate': ltruncate,
'weekday': formatweekday,
- 'monthname': formatmonthname,
'bytes': formatbytes,
- 'sum': getsum,
- 'max': getmax,
- 'ensuremin': ensuremin,
'json': toJSON,
}

Powered by Google App Engine
This is Rietveld