1. Olemis Lang
  2. trac-gviz

Commits

Olemis Lang  committed f98adf0

GViz QL [ refs #299 ] : Refactor 'format_value' to support any object implementing format(value) contract

  • Participants
  • Parent commits fcd8ab3
  • Branches default

Comments (0)

Files changed (1)

File trac-dev/gviz/tracgviz/gvizql.py

View file
   def format_value(cls, value, coltype, formatter):
     r"""Format value of given data type according to some formatting pattern.
     """
+    supported = False
     if coltype == 'boolean':
       # Formatter is a binary tuple
       idx = 0 if bool(value) else 1
       return formatter[idx]
+      supported = True
     elif coltype in cls.DATETIME_CONVERTER:
-      # Formatter is an instance of PyICU.SimpleDateFormat
-      return formatter.format(cls.DATETIME_CONVERTER[coltype](value)) \
-          .encode('utf8')
-    elif coltype == 'number':
-      # Formatter is an instance of PyICU.DecimalFormat
+      value = cls.DATETIME_CONVERTER[coltype](value)
+      supported = True
+    else:
+      supported = coltype in ('number',)
+    if supported:
+      # For dates default formatter is an instance of PyICU.SimpleDateFormat
+      # For numbers default formatter is an instance of PyICU.DecimalFormat
       return formatter.format(value).encode('utf8')
     else:
       raise GVizRuntimeError("Format not supported for %s type" % (coltype,))