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
amrani
erp5
Commits
8a9ce166
Commit
8a9ce166
authored
Mar 04, 2015
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formulator DateTimeField: Do not use sub form to generate date and time
parent
6faa1b16
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
45 deletions
+62
-45
product/Formulator/StandardFields.py
product/Formulator/StandardFields.py
+2
-4
product/Formulator/Validator.py
product/Formulator/Validator.py
+20
-12
product/Formulator/Widget.py
product/Formulator/Widget.py
+40
-29
No files found.
product/Formulator/StandardFields.py
View file @
8a9ce166
...
@@ -127,6 +127,7 @@ class DateTimeField(ZMIField):
...
@@ -127,6 +127,7 @@ class DateTimeField(ZMIField):
widget
=
Widget
.
DateTimeWidgetInstance
widget
=
Widget
.
DateTimeWidgetInstance
validator
=
Validator
.
DateTimeValidatorInstance
validator
=
Validator
.
DateTimeValidatorInstance
"""
def __init__(self, id, **kw):
def __init__(self, id, **kw):
# icky but necessary...
# icky but necessary...
apply(ZMIField.__init__, (self, id), kw)
apply(ZMIField.__init__, (self, id), kw)
...
@@ -160,10 +161,7 @@ class DateTimeField(ZMIField):
...
@@ -160,10 +161,7 @@ class DateTimeField(ZMIField):
for field in self.sub_form.get_fields():
for field in self.sub_form.get_fields():
field.values['css_class'] = value
field.values['css_class'] = value
field._p_changed = 1
field._p_changed = 1
def override_year_items(self):
def override_year_items(self):
"""The method gets called to get the right amount of years.
"""
start_datetime = self.get_value('start_datetime')
start_datetime = self.get_value('start_datetime')
end_datetime = self.get_value('end_datetime')
end_datetime = self.get_value('end_datetime')
current_year = DateTime().year()
current_year = DateTime().year()
...
@@ -176,7 +174,7 @@ class DateTimeField(ZMIField):
...
@@ -176,7 +174,7 @@ class DateTimeField(ZMIField):
else:
else:
last_year = first_year + 11
last_year = first_year + 11
return create_items(first_year, last_year, digits=4)
return create_items(first_year, last_year, digits=4)
"""
def
_get_user_input_value
(
self
,
key
,
REQUEST
):
def
_get_user_input_value
(
self
,
key
,
REQUEST
):
"""
"""
Try to get a value of the field from the REQUEST
Try to get a value of the field from the REQUEST
...
...
product/Formulator/Validator.py
View file @
8a9ce166
...
@@ -278,8 +278,11 @@ class IntegerValidator(StringBaseValidator):
...
@@ -278,8 +278,11 @@ class IntegerValidator(StringBaseValidator):
value
=
int
(
value
)
value
=
int
(
value
)
except
ValueError
:
except
ValueError
:
self
.
raise_error
(
'not_integer'
,
field
)
self
.
raise_error
(
'not_integer'
,
field
)
start
=
""
end
=
""
if
hasattr
(
field
,
start
):
start
=
field
.
get_value
(
'start'
)
start
=
field
.
get_value
(
'start'
)
if
hasattr
(
field
,
end
):
end
=
field
.
get_value
(
'end'
)
end
=
field
.
get_value
(
'end'
)
if
start
!=
""
and
value
<
start
:
if
start
!=
""
and
value
<
start
:
self
.
raise_error
(
'integer_out_of_range'
,
field
)
self
.
raise_error
(
'integer_out_of_range'
,
field
)
...
@@ -734,29 +737,33 @@ class DateTimeValidator(Validator):
...
@@ -734,29 +737,33 @@ class DateTimeValidator(Validator):
not_datetime
=
'You did not enter a valid date and time.'
not_datetime
=
'You did not enter a valid date and time.'
datetime_out_of_range
=
'The date and time you entered were out of range.'
datetime_out_of_range
=
'The date and time you entered were out of range.'
def
validate_sub_field
(
self
,
field
,
key
,
name
,
REQUEST
):
id
=
field
.
generate_subfield_key
(
name
,
validation
=
1
,
key
=
key
)
return
IntegerValidatorInstance
.
validate
(
field
,
id
,
REQUEST
)
def
validate
(
self
,
field
,
key
,
REQUEST
):
def
validate
(
self
,
field
,
key
,
REQUEST
):
try
:
try
:
year
=
field
.
validate_sub_field
(
'year'
,
REQUEST
,
key
=
key
)
year
=
self
.
validate_sub_field
(
field
,
key
,
'year'
,
REQUEST
)
month
=
field
.
validate_sub_field
(
'month'
,
REQUEST
,
key
=
key
)
month
=
self
.
validate_sub_field
(
field
,
key
,
'month'
,
REQUEST
)
if
field
.
get_value
(
'hide_day'
):
if
field
.
get_value
(
'hide_day'
):
day
=
1
day
=
1
else
:
else
:
day
=
field
.
validate_sub_field
(
'day'
,
REQUEST
,
key
=
key
)
day
=
self
.
validate_sub_field
(
field
,
key
,
'day'
,
REQUEST
)
if
field
.
get_value
(
'date_only'
):
if
field
.
get_value
(
'date_only'
):
hour
=
0
hour
=
0
minute
=
0
minute
=
0
elif
field
.
get_value
(
'allow_empty_time'
):
elif
field
.
get_value
(
'allow_empty_time'
):
hour
=
field
.
validate_sub_field
(
'hour'
,
REQUEST
,
key
=
key
)
hour
=
self
.
validate_sub_field
(
field
,
key
,
'hour'
,
REQUEST
)
minute
=
field
.
validate_sub_field
(
'minute'
,
REQUEST
,
key
=
key
)
minute
=
self
.
validate_sub_field
(
field
,
key
,
'minute'
,
REQUEST
)
if
hour
==
''
and
minute
==
''
:
if
hour
==
''
and
minute
==
''
:
hour
=
0
hour
=
0
minute
=
0
minute
=
0
elif
hour
==
''
or
minute
==
''
:
elif
hour
==
''
or
minute
==
''
:
raise
ValidationError
(
'not_datetime'
,
field
)
raise
ValidationError
(
'not_datetime'
,
field
)
else
:
else
:
hour
=
field
.
validate_sub_field
(
'hour'
,
REQUEST
,
key
=
key
)
hour
=
self
.
validate_sub_field
(
field
,
key
,
'hour'
,
REQUEST
)
minute
=
field
.
validate_sub_field
(
'minute'
,
REQUEST
,
key
=
key
)
minute
=
self
.
validate_sub_field
(
field
,
key
,
'minute'
,
REQUEST
)
except
ValidationError
:
except
ValidationError
:
self
.
raise_error
(
'not_datetime'
,
field
)
self
.
raise_error
(
'not_datetime'
,
field
)
...
@@ -778,7 +785,7 @@ class DateTimeValidator(Validator):
...
@@ -778,7 +785,7 @@ class DateTimeValidator(Validator):
self
.
raise_error
(
'not_datetime'
,
field
)
self
.
raise_error
(
'not_datetime'
,
field
)
if
field
.
get_value
(
'ampm_time_style'
):
if
field
.
get_value
(
'ampm_time_style'
):
ampm
=
field
.
validate_sub_field
(
'ampm'
,
REQUEST
,
key
=
key
)
ampm
=
self
.
validate_sub_field
(
field
,
key
,
'ampm'
,
REQUEST
)
if
field
.
get_value
(
'allow_empty_time'
):
if
field
.
get_value
(
'allow_empty_time'
):
if
ampm
==
''
:
if
ampm
==
''
:
ampm
=
'am'
ampm
=
'am'
...
@@ -794,9 +801,10 @@ class DateTimeValidator(Validator):
...
@@ -794,9 +801,10 @@ class DateTimeValidator(Validator):
# handle possible timezone input
# handle possible timezone input
timezone
=
''
timezone
=
''
"""
if field.get_value('timezone_style'):
if field.get_value('timezone_style'):
timezone = field.validate_sub_field('timezone', REQUEST, key=key)
timezone = field.validate_sub_field('timezone', REQUEST, key=key)
"""
try
:
try
:
# handling of hidden day, which can be first or last day of the month:
# handling of hidden day, which can be first or last day of the month:
if
field
.
get_value
(
'hidden_day_is_last_day'
):
if
field
.
get_value
(
'hidden_day_is_last_day'
):
...
...
product/Formulator/Widget.py
View file @
8a9ce166
...
@@ -1417,10 +1417,6 @@ class DateTimeWidget(Widget):
...
@@ -1417,10 +1417,6 @@ class DateTimeWidget(Widget):
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'
)
# FIXME: backwards compatibility hack:
if
not
hasattr
(
field
,
'sub_form'
):
from
StandardFields
import
create_datetime_text_sub_form
field
.
sub_form
=
create_datetime_text_sub_form
()
# Is it still usefull to test the None value,
# Is it still usefull to test the None value,
# as DateTimeField should be considerer as the other field
# as DateTimeField should be considerer as the other field
...
@@ -1428,8 +1424,7 @@ class DateTimeWidget(Widget):
...
@@ -1428,8 +1424,7 @@ class DateTimeWidget(Widget):
# XXX hasattr(REQUEST, 'form') seems useless,
# XXX hasattr(REQUEST, 'form') seems useless,
# because REQUEST always has a form property
# because REQUEST always has a form property
if
(
value
in
(
None
,
''
))
and
(
field
.
get_value
(
'default_now'
))
and
\
if
(
value
in
(
None
,
''
))
and
(
field
.
get_value
(
'default_now'
))
and
\
((
REQUEST
is
None
)
or
(
not
hasattr
(
REQUEST
,
'form'
))
or
\
((
REQUEST
is
None
)
or
(
not
REQUEST
.
form
.
has_key
(
'subfield_%s_%s'
%
(
key
,
'year'
)))):
(
not
REQUEST
.
form
.
has_key
(
'subfield_%s_%s'
%
(
key
,
'year'
)))):
value
=
DateTime
()
value
=
DateTime
()
year
=
None
year
=
None
month
=
None
month
=
None
...
@@ -1449,48 +1444,64 @@ class DateTimeWidget(Widget):
...
@@ -1449,48 +1444,64 @@ class DateTimeWidget(Widget):
minute
=
"%02d"
%
value
.
minute
()
minute
=
"%02d"
%
value
.
minute
()
ampm
=
value
.
ampm
()
ampm
=
value
.
ampm
()
timezone
=
value
.
timezone
()
timezone
=
value
.
timezone
()
elif
REQUEST
is
not
None
:
year
=
REQUEST
.
get
(
field
.
generate_subfield_key
(
"year"
,
key
=
key
))
month
=
REQUEST
.
get
(
field
.
generate_subfield_key
(
"month"
,
key
=
key
))
day
=
REQUEST
.
get
(
field
.
generate_subfield_key
(
"day"
,
key
=
key
))
hour
=
REQUEST
.
get
(
field
.
generate_subfield_key
(
"hour"
,
key
=
key
))
minute
=
REQUEST
.
get
(
field
.
generate_subfield_key
(
"minute"
,
key
=
key
))
ampm
=
REQUEST
.
get
(
field
.
generate_subfield_key
(
"ampm"
,
key
=
key
))
timezone
=
REQUEST
.
get
(
field
.
generate_subfield_key
(
"timezone"
,
key
=
key
))
input_order
=
self
.
getInputOrder
(
field
)
input_order
=
self
.
getInputOrder
(
field
)
if
input_order
==
'ymd'
:
if
input_order
==
'ymd'
:
order
=
[
(
'year'
,
year
)
,
order
=
[
[
'year'
,
year
,
4
,
4
]
,
(
'month'
,
month
)
,
[
'month'
,
month
,
2
,
2
]
,
(
'day'
,
day
)
]
[
'day'
,
day
,
2
,
2
]
]
elif
input_order
==
'dmy'
:
elif
input_order
==
'dmy'
:
order
=
[
(
'day'
,
day
)
,
order
=
[
[
'day'
,
day
,
2
,
2
]
,
(
'month'
,
month
)
,
[
'month'
,
month
,
2
,
2
]
,
(
'year'
,
year
)
]
[
'year'
,
year
,
4
,
4
]
]
elif
input_order
==
'mdy'
:
elif
input_order
==
'mdy'
:
order
=
[
(
'month'
,
month
)
,
order
=
[
[
'month'
,
month
,
2
,
2
]
,
(
'day'
,
day
)
,
[
'day'
,
day
,
2
,
2
]
,
(
'year'
,
year
)
]
[
'year'
,
year
,
4
,
4
]
]
elif
input_order
==
'my'
:
elif
input_order
==
'my'
:
order
=
[
(
'month'
,
month
)
,
order
=
[
[
'month'
,
month
,
2
,
2
]
,
(
'year'
,
year
)
]
[
'year'
,
year
,
4
,
4
]
]
elif
input_order
==
'ym'
:
elif
input_order
==
'ym'
:
order
=
[
(
'year'
,
year
)
,
order
=
[
[
'year'
,
year
,
4
,
4
]
,
(
'month'
,
month
)
]
[
'month'
,
month
,
2
,
2
]
]
else
:
else
:
order
=
[
(
'year'
,
year
)
,
order
=
[
[
'year'
,
year
,
4
,
4
]
,
(
'month'
,
month
)
,
[
'month'
,
month
,
2
,
2
]
,
(
'day'
,
day
)
]
[
'day'
,
day
,
2
,
2
]
]
result
=
[]
result
=
[]
for
sub_field_name
,
sub_field_value
in
order
:
for
sub_field_name
,
sub_field_value
,
size
,
maxlength
in
order
:
result
.
append
(
field
.
render_sub_field
(
sub_field_name
,
result
.
append
(
self
.
render_sub_field
(
field
,
key
,
sub_field_name
,
sub_field_value
,
REQUEST
,
key
=
key
))
sub_field_value
,
size
,
maxlength
,
REQUEST
))
date_result
=
string
.
join
(
result
,
field
.
get_value
(
'date_separator'
))
date_result
=
string
.
join
(
result
,
field
.
get_value
(
'date_separator'
))
if
not
field
.
get_value
(
'date_only'
):
if
not
field
.
get_value
(
'date_only'
):
time_result
=
(
field
.
render_sub_field
(
'hour'
,
hour
,
REQUEST
,
key
=
key
)
+
time_result
=
(
self
.
render_sub_field
(
field
,
key
,
'hour'
,
hour
,
2
,
2
,
REQUEST
)
+
field
.
get_value
(
'time_separator'
)
+
field
.
get_value
(
'time_separator'
)
+
field
.
render_sub_field
(
'minute'
,
minute
,
REQUEST
,
key
=
key
))
self
.
render_sub_field
(
field
,
key
,
'minute'
,
minute
,
2
,
2
,
REQUEST
))
if
use_ampm
:
if
use_ampm
:
time_result
+=
' '
+
field
.
render_sub_field
(
'ampm'
,
time_result
+=
' '
+
self
.
render_sub_field
(
field
,
key
,
'ampm'
,
ampm
,
REQUEST
,
key
=
key
)
ampm
,
2
,
2
,
REQUEST
)
"""
if use_timezone:
if use_timezone:
time_result += ' ' + field.render_sub_field('timezone',
time_result += ' ' + field.render_sub_field('timezone',
timezone, REQUEST, key=key)
timezone, REQUEST, key=key)
"""
return
date_result
+
' '
+
time_result
return
date_result
+
' '
+
time_result
else
:
else
:
return
date_result
return
date_result
def
render_sub_field
(
self
,
field
,
key
,
name
,
value
,
size
,
maxlength
,
REQUEST
):
if
value
is
None
:
value
=
""
return
render_element
(
"input"
,
type
=
"text"
,
name
=
field
.
generate_subfield_key
(
name
,
key
=
key
),
value
=
value
,
size
=
size
,
maxlength
=
maxlength
)
def
format_value
(
self
,
field
,
value
,
mode
=
'html'
):
def
format_value
(
self
,
field
,
value
,
mode
=
'html'
):
# Is it still usefull to test the None value,
# Is it still usefull to test the None value,
...
...
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