def save(self, **kw):
        params, data = TinyDict.split(kw)

        data = {}
        ds = tc.utils.parse_datetime(params.starts)
        de = tc.utils.parse_datetime(params.ends)

        data[params.fields['date_start']['name']] = format.parse_datetime(
            ds.timetuple())

        if 'date_stop' in params.fields:
            data[params.fields['date_stop']['name']] = format.parse_datetime(
                de.timetuple())
        elif 'date_delay' in params.fields:
            # convert the end time in hours
            day_length = params.fields['day_length']

            tds = time.mktime(ds.timetuple())
            tde = time.mktime(de.timetuple())

            n = (tde - tds) / (60 * 60)

            if n > day_length:
                d = math.floor(n / 24)
                h = n % 24

                n = d * day_length + h

            data[params.fields['date_delay']['name']] = n

        ctx = dict(rpc.session.context, **(params.context or {}))
        ctx = context_with_concurrency_info(ctx, params.concurrency_info)

        error = None
        proxy = rpc.RPCProxy(params.model)

        try:
            proxy.write([params.id], data, ctx)
            info = proxy.read([params.id],
                              ['__last_update'])[0]['__last_update']
            info = {'%s,%s' % (params.model, params.id): info}
        except Exception, e:
            error = ustr(e)
Exemple #2
0
 def _to_python(self, value, state):
     # do validation
     try:
         res = time.strptime(value, self.format)
     except ValueError:
         raise formencode.api.Invalid(_('Invalid datetime format'), value, state)
     # return str instead of real datetime object
     try:
         return format.parse_datetime(value, kind=self.kind)
     except ValueError:
         raise formencode.api.Invalid(_('Invalid datetime format'), value, state)
 def _to_python(self, value, state):
     # do validation
     try:
         res = time.strptime(value, self.format)
     except ValueError:
         raise formencode.api.Invalid(_('Invalid datetime format'), value, state)
     # return str instead of real datetime object
     try:
         return format.parse_datetime(value, kind=self.kind)
     except ValueError:
         raise formencode.api.Invalid(_('Invalid datetime format'), value, state)
Exemple #4
0
    def save(self, **kw):
        params, data = TinyDict.split(kw)

        data = {}
        ds = tc.utils.parse_datetime(params.starts)
        de = tc.utils.parse_datetime(params.ends)

        data[params.fields['date_start']['name']] = format.parse_datetime(ds.timetuple())

        if 'date_stop' in params.fields:
            data[params.fields['date_stop']['name']] = format.parse_datetime(de.timetuple())
        elif 'date_delay' in params.fields:
            # convert the end time in hours
            day_length = params.fields['day_length']

            tds = time.mktime(ds.timetuple())
            tde = time.mktime(de.timetuple())

            n = (tde - tds) / (60 * 60)

            if n > day_length:
                d = math.floor(n / 24)
                h = n % 24

                n = d * day_length + h

            data[params.fields['date_delay']['name']] = n

        ctx = dict(rpc.get_session().context,
                   **(params.context or {}))
        ctx = context_with_concurrency_info(ctx, params.concurrency_info)

        error = None
        proxy = rpc.RPCProxy(params.model)

        try:
            proxy.write([params.id], data, ctx)
            info = proxy.read([params.id], ['__last_update'])[0]['__last_update']
            info = {'%s,%s'%(params.model, params.id): info}
        except Exception, e:
            error = ustr(e)