comparison sat/tools/common/template.py @ 3311:29f8122f00f3

tools (common/template): use `to_json` instead of `json` + added missing args to `date_fmt`
author Goffi <goffi@goffi.org>
date Thu, 16 Jul 2020 09:07:26 +0200
parents 3af0909629a2
children b65175eb7769
comparison
equal deleted inserted replaced
3310:e4121a1f2399 3311:29f8122f00f3
452 # policies 452 # policies
453 self.env.policies["ext.i18n.trimmed"] = True 453 self.env.policies["ext.i18n.trimmed"] = True
454 self.env.policies["json.dumps_kwargs"] = { 454 self.env.policies["json.dumps_kwargs"] = {
455 "sort_keys": True, 455 "sort_keys": True,
456 # if object can't be serialised, we use None 456 # if object can't be serialised, we use None
457 "default": lambda o: o.json() if hasattr(o, "json") else None 457 "default": lambda o: o.to_json() if hasattr(o, "to_json") else None
458 } 458 }
459 459
460 def getFrontURL(self, template_data, path=None): 460 def getFrontURL(self, template_data, path=None):
461 """Give front URL (i.e. URL seen by end-user) of a path 461 """Give front URL (i.e. URL seen by end-user) of a path
462 462
732 def _cur_gidx(self, ctx, value): 732 def _cur_gidx(self, ctx, value):
733 """Use current current global index as suffix""" 733 """Use current current global index as suffix"""
734 current = ctx["gidx"].current(value) 734 current = ctx["gidx"].current(value)
735 return value if not current else "{}_{}".format(value, current) 735 return value if not current else "{}_{}".format(value, current)
736 736
737 def _date_fmt(self, timestamp, fmt="short", date_only=False, auto_limit=None, 737 def _date_fmt(self, timestamp, fmt="short", date_only=False, auto_limit=7,
738 auto_old_fmt=None): 738 auto_old_fmt="short", auto_new_fmt="relative"):
739 if is_undefined(fmt): 739 if is_undefined(fmt):
740 fmt = "short" 740 fmt = "short"
741 try: 741 try:
742 return date_utils.date_fmt( 742 return date_utils.date_fmt(
743 timestamp, fmt, date_only, auto_limit, auto_old_fmt, 743 timestamp, fmt, date_only, auto_limit, auto_old_fmt,