Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Kirill Smelkov
Zope
Commits
766d3a96
Commit
766d3a96
authored
Nov 30, 2002
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added converter for international date formats
parent
b08647d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
lib/python/ZPublisher/Converters.py
lib/python/ZPublisher/Converters.py
+16
-6
No files found.
lib/python/ZPublisher/Converters.py
View file @
766d3a96
...
...
@@ -10,10 +10,11 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__version__
=
'$Revision: 1.2
0
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.2
1
$'
[
11
:
-
2
]
import
re
from
types
import
ListType
,
TupleType
,
UnicodeType
from
DateTime
import
DateTime
from
cgi
import
escape
def
field2string
(
v
):
...
...
@@ -47,7 +48,7 @@ def field2required(v):
raise
ValueError
,
'No input for required field<p>'
def
field2int
(
v
):
if
type
(
v
)
in
(
ListType
,
TupleType
):
if
isinstance
(
v
,
(
ListType
,
TupleType
)
):
return
map
(
field2int
,
v
)
v
=
field2string
(
v
)
if
v
:
...
...
@@ -59,7 +60,7 @@ def field2int(v):
raise
ValueError
,
'Empty entry when <strong>integer</strong> expected'
def
field2float
(
v
):
if
type
(
v
)
in
(
ListType
,
TupleType
):
if
isinstance
(
v
,
(
ListType
,
TupleType
)
):
return
map
(
field2float
,
v
)
v
=
field2string
(
v
)
if
v
:
...
...
@@ -73,7 +74,7 @@ def field2float(v):
'Empty entry when <strong>floating-point number</strong> expected'
)
def
field2long
(
v
):
if
type
(
v
)
in
(
ListType
,
TupleType
):
if
isinstance
(
v
,
(
ListType
,
TupleType
)
):
return
map
(
field2long
,
v
)
v
=
field2string
(
v
)
# handle trailing 'L' if present.
...
...
@@ -92,7 +93,7 @@ def field2tokens(v):
return
v
.
split
()
def
field2lines
(
v
):
if
type
(
v
)
in
(
ListType
,
TupleType
):
if
isinstance
(
v
,
(
ListType
,
TupleType
)
):
result
=
[]
for
item
in
v
:
result
.
append
(
str
(
item
))
...
...
@@ -100,7 +101,7 @@ def field2lines(v):
return
field2text
(
v
).
split
(
'
\
n
'
)
def
field2date
(
v
):
from
DateTime
import
DateTime
v
=
field2string
(
v
)
try
:
v
=
DateTime
(
v
)
...
...
@@ -108,6 +109,14 @@ def field2date(v):
raise
DateTime
.
SyntaxError
,
escape
(
e
)
return
v
def
field2date_international
(
v
):
v
=
field2string
(
v
)
try
:
v
=
DateTime
(
v
,
datefmt
=
"international"
)
except
DateTime
.
SyntaxError
,
e
:
raise
DateTime
.
SyntaxError
,
escape
(
e
)
return
v
def
field2boolean
(
v
):
return
not
not
v
...
...
@@ -152,6 +161,7 @@ type_converters = {
'long'
:
field2long
,
'string'
:
field2string
,
'date'
:
field2date
,
'date_international'
:
field2date_international
,
'required'
:
field2required
,
'tokens'
:
field2tokens
,
'lines'
:
field2lines
,
...
...
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