appobject.py
changeset 2002 031414d88003
parent 2001 c6bb482f40c6
child 2058 7ef12c03447c
child 2098 13aab3775af7
equal deleted inserted replaced
2001:c6bb482f40c6 2002:031414d88003
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 """
     7 """
     8 __docformat__ = "restructuredtext en"
     8 __docformat__ = "restructuredtext en"
     9 
     9 
    10 from datetime import datetime, timedelta
    10 from datetime import datetime, timedelta, time
    11 
    11 
    12 from logilab.common.decorators import classproperty
    12 from logilab.common.decorators import classproperty
    13 from logilab.common.deprecation import obsolete
    13 from logilab.common.deprecation import obsolete
    14 
    14 
    15 from rql.nodes import VariableRef, SubQuery
    15 from rql.nodes import VariableRef, SubQuery
   303         # XXX raise proper validation error
   303         # XXX raise proper validation error
   304         if etype == 'Datetime':
   304         if etype == 'Datetime':
   305             format = self.req.property_value('ui.datetime-format')
   305             format = self.req.property_value('ui.datetime-format')
   306             try:
   306             try:
   307                 return todatetime(strptime(value, format))
   307                 return todatetime(strptime(value, format))
   308             except:
   308             except ValueError:
   309                 pass
   309                 pass
   310         elif etype == 'Time':
   310         elif etype == 'Time':
   311             format = self.req.property_value('ui.time-format')
   311             format = self.req.property_value('ui.time-format')
   312             try:
   312             try:
   313                 # (adim) I can't find a way to parse a Time with a custom format
   313                 # (adim) I can't find a way to parse a Time with a custom format
   314                 date = strptime(value, format) # this returns a DateTime
   314                 date = strptime(value, format) # this returns a DateTime
   315                 return datetime.time(date.hour, date.minute, date.second)
   315                 return time(date.hour, date.minute, date.second)
   316             except:
   316             except ValueError:
   317                 raise ValueError('can\'t parse %r (expected %s)' % (value, format))
   317                 raise ValueError('can\'t parse %r (expected %s)' % (value, format))
   318         try:
   318         try:
   319             format = self.req.property_value('ui.date-format')
   319             format = self.req.property_value('ui.date-format')
   320             dt = strptime(value, format)
   320             dt = strptime(value, format)
   321             if etype == 'Datetime':
   321             if etype == 'Datetime':
   322                 return todatetime(dt)
   322                 return todatetime(dt)
   323             return todate(dt)
   323             return todate(dt)
   324         except:
   324         except ValueError:
   325             raise ValueError('can\'t parse %r (expected %s)' % (value, format))
   325             raise ValueError('can\'t parse %r (expected %s)' % (value, format))
   326 
   326 
   327     # security related methods ################################################
   327     # security related methods ################################################
   328 
   328 
   329     def ensure_ro_rql(self, rql):
   329     def ensure_ro_rql(self, rql):