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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mikolaï Krol
erp5
Commits
1311964f
Commit
1311964f
authored
Mar 05, 2015
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formulator DateTimeFiled: support list input style
parent
6fc417d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
20 deletions
+50
-20
product/Formulator/Widget.py
product/Formulator/Widget.py
+50
-20
No files found.
product/Formulator/Widget.py
View file @
1311964f
...
...
@@ -1390,6 +1390,17 @@ class DateTimeWidget(Widget):
input_order
=
'my'
return
input_order
def
create_items
(
self
,
start
,
end
,
digits
=
0
):
result
=
[(
"-"
,
""
)]
if
digits
:
format_string
=
"%0"
+
str
(
digits
)
+
"d"
else
:
format_string
=
"%s"
for
i
in
range
(
start
,
end
):
s
=
format_string
%
i
result
.
append
((
s
,
s
))
return
result
def
render_dict
(
self
,
field
,
value
,
render_prefix
=
None
):
"""
This is yet another field rendering. It is designed to allow code to
...
...
@@ -1426,13 +1437,13 @@ class DateTimeWidget(Widget):
if
(
value
in
(
None
,
''
))
and
(
field
.
get_value
(
'default_now'
))
and
\
((
REQUEST
is
None
)
or
(
not
REQUEST
.
form
.
has_key
(
'subfield_%s_%s'
%
(
key
,
'year'
)))):
value
=
DateTime
()
year
=
None
month
=
None
day
=
None
hour
=
None
minute
=
None
ampm
=
None
timezone
=
None
year
=
""
month
=
""
day
=
""
hour
=
""
minute
=
""
ampm
=
""
timezone
=
""
if
isinstance
(
value
,
DateTime
):
year
=
"%04d"
%
value
.
year
()
month
=
"%02d"
%
value
.
month
()
...
...
@@ -1498,27 +1509,47 @@ class DateTimeWidget(Widget):
return
date_result
def
render_sub_field
(
self
,
field
,
key
,
name
,
value
,
size
,
maxlength
,
REQUEST
):
if
value
is
None
:
value
=
""
if
name
in
(
'year'
,
'month'
,
'day'
,
'hour'
,
'minute'
,
'ampm'
):
return
render_element
(
"input"
,
type
=
"text"
,
name
=
field
.
generate_subfield_key
(
name
,
key
=
key
),
value
=
value
,
size
=
size
,
maxlength
=
maxlength
)
else
:
gmt_timezones
=
[(
'GMT%s'
%
zone
,
'GMT%s'
%
zone
,)
for
zone
in
range
(
-
12
,
0
)]
\
+
[(
'GMT'
,
'GMT'
,),]
\
+
[(
'GMT+%s'
%
zone
,
'GMT+%s'
%
zone
,)
for
zone
in
range
(
1
,
13
)]
rendered_items
=
self
.
render_sub_list
(
field
,
value
,
gmt_timezones
,
REQUEST
)
if
name
in
(
'hour'
,
'minute'
):
return
render_element
(
"input"
,
type
=
"text"
,
name
=
field
.
generate_subfield_key
(
name
,
key
=
key
),
value
=
value
,
size
=
size
,
maxlength
=
maxlength
)
if
name
in
(
'year'
,
'month'
,
'day'
,
'ampm'
):
style
=
field
.
get_value
(
'input_style'
)
if
style
==
'text'
:
return
render_element
(
"input"
,
type
=
"text"
,
name
=
field
.
generate_subfield_key
(
name
,
key
=
key
),
value
=
value
,
size
=
size
,
maxlength
=
maxlength
)
if
name
==
'year'
:
items
=
self
.
create_items
(
int
(
value
)
-
5
,
int
(
value
)
+
5
,
digits
=
4
)
elif
name
==
'month'
:
items
=
self
.
create_items
(
1
,
13
,
digits
=
2
)
elif
name
==
'day'
:
items
=
self
.
create_items
(
1
,
32
,
digits
=
2
)
else
:
items
=
[(
"am"
,
"am"
),
(
"pm"
,
"pm"
)]
rendered_items
=
self
.
render_sub_list
(
field
,
value
,
items
,
REQUEST
)
return
render_element
(
'select'
,
name
=
field
.
generate_subfield_key
(
name
,
key
=
key
),
css_class
=
field
.
get_value
(
'css_class'
,
REQUEST
=
REQUEST
),
size
=
1
,
contents
=
string
.
join
(
rendered_items
,
"
\
n
"
))
gmt_timezones
=
[(
'GMT%s'
%
zone
,
'GMT%s'
%
zone
,)
for
zone
in
range
(
-
12
,
0
)]
\
+
[(
'GMT'
,
'GMT'
,),]
\
+
[(
'GMT+%s'
%
zone
,
'GMT+%s'
%
zone
,)
for
zone
in
range
(
1
,
13
)]
value
=
value
.
replace
(
"UTC"
,
"GMT"
)
rendered_items
=
self
.
render_sub_list
(
field
,
value
,
gmt_timezones
,
REQUEST
)
return
render_element
(
'select'
,
name
=
field
.
generate_subfield_key
(
name
,
key
=
key
),
css_class
=
field
.
get_value
(
'css_class'
,
REQUEST
=
REQUEST
),
size
=
1
,
contents
=
string
.
join
(
rendered_items
,
"
\
n
"
))
def
render_sub_list
(
self
,
field
,
value
,
items
,
REQUEST
):
selected_found
=
0
rendered_items
=
[]
value
=
value
.
replace
(
"UTC"
,
"GMT"
)
for
item
in
items
:
try
:
item_text
,
item_value
=
item
...
...
@@ -1532,7 +1563,6 @@ class DateTimeWidget(Widget):
rendered_item
=
render_element
(
'option'
,
contents
=
item_text
,
value
=
item_value
)
rendered_items
.
append
(
rendered_item
)
return
rendered_items
def
format_value
(
self
,
field
,
value
,
mode
=
'html'
):
...
...
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