How to use the tryton.translate.date_format function in tryton

To help you get started, we’ve selected a few tryton examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tryton / tryton / tryton / gui / window / view_tree / view_tree.py View on Github external
and self.fields_type[field]['type'] \
                                    in ('one2many', 'many2many'):
                            val[field] = []
                        else:
                            val[field] = ''
                    res_ids.append(val)
                    if obj_id not in self.to_reload:
                        self.to_reload.append(obj_id)
        res_ids.sort(lambda x, y: cmp(ids.index(x['id']), ids.index(y['id'])))
        for field in self.fields:
            field_type = self.fields_type[field]['type']
            if field in self.fields_attrs \
                    and 'widget' in self.fields_attrs[field]:
                field_type = self.fields_attrs[field]['widget']
            if field_type in ('date',):
                display_format = date_format()
                for obj in res_ids:
                    if obj[field]:
                        obj[field] = common.datetime_strftime(obj[field],
                                display_format)
            elif field_type in ('datetime',):
                display_format = date_format() + ' ' + HM_FORMAT
                for obj in res_ids:
                    if obj[field]:
                        if 'timezone' in rpc.CONTEXT:
                            try:
                                import pytz
                                lzone = pytz.timezone(rpc.CONTEXT['timezone'])
                                szone = pytz.timezone(rpc.TIMEZONE)
                                sdt = szone.localize(obj[field], is_dst=True)
                                ldt = sdt.astimezone(lzone)
                                obj[field] = ldt
github tryton / tryton / tryton / common / tdp.py View on Github external
return 0.0
    elif type_ == 'numeric':
        try:
            return Decimal(value)
        except decimal.InvalidOperation:
            return Decimal(0)
    elif type_ in ('selection', 'reference'):
        for key, text in field['selection']:
            if text == value:
                return key
        return value
    elif type_ == 'datetime':
        value = value.replace(' : ', ':')  # Parser add spaces arround :
        try:
            value = datetime.datetime(*time.strptime(value,
                    date_format() + ' ' + HM_FORMAT)[:6])
        except ValueError:
            try:
                value = datetime.datetime(*time.strptime(value,
                        date_format())[:6])
            except ValueError:
                return False
        return timezoned_date(value)
    elif type_ == 'date':
        try:
            return datetime.date(*time.strptime(value, date_format())[:3])
        except ValueError:
            return False
    else:
        return value
github tryton / tryton / tryton / gui / window / view_form / widget_search / calendar.py View on Github external
def __init__(self, name, attrs=None, context=None,
            on_change=None):
        super(Calendar, self).__init__(name, attrs=attrs, context=context,
            on_change=on_change)

        tooltips = Tooltips()
        self.widget = gtk.HBox(spacing=3)

        self.format = date_format()

        self.liststore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        self.combo = gtk.ComboBox(self.liststore)
        cell = gtk.CellRendererText()
        self.combo.pack_start(cell, True)
        self.combo.add_attribute(cell, 'text', 1)
        for oper in (['=', _('is')],
                ['between', _('is between')],
                ['not between', _('is not between')],
                ['!=', _('is not')],
                ):
            self.liststore.append(oper)
        self.combo.set_active(0)
        self.widget.pack_start(self.combo, False, False)
        self.combo.connect('changed', self._changed)
        self.combo.connect('changed', self.on_change)
github tryton / tryton / tryton / gui / window / view_tree / view_tree.py View on Github external
if obj_id not in self.to_reload:
                        self.to_reload.append(obj_id)
        res_ids.sort(lambda x, y: cmp(ids.index(x['id']), ids.index(y['id'])))
        for field in self.fields:
            field_type = self.fields_type[field]['type']
            if field in self.fields_attrs \
                    and 'widget' in self.fields_attrs[field]:
                field_type = self.fields_attrs[field]['widget']
            if field_type in ('date',):
                display_format = date_format()
                for obj in res_ids:
                    if obj[field]:
                        obj[field] = common.datetime_strftime(obj[field],
                                display_format)
            elif field_type in ('datetime',):
                display_format = date_format() + ' ' + HM_FORMAT
                for obj in res_ids:
                    if obj[field]:
                        if 'timezone' in rpc.CONTEXT:
                            try:
                                import pytz
                                lzone = pytz.timezone(rpc.CONTEXT['timezone'])
                                szone = pytz.timezone(rpc.TIMEZONE)
                                sdt = szone.localize(obj[field], is_dst=True)
                                ldt = sdt.astimezone(lzone)
                                obj[field] = ldt
                            except Exception:
                                pass
                        obj[field] = common.datetime_strftime(obj[field],
                                display_format)
            elif field_type in ('many2one', 'one2one'):
                for obj in res_ids:
github tryton / tryton / tryton / common / tdp.py View on Github external
except decimal.InvalidOperation:
            return Decimal(0)
    elif type_ in ('selection', 'reference'):
        for key, text in field['selection']:
            if text == value:
                return key
        return value
    elif type_ == 'datetime':
        value = value.replace(' : ', ':')  # Parser add spaces arround :
        try:
            value = datetime.datetime(*time.strptime(value,
                    date_format() + ' ' + HM_FORMAT)[:6])
        except ValueError:
            try:
                value = datetime.datetime(*time.strptime(value,
                        date_format())[:6])
            except ValueError:
                return False
        return timezoned_date(value)
    elif type_ == 'date':
        try:
            return datetime.date(*time.strptime(value, date_format())[:3])
        except ValueError:
            return False
    else:
        return value
github tryton / tryton / tryton / common / tdp.py View on Github external
def test_datetime_complete():
    today = datetime.date.today()
    today_str = datetime_strftime(today, date_format())
    parser = test_parser()
    assert list(parser.parse('Date Time: ' + today_str).complete()) == [
        'Date Time: ' + today_str]
    assert list(parser.parse('Date Time: "' + today_str + ' 12:30:00"'
            ).complete()) == ['Date Time: "' + today_str + ' 12:30:00"']
    assert list(parser.parse('Date Time: ' + today_str + ' 12:30:00'
            ).complete()) == ['Date Time: "' + today_str + ' 12:30:00"']