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
Show 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
from
zLOG
import
LOG
,
WARNING
from
Acquisition
import
aq_base
def
IdAsReferenceMixin
(
suffix
):
suffix_index
=
-
len
(
suffix
)
def
IdAsReferenceMixin
(
extra_string
,
string_type
=
"suffix"
):
extra_string_index
=
-
len
(
extra_string
)
class
IdAsReferenceMixin
(
object
):
# Declarative security
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
Permissions
.
AccessContentsInformation
)
def
cb_isMoveable
(
self
):
return
self
.
cb_userHasCopyOrMovePermission
()
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getIdAsReferenceSuffix'
)
@
staticmethod
def
getIdAsReferenceSuffix
():
return
suffix
return
extra_string
def
__migrate
(
self
):
if
self
.
id
[
suffix_index
:]
!=
suffix
:
new_id
=
self
.
__dict__
.
get
(
'default_reference'
)
+
suffix
if
self
.
id
[
extra_string_index
:]
!=
extra_string
:
new_id
=
self
.
__dict__
.
get
(
'default_reference'
)
+
extra_string
parent
=
self
.
getParentValue
()
if
parent
.
has_key
(
new_id
):
LOG
(
"IdAsReferenceMixin"
,
WARNING
,
"Skipping migration of %r in %r"
...
...
@@ -70,8 +69,16 @@ def IdAsReferenceMixin(suffix):
'getReference'
)
def
getReference
(
self
,
*
args
):
id
=
self
.
id
if
id
[
suffix_index
:]
==
suffix
:
return
id
[:
suffix_index
]
if
string_type
==
"suffix"
:
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
])
elif
string_type
==
"prefix"
:
if
id
[:
extra_string_index
]
==
extra_string
:
return
id
[
extra_string_index
:]
try
:
return
self
.
_baseGetReference
(
*
args
)
except
AttributeError
:
...
...
@@ -79,7 +86,10 @@ def IdAsReferenceMixin(suffix):
def
_setReference
(
self
,
value
):
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'
)
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