comparison roundup/cgi/templating.py @ 2955:6d3e2848e0ba maint-0.7

format parameter for DateHTMLProperty.field() (based on patch [SF#1072834])
author Alexander Smishlajev <a1s@users.sourceforge.net>
date Thu, 25 Nov 2004 10:21:11 +0000
parents b72cd8fa1b9c
children 409510fcb18f
comparison
equal deleted inserted replaced
2950:448cc54ffa1d 2955:6d3e2848e0ba
1278 checked="checked") 1278 checked="checked")
1279 s += 'No' 1279 s += 'No'
1280 return s 1280 return s
1281 1281
1282 class DateHTMLProperty(HTMLProperty): 1282 class DateHTMLProperty(HTMLProperty):
1283
1284 _marker = []
1285
1283 def __init__(self, client, classname, nodeid, prop, name, value, 1286 def __init__(self, client, classname, nodeid, prop, name, value,
1284 anonymous=0, offset=None): 1287 anonymous=0, offset=None):
1285 HTMLProperty.__init__(self, client, classname, nodeid, prop, name, 1288 HTMLProperty.__init__(self, client, classname, nodeid, prop, name,
1286 value, anonymous=anonymous) 1289 value, anonymous=anonymous)
1287 self._offset = offset 1290 self._offset = offset
1308 self.view_check() 1311 self.view_check()
1309 1312
1310 return DateHTMLProperty(self._client, self._classname, self._nodeid, 1313 return DateHTMLProperty(self._client, self._classname, self._nodeid,
1311 self._prop, self._formname, date.Date('.')) 1314 self._prop, self._formname, date.Date('.'))
1312 1315
1313 def field(self, size=30): 1316 def field(self, size=30, format=_marker):
1314 ''' Render a form edit field for the property 1317 '''Render a form edit field for the property
1315 1318
1316 If not editable, just display the value via plain(). 1319 If not editable, just display the value via plain().
1317 ''' 1320
1318 self.view_check() 1321 The format string is a standard python strftime format string.
1322 '''
1323 self.view_check()
1324 if not self.is_edit_ok():
1325 if format is self._marker:
1326 return self.plain()
1327 else:
1328 return self.pretty(format)
1319 1329
1320 if self._value is None: 1330 if self._value is None:
1321 value = '' 1331 value = ''
1322 elif type(self._value) is type(''): 1332 elif type(self._value) is type(''):
1323 value = self._value 1333 if format is self._marker:
1334 value = self._value
1335 else:
1336 value = date.Date(self._value).pretty(format)
1324 else: 1337 else:
1325 tz = self._db.getUserTimezone() 1338 tz = self._db.getUserTimezone()
1326 value = cgi.escape(str(self._value.local(tz))) 1339 value = self._value.local(tz)
1327 1340 if format is not self._marker:
1328 if self.is_edit_ok(): 1341 value = value.pretty(format)
1329 value = '&quot;'.join(value.split('"')) 1342
1330 return self.input(name=self._formname,value=value,size=size) 1343 value = cgi.escape(str(value), True)
1331 1344 return self.input(name=self._formname, value=value, size=size)
1332 return self.plain()
1333 1345
1334 def reldate(self, pretty=1): 1346 def reldate(self, pretty=1):
1335 ''' Render the interval between the date and now. 1347 ''' Render the interval between the date and now.
1336 1348
1337 If the "pretty" flag is true, then make the display pretty. 1349 If the "pretty" flag is true, then make the display pretty.
1345 interval = self._value - date.Date('.') 1357 interval = self._value - date.Date('.')
1346 if pretty: 1358 if pretty:
1347 return interval.pretty() 1359 return interval.pretty()
1348 return str(interval) 1360 return str(interval)
1349 1361
1350 _marker = []
1351 def pretty(self, format=_marker): 1362 def pretty(self, format=_marker):
1352 ''' Render the date in a pretty format (eg. month names, spaces). 1363 ''' Render the date in a pretty format (eg. month names, spaces).
1353 1364
1354 The format string is a standard python strftime format string. 1365 The format string is a standard python strftime format string.
1355 Note that if the day is zero, and appears at the start of the 1366 Note that if the day is zero, and appears at the start of the
1356 string, then it'll be stripped from the output. This is handy 1367 string, then it'll be stripped from the output. This is handy
1357 for the situatin when a date only specifies a month and a year. 1368 for the situatin when a date only specifies a month and a year.
1358 ''' 1369 '''
1359 self.view_check() 1370 self.view_check()
1360 1371
1361 if format is not self._marker: 1372 if not self._value:
1373 return ''
1374 elif format is not self._marker:
1362 return self._value.pretty(format) 1375 return self._value.pretty(format)
1363 else: 1376 else:
1364 return self._value.pretty() 1377 return self._value.pretty()
1365 1378
1366 def local(self, offset): 1379 def local(self, offset):

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