Use encoding_date for date/datetime format

This commit is contained in:
Cédric Krier committed 2008-08-26 15:09:56 +02:00
1 parent 11d4dae045
commit 88ed7093d2
6 files changed
+29 -16

No files matched your search

+12
View File
@@ -671,6 +671,18 @@ def node_attributes(node):
result[attrs.item(i).localName] = eval(attrs.item(i).nodeValue)
return result
def encoding_date(format):
format.replace('%y', '%Y')
for i in ('%a', '%A', '%j', '%w', '%W', '%Z'):
format = format.replace(i, '')
for i in ('%b', '%B'):
if i in format:
if '%m' not in format:
format = format.replace(i, '%m')
else:
format = format.replace(i, '')
return format
def hex2rgb(hexstring, digits=2):
"""
Converts a hexstring color to a rgb tuple.
@@ -6,7 +6,8 @@ import gettext
import locale
from interface import WidgetInterface
import tryton.rpc as rpc
from tryton.common import DT_FORMAT, DHM_FORMAT, HM_FORMAT, message, TRYTON_ICON
from tryton.common import DT_FORMAT, DHM_FORMAT, HM_FORMAT, message, \
TRYTON_ICON, encoding_date
from _strptime import LocaleTime
from tryton.common import date_widget
@@ -19,7 +20,7 @@ class Calendar(WidgetInterface):
def __init__(self, window, parent=None, model=None, attrs=None):
super(Calendar, self).__init__(window, parent, model=model, attrs=attrs)
self.format = LocaleTime().LC_date.replace('%y', '%Y')
self.format = encoding_date(LocaleTime().LC_date)
self.widget = date_widget.ComplexEntry(self.format, spacing=3)
self.entry = self.widget.widget
self.entry.set_property('activates_default', True)
@@ -132,7 +133,7 @@ class DateTime(WidgetInterface):
def __init__(self, window, parent, model, attrs=None):
super(DateTime, self).__init__(window, parent, model, attrs=attrs)
self.format = LocaleTime().LC_date.replace('%y', '%Y') + ' ' + HM_FORMAT
self.format = encoding_date(LocaleTime().LC_date + ' ' + HM_FORMAT)
self.widget = date_widget.ComplexEntry(self.format, spacing=3)
self.entry = self.widget.widget
self.entry.set_property('activates_default', True)
@@ -1,6 +1,7 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
import gtk
from tryton.common import hex2rgb, generateColorscheme, DT_FORMAT, COLOR_SCHEMES
from tryton.common import hex2rgb, generateColorscheme, DT_FORMAT, \
COLOR_SCHEMES, encoding_date
import locale
import math
import datetime
@@ -366,8 +367,8 @@ class Graph(gtk.DrawingArea):
while date <= end_date:
key = datetime.date(date.year, date.month, date.day)
self.labels[key] = time.strftime(
LocaleTime().LC_date.replace('%y', '%Y'),
time.strptime(str(key), DT_FORMAT))
end_date(LocaleTime().LC_date),
time.strptime(str(key), DT_FORMAT))
self.datas.setdefault(key, {})
for yfield in self.yfields:
self.datas[key].setdefault(
@@ -17,7 +17,8 @@ from tryton.gui.window.win_search import WinSearch
import tryton.rpc as rpc
import datetime as DT
from tryton.common import DT_FORMAT, DHM_FORMAT, COLORS, node_attributes, TRYTON_ICON
from tryton.common import DT_FORMAT, DHM_FORMAT, COLORS, node_attributes, \
TRYTON_ICON, encoding_date
import tryton.common as common
from _strptime import LocaleTime
from tryton.common.cellrendererbutton import CellRendererButton
@@ -313,7 +314,7 @@ class Boolean(Int):
class Date(Char):
server_format = DT_FORMAT
display_format = LocaleTime().LC_date.replace('%y', '%Y')
display_format = encoding_date(LocaleTime().LC_date)
def get_textual_value(self, model):
value = model[self.field_name].get_client(model)
@@ -339,8 +340,7 @@ class Date(Char):
class Datetime(Date):
server_format = DHM_FORMAT
display_format = LocaleTime().LC_date.replace('%y', '%Y') + \
' %H:%M:%S'
display_format = encoding_date(LocaleTime().LC_date + ' %H:%M:%S')
def get_textual_value(self, model):
value = model[self.field_name].get_client(model)
@@ -7,7 +7,7 @@ import locale
from interface import Interface
from tryton.common import DT_FORMAT
from _strptime import LocaleTime
from tryton.common import date_widget
from tryton.common import date_widget, encoding_date
_ = gettext.gettext
@@ -20,7 +20,7 @@ class Calendar(Interface):
tooltips = gtk.Tooltips()
self.widget = gtk.HBox(spacing=3)
self.format = LocaleTime().LC_date.replace('%y', '%Y')
self.format = encoding_date(LocaleTime().LC_date)
self.widget1 = date_widget.ComplexEntry(self.format, spacing=3)
self.entry1 = self.widget1.widget
+3 -4
View File
@@ -9,7 +9,7 @@ import tryton.rpc as rpc
from parse import Parse
import datetime as DT
import locale
from tryton.common import DT_FORMAT, DHM_FORMAT
from tryton.common import DT_FORMAT, DHM_FORMAT, encoding_date
import tryton.common as common
from _strptime import LocaleTime
@@ -67,14 +67,13 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable):
and 'widget' in self.fields_attrs[field]:
field_type = self.fields_attrs[field]['widget']
if field_type in ('date',):
display_format = LocaleTime().LC_date.replace('%y', '%Y')
display_format = encoding_date(LocaleTime().LC_date)
for obj in res_ids:
if obj[field]:
date = time.strptime(obj[field], DT_FORMAT)
obj[field] = time.strftime(display_format, date)
elif field_type in ('datetime',):
display_format = LocaleTime().LC_date.replace('%y', '%Y') \
+ ' %H:%M:%S'
display_format = encoding_date(LocaleTime().LC_date + ' %H:%M:%S')
for obj in res_ids:
if obj[field]:
date = time.strptime(obj[field], DHM_FORMAT)