Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
preetwinder
erp5
Commits
7a5b64d5
Commit
7a5b64d5
authored
Sep 28, 2012
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support timezone conversion on date fields
parent
a96aa643
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
product/Formulator/Widget.py
product/Formulator/Widget.py
+10
-1
product/ZSQLCatalog/SearchKey/DateTimeKey.py
product/ZSQLCatalog/SearchKey/DateTimeKey.py
+3
-0
No files found.
product/Formulator/Widget.py
View file @
7a5b64d5
...
@@ -1368,7 +1368,8 @@ class DateTimeWidget(Widget):
...
@@ -1368,7 +1368,8 @@ class DateTimeWidget(Widget):
default_timezone
=
fields
.
ListField
(
'default_timezone'
,
default_timezone
=
fields
.
ListField
(
'default_timezone'
,
title
=
"Default Timezone"
,
title
=
"Default Timezone"
,
description
=
(
description
=
(
"The default timezone display when inputing a new date"
),
"The default timezone display when inputing a new date."
"Upon display, the dates are converted to this timezone"
),
default
=
""
,
default
=
""
,
items
=
all_timezones
,
items
=
all_timezones
,
size
=
1
)
size
=
1
)
...
@@ -1424,6 +1425,7 @@ class DateTimeWidget(Widget):
...
@@ -1424,6 +1425,7 @@ class DateTimeWidget(Widget):
This only describes the field format settings, not the actual
This only describes the field format settings, not the actual
format of provided value.
format of provided value.
query : Passthrough of given value.
query : Passthrough of given value.
timezone: the timezone to consider.
"""
"""
if
not
value
:
if
not
value
:
return
None
return
None
...
@@ -1434,11 +1436,13 @@ class DateTimeWidget(Widget):
...
@@ -1434,11 +1436,13 @@ class DateTimeWidget(Widget):
value
=
value
.
encode
(
field
.
get_form_encoding
())
value
=
value
.
encode
(
field
.
get_form_encoding
())
return
{
'query'
:
value
,
return
{
'query'
:
value
,
'format'
:
field
.
get_value
(
'date_separator'
).
join
(
input_order
),
'format'
:
field
.
get_value
(
'date_separator'
).
join
(
input_order
),
'timezone'
:
field
.
get_value
(
'default_timezone'
),
'type'
:
'date'
}
'type'
:
'date'
}
def
render
(
self
,
field
,
key
,
value
,
REQUEST
,
render_prefix
=
None
):
def
render
(
self
,
field
,
key
,
value
,
REQUEST
,
render_prefix
=
None
):
use_ampm
=
field
.
get_value
(
'ampm_time_style'
)
use_ampm
=
field
.
get_value
(
'ampm_time_style'
)
use_timezone
=
field
.
get_value
(
'timezone_style'
)
use_timezone
=
field
.
get_value
(
'timezone_style'
)
timezone
=
field
.
get_value
(
'default_timezone'
)
# FIXME: backwards compatibility hack:
# FIXME: backwards compatibility hack:
if
not
hasattr
(
field
,
'sub_form'
):
if
not
hasattr
(
field
,
'sub_form'
):
from
StandardFields
import
create_datetime_text_sub_form
from
StandardFields
import
create_datetime_text_sub_form
...
@@ -1461,6 +1465,8 @@ class DateTimeWidget(Widget):
...
@@ -1461,6 +1465,8 @@ class DateTimeWidget(Widget):
ampm
=
None
ampm
=
None
timezone
=
field
.
get_value
(
"default_timezone"
)
timezone
=
field
.
get_value
(
"default_timezone"
)
if
isinstance
(
value
,
DateTime
):
if
isinstance
(
value
,
DateTime
):
if
timezone
:
value
=
value
.
toZone
(
timezone
)
year
=
"%04d"
%
value
.
year
()
year
=
"%04d"
%
value
.
year
()
month
=
"%02d"
%
value
.
month
()
month
=
"%02d"
%
value
.
month
()
day
=
"%02d"
%
value
.
day
()
day
=
"%02d"
%
value
.
day
()
...
@@ -1525,6 +1531,9 @@ class DateTimeWidget(Widget):
...
@@ -1525,6 +1531,9 @@ class DateTimeWidget(Widget):
use_ampm
=
field
.
get_value
(
'ampm_time_style'
)
use_ampm
=
field
.
get_value
(
'ampm_time_style'
)
use_timezone
=
field
.
get_value
(
'timezone_style'
)
use_timezone
=
field
.
get_value
(
'timezone_style'
)
default_timezone
=
field
.
get_value
(
'default_timezone'
)
if
default_timezone
:
value
=
value
.
toZone
(
default_timezone
)
year
=
"%04d"
%
value
.
year
()
year
=
"%04d"
%
value
.
year
()
month
=
"%02d"
%
value
.
month
()
month
=
"%02d"
%
value
.
month
()
...
...
product/ZSQLCatalog/SearchKey/DateTimeKey.py
View file @
7a5b64d5
...
@@ -59,7 +59,10 @@ def castDate(value, change_timezone=True):
...
@@ -59,7 +59,10 @@ def castDate(value, change_timezone=True):
# input.
# input.
assert
value
[
'type'
]
==
'date'
assert
value
[
'type'
]
==
'date'
format
=
value
.
get
(
'format'
)
format
=
value
.
get
(
'format'
)
timezone
=
value
.
get
(
'timezone'
)
value
=
value
[
'query'
]
value
=
value
[
'query'
]
if
timezone
:
value
=
"%s %s"
%
(
value
,
timezone
)
if
format
==
'%m/%d/%Y'
:
if
format
==
'%m/%d/%Y'
:
date_kw
.
pop
(
'datefmt'
)
date_kw
.
pop
(
'datefmt'
)
if
isinstance
(
value
,
DateTime
):
if
isinstance
(
value
,
DateTime
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment