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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
erp5
Commits
03deea25
Commit
03deea25
authored
Aug 28, 2019
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP! raise if value doesn't match setter
parent
6ff0893f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
3 deletions
+59
-3
product/CMFCategory/CategoryTool.py
product/CMFCategory/CategoryTool.py
+3
-0
product/ERP5Type/Accessor/Base.py
product/ERP5Type/Accessor/Base.py
+19
-0
product/ERP5Type/Accessor/Value.py
product/ERP5Type/Accessor/Value.py
+1
-0
product/ERP5Type/Base.py
product/ERP5Type/Base.py
+10
-3
product/ERP5Type/tests/testDynamicClassGeneration.py
product/ERP5Type/tests/testDynamicClassGeneration.py
+26
-0
No files found.
product/CMFCategory/CategoryTool.py
View file @
03deea25
...
...
@@ -638,6 +638,9 @@ class CategoryTool(BaseTool):
category_list
=
(
category_list
,
)
elif
category_list
is
None
:
category_list
=
()
elif
isinstance
(
category_list
,
list
):
if
any
([
not
isinstance
(
c
,
str
)
for
c
in
category_list
]):
raise
TypeError
(
'CategoryTool.setCategoryMembership only takes string(s) as value'
,
base_category_list
,
category_list
)
if
isinstance
(
base_category_list
,
str
):
base_category_list
=
(
base_category_list
,
)
...
...
product/ERP5Type/Accessor/Base.py
View file @
03deea25
...
...
@@ -26,12 +26,14 @@
#
##############################################################################
import
types
from
ZPublisher.HTTPRequest
import
FileUpload
from
TypeDefinition
import
type_definition
,
list_types
,
ATTRIBUTE_PREFIX
from
Accessor
import
Accessor
as
Method
from
Acquisition
import
aq_base
from
zLOG
import
LOG
from
DateTime
import
DateTime
from
Products.ERP5Type.Cache
import
CachingMethod
from
Products.ERP5Type.PsycoWrapper
import
psyco
...
...
@@ -41,6 +43,21 @@ from AccessControl.PermissionRole import PermissionRole
# Creation of default constructor
class
func_code
:
pass
builtin_type_tuple
=
(
types
.
NoneType
,
types
.
BooleanType
,
types
.
IntType
,
types
.
LongType
,
types
.
FloatType
,
types
.
ComplexType
,
types
.
StringType
,
types
.
UnicodeType
,
types
.
TupleType
,
types
.
ListType
,
types
.
DictType
,
DateTime
,
)
class
Setter
(
Method
):
"""
Sets an attribute value. ATTRIBUTE_PREFIX and storage_id allow
...
...
@@ -72,6 +89,8 @@ class Setter(Method):
# Modify the property
if
value
in
self
.
_null
:
setattr
(
instance
,
self
.
_storage_id
,
None
)
elif
not
isinstance
(
value
,
builtin_type_tuple
):
raise
TypeError
(
'Class Objects can
\
'
t be used as property values'
)
elif
self
.
_property_type
==
'content'
:
# A file object should be provided
file_upload
=
value
...
...
product/ERP5Type/Accessor/Value.py
View file @
03deea25
...
...
@@ -31,6 +31,7 @@ from Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Sette
from
zLOG
import
LOG
from
Products.ERP5Type.PsycoWrapper
import
psyco
from
Products.ERP5Type.Utils
import
convertToUpperCase
from
Products.ERP5Type.Base
import
Base
class
SetSetter
(
BaseSetter
):
"""
...
...
product/ERP5Type/Base.py
View file @
03deea25
...
...
@@ -1288,9 +1288,16 @@ class Base( CopyContainer,
**kw allows to call setProperty as a generic setter (ex. setProperty(value_uid, portal_type=))
"""
LOG
(
"NICOLAS-Base_setProperty"
,
0
,
key
,
value
)
if
type
is
not
None
:
# Speed
if
type
in
list_types
:
# Patch for OFS PropertyManager
key
+=
'_list'
if
not
(
key
.
endswith
(
'_value'
)
or
key
.
endswith
(
'_value_list'
)):
if
isinstance
(
value
,
(
list
,
tuple
)):
if
any
([
isinstance
(
x
,
Base
)
for
x
in
value
]):
raise
TypeError
(
'_setProperty only accepts byte values'
)
elif
isinstance
(
value
,
Base
):
raise
TypeError
(
'_setProperty only accepts byte values'
)
accessor_name
=
'_set'
+
UpperCase
(
key
)
aq_self
=
aq_base
(
self
)
# We must use aq_self
...
...
@@ -1838,14 +1845,14 @@ class Base( CopyContainer,
if
target
is
None
:
path
=
target
elif
isinstance
(
target
,
str
):
#
We have been provided a string
path
=
target
#
is Base in obj.__class__.__mro__ ?
raise
TypeError
(
'Only objects should be passed as values'
)
elif
isinstance
(
target
,
(
tuple
,
list
,
set
,
frozenset
)):
# We have been provided a list or tuple
path_list
=
[]
for
target_item
in
target
:
if
isinstance
(
target_item
,
str
):
path
=
target_item
raise
TypeError
(
'Only objects should be passed as values'
)
else
:
path
=
getRelativeUrl
(
target_item
)
path_list
.
append
(
cleanupCategory
(
path
))
...
...
product/ERP5Type/tests/testDynamicClassGeneration.py
View file @
03deea25
...
...
@@ -378,6 +378,32 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
"""
XXX: WORK IN PROGRESS
"""
def
testNicolas
(
self
):
from
zLOG
import
LOG
person
=
self
.
portal
.
person_module
.
newContent
()
person
.
setTitle
(
'NW'
)
with
self
.
assertRaises
(
TypeError
):
organisation
=
self
.
portal
.
organisation_module
.
newContent
()
person
.
setFirstName
(
organisation
)
with
self
.
assertRaises
(
TypeError
):
organisation
=
self
.
portal
.
organisation_module
.
newContent
()
person
.
setSubordinationValue
(
organisation
.
getRelativeUrl
())
with
self
.
assertRaises
(
TypeError
):
organisation
=
self
.
portal
.
organisation_module
.
newContent
()
person
.
setSubordination
(
organisation
)
social_title
=
self
.
portal
.
portal_categories
.
social_title
.
newContent
(
id
=
'Mr'
)
with
self
.
assertRaises
(
TypeError
):
person
.
setSocialTitle
(
social_title
)
with
self
.
assertRaises
(
TypeError
):
person
.
setSocialTitleValue
(
social_title
.
getRelativeUrl
())
def
getBusinessTemplateList
(
self
):
return
'erp5_base'
,
...
...
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