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
Amer
erp5
Commits
f4fcbec4
Commit
f4fcbec4
authored
Apr 30, 2015
by
wenjie.zheng
Committed by
Sebastien Robin
Jul 16, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
id_as_reference.py: now allow to select between adding prefix or suffix.
parent
0f3124f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
14 deletions
+24
-14
product/ERP5Type/id_as_reference.py
product/ERP5Type/id_as_reference.py
+24
-14
No files found.
product/ERP5Type/id_as_reference.py
View file @
f4fcbec4
...
@@ -33,26 +33,25 @@ from Products.CMFActivity.Errors import ActivityPendingError
...
@@ -33,26 +33,25 @@ from Products.CMFActivity.Errors import ActivityPendingError
from
zLOG
import
LOG
,
WARNING
from
zLOG
import
LOG
,
WARNING
from
Acquisition
import
aq_base
from
Acquisition
import
aq_base
def
IdAsReferenceMixin
(
suffix
):
def
IdAsReferenceMixin
(
extra_string
,
string_type
=
"suffix"
):
suffix_index
=
-
len
(
suffix
)
extra_string_index
=
-
len
(
extra_string
)
class
IdAsReferenceMixin
(
object
):
class
IdAsReferenceMixin
(
object
):
# Declarative security
# Declarative security
security
=
ClassSecurityInfo
()
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
Permissions
.
AccessContentsInformation
)
security
.
declareObjectProtected
(
Permissions
.
AccessContentsInformation
)
def
cb_isMoveable
(
self
):
def
cb_isMoveable
(
self
):
return
self
.
cb_userHasCopyOrMovePermission
()
return
self
.
cb_userHasCopyOrMovePermission
()
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getIdAsReferenceSuffix'
)
'getIdAsReferenceSuffix'
)
@
staticmethod
@
staticmethod
def
getIdAsReferenceSuffix
():
def
getIdAsReferenceSuffix
():
return
suffix
return
extra_string
def
__migrate
(
self
):
def
__migrate
(
self
):
if
self
.
id
[
suffix_index
:]
!=
suffix
:
if
self
.
id
[
extra_string_index
:]
!=
extra_string
:
new_id
=
self
.
__dict__
.
get
(
'default_reference'
)
+
suffix
new_id
=
self
.
__dict__
.
get
(
'default_reference'
)
+
extra_string
parent
=
self
.
getParentValue
()
parent
=
self
.
getParentValue
()
if
parent
.
has_key
(
new_id
):
if
parent
.
has_key
(
new_id
):
LOG
(
"IdAsReferenceMixin"
,
WARNING
,
"Skipping migration of %r in %r"
LOG
(
"IdAsReferenceMixin"
,
WARNING
,
"Skipping migration of %r in %r"
...
@@ -70,16 +69,27 @@ def IdAsReferenceMixin(suffix):
...
@@ -70,16 +69,27 @@ def IdAsReferenceMixin(suffix):
'getReference'
)
'getReference'
)
def
getReference
(
self
,
*
args
):
def
getReference
(
self
,
*
args
):
id
=
self
.
id
id
=
self
.
id
if
id
[
suffix_index
:]
==
suffix
:
if
string_type
==
"suffix"
:
return
id
[:
suffix_index
]
if
id
[
extra_string_index
:]
==
extra_string
:
try
:
return
id
[:
extra_string_index
]
return
self
.
_baseGetReference
(
*
args
)
try
:
except
AttributeError
:
return
self
.
_baseGetReference
(
*
args
)
return
getattr
(
aq_base
(
self
),
'default_reference'
,
(
args
or
[
None
])[
0
])
except
AttributeError
:
return
getattr
(
aq_base
(
self
),
'default_reference'
,
(
args
or
[
None
])[
0
])
elif
string_type
==
"prefix"
:
if
id
[:
extra_string_index
]
==
extra_string
:
return
id
[
extra_string_index
:]
try
:
return
self
.
_baseGetReference
(
*
args
)
except
AttributeError
:
return
getattr
(
aq_base
(
self
),
'default_reference'
,
(
args
or
[
None
])[
0
])
def
_setReference
(
self
,
value
):
def
_setReference
(
self
,
value
):
self
.
__dict__
.
pop
(
'default_reference'
,
None
)
self
.
__dict__
.
pop
(
'default_reference'
,
None
)
self
.
setId
(
value
+
suffix
)
if
string_type
==
"prefix"
:
self
.
setId
(
extra_string
+
value
)
elif
string_type
==
"suffix"
:
self
.
setId
(
value
+
extra_string
)
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'setReference'
)
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'setReference'
)
setReference
=
_setReference
setReference
=
_setReference
...
...
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