diff roundup/cgi/templating.py @ 6377:a7e7314fb7d9

issue2551126 - AttributeError: 'str' object has no attribute 'local'. Fix traceback caused by DateHTMLProperty.pretty() called on a string value due to error in some other field.
author John Rouillard <rouilj@ieee.org>
date Sat, 10 Apr 2021 22:10:07 -0400
parents 6f89cdc7c938
children 26e5c42f148c
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Wed Apr 07 15:18:25 2021 +0200
+++ b/roundup/cgi/templating.py	Sat Apr 10 22:10:07 2021 -0400
@@ -2244,12 +2244,16 @@
         else:
             offset = self._offset
 
-        if not self._value:
-            return ''
-        elif format is not self._marker:
-            return self._value.local(offset).pretty(format)
-        else:
-            return self._value.local(offset).pretty()
+        try:
+            if not self._value:
+                return ''
+            elif format is not self._marker:
+                return self._value.local(offset).pretty(format)
+            else:
+                return self._value.local(offset).pretty()
+        except AttributeError:
+            # not a date value, e.g. from unsaved form data
+            return str(self._value)
 
     def local(self, offset):
         """ Return the date/time as a local (timezone offset) date/time.

Roundup Issue Tracker: http://roundup-tracker.org/