# ./utils/localdatetimefilters.py
from time import mktime
from google.appengine.ext import webapp
def localdate(value, arg=None):
from django.conf import settings
from django.template import defaultfilters
if not value:
return ''
if arg is None:
arg = settings.DATE_FORMAT
content = '''''' % (
mktime(value.utctimetuple())*1000,
defaultfilters.date(value, arg)
)
return content
def localtime(value, arg=None):
from django.conf import settings
from django.template import defaultfilters
if not value:
return ''
if arg is None:
arg = settings.TIME_FORMAT
content = '''''' % (
mktime(value.utctimetuple())*1000,
defaultfilters.time(value, arg)
)
return content
def localdatetime(value, arg1=None, arg2=None):
from django.conf import settings
from django.template import defaultfilters
if not value:
return ''
if arg1 is None:
arg1 = settings.DATE_FORMAT
if arg2 is None:
arg2 = settings.TIME_FORMAT
content = '''''' % (
mktime(value.utctimetuple())*1000,
defaultfilters.date(value, arg1),
defaultfilters.time(value, arg2)
)
return content
register = webapp.template.create_template_register()
register.filter(localdate)
register.filter(localtime)
register.filter(localdatetime)
# ./main.py (Request handler)
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
def main():
webapp.template.register_template_library('utils.localdatetimefilters')