@@ -365,48 +365,73 @@ def maybe_call(obj, *args, **kwargs):
365365 return obj (* args , ** kwargs )
366366
367367
368+ def reference_represent (value ):
369+ """
370+ Assumes value is a pydal.objects.Reference value and represts is using the
371+ table._format of the referenced table
372+ """
373+ table = value ._table
374+ row = table (row )
375+ if isinstance (table ._format , str ):
376+ return table ._format % row
377+ elif callable (table ._format ):
378+ return table ._format (row )
379+ else :
380+ return str (value )
381+
382+
383+ def datetime_represent (value ):
384+ """Represents a datetime value"""
385+ if not value or not isinstance (value , datetime .datetime ):
386+ return value or ""
387+ return XML (
388+ "<script>document.write((new Date(%s,%s,%s,%s,%s,%s)).toLocaleString())</script>"
389+ % (
390+ value .year ,
391+ value .month - 1 ,
392+ value .day ,
393+ value .hour ,
394+ value .minute ,
395+ value .second ,
396+ )
397+ )
398+
399+
400+ def date_represent (value ):
401+ """Represents a date value"""
402+ if not value or not isinstance (value , datetime .date ):
403+ return value or ""
404+ return XML (
405+ '<script>document.write((new Date(%s,%s,%s)).toLocaleString().split(",")[0])</script>'
406+ % (
407+ value .year ,
408+ value .month - 1 ,
409+ value .day ,
410+ )
411+ )
412+
413+
414+ def time_represent (value ):
415+ """Represents a time value"""
416+ if not value or not isinstance (value , datetime .time ):
417+ return value or ""
418+ return XML (
419+ "<script>document.write((new Date(0, 0, 0,%s,%s,%s)).toLocaleString().split(', ')[1])</script>"
420+ % (value .hour , value .minute , value .second )
421+ )
422+
423+
368424class Grid :
369425 FORMATTERS_BY_TYPE = {
370426 "NoneType" : lambda value : "" ,
371427 "bool" : lambda value : "☑" if value else "☐" if value is False else "" ,
372428 "float" : lambda value : "%.2f" % value ,
373429 "double" : lambda value : "%.2f" % value ,
374- "datetime" : lambda value : (
375- XML (
376- "<script>document.write((new Date(%s,%s,%s,%s,%s,%s)).toLocaleString())</script>"
377- % (
378- value .year ,
379- value .month - 1 ,
380- value .day ,
381- value .hour ,
382- value .minute ,
383- value .second ,
384- )
385- )
386- if value and isinstance (value , datetime .datetime )
387- else (value or "" )
388- ),
389- "time" : lambda value : (
390- XML (
391- "<script>document.write((new Date(0, 0, 0,%s,%s,%s)).toLocaleString().split(', ')[1])</script>"
392- % (value .hour , value .minute , value .second )
393- )
394- if value and isinstance (value , datetime .time )
395- else (value or "" )
396- ),
397- "date" : lambda value : (
398- XML (
399- '<script>document.write((new Date(%s,%s,%s)).toLocaleString().split(",")[0])</script>'
400- % (
401- value .year ,
402- value .month - 1 ,
403- value .day ,
404- )
405- )
406- if value and isinstance (value , datetime .date )
407- else (value or "" )
408- ),
409- "list" : lambda value : ", " .join (x for x in value ) or "" ,
430+ "Reference" : reference_represent ,
431+ "datetime" : datetime_represent ,
432+ "date" : date_represent ,
433+ "time" : time_represent ,
434+ "list" : lambda value : ", " .join (str (x ) for x in value ) or "" ,
410435 }
411436
412437 def __init__ (
0 commit comments