Package coprs :: Module filters
[hide private]
[frames] | no frames]

Source Code for Module coprs.filters

 1  import datetime 
 2  import pytz 
 3  import time 
 4  from coprs import app 
 5  from coprs import helpers 
6 7 @app.template_filter('date_from_secs') 8 -def date_from_secs(secs):
9 return time.strftime('%Y-%m-%d %H:%M:%S %Z', time.gmtime(secs)) if secs else None
10
11 @app.template_filter('perm_type_from_num') 12 -def perm_type_from_num(num):
13 return helpers.PermissionEnum(num)
14
15 # this should probably be stored in DB with the whole mock_chroot... 16 @app.template_filter('os_name_short') 17 -def os_name_short(os_name, os_version):
18 # TODO: make it models.MockChroot method or not? 19 if os_version: 20 if os_version == 'rawhide': 21 return os_version 22 if os_name == 'fedora': 23 return 'fc.{0}'.format(os_version) 24 elif os_name == 'epel': 25 return 'el{0}'.format(os_version) 26 return os_name
27
28 @app.template_filter('localized_time') 29 -def localized_time(time_in, timezone):
30 """ return time shifted into timezone (and printed in ISO format) 31 32 Input is in EPOCH (seconds since epoch). 33 """ 34 if not time_in: 35 return "Not yet" 36 format_tz = "%Y-%m-%d %H:%M:%S %Z" 37 utc_tz = pytz.timezone('UTC') 38 if timezone: 39 user_tz = pytz.timezone(timezone) 40 else: 41 user_tz = utc_tz 42 dt_aware = datetime.datetime.fromtimestamp(time_in).replace(tzinfo=utc_tz) 43 dt_my_tz = dt_aware.astimezone(user_tz) 44 return dt_my_tz.strftime(format_tz)
45