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
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
5c36a25d
Commit
5c36a25d
authored
Sep 25, 2017
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Type: move history access from component to a dedicated mixin
parent
63dc8c7b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
47 deletions
+85
-47
product/ERP5Type/Core/DocumentComponent.py
product/ERP5Type/Core/DocumentComponent.py
+2
-1
product/ERP5Type/Core/ExtensionComponent.py
product/ERP5Type/Core/ExtensionComponent.py
+2
-1
product/ERP5Type/Core/TestComponent.py
product/ERP5Type/Core/TestComponent.py
+2
-1
product/ERP5Type/mixin/component.py
product/ERP5Type/mixin/component.py
+0
-44
product/ERP5Type/mixin/text_content_history.py
product/ERP5Type/mixin/text_content_history.py
+79
-0
No files found.
product/ERP5Type/Core/DocumentComponent.py
View file @
5c36a25d
...
...
@@ -28,13 +28,14 @@
##############################################################################
from
Products.ERP5Type.mixin.component
import
ComponentMixin
from
Products.ERP5Type.mixin.text_content_history
import
TextContentHistoryMixin
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type
import
Permissions
import
zope.interface
from
Products.ERP5Type.interfaces.component
import
IComponent
class
DocumentComponent
(
ComponentMixin
):
class
DocumentComponent
(
ComponentMixin
,
TextContentHistoryMixin
):
"""
ZODB Component for Documents in bt5 only for now (which used to be installed
in INSTANCE_HOME/Document) but this will also be used later on for Documents
...
...
product/ERP5Type/Core/ExtensionComponent.py
View file @
5c36a25d
...
...
@@ -28,13 +28,14 @@
##############################################################################
from
Products.ERP5Type.mixin.component
import
ComponentMixin
from
Products.ERP5Type.mixin.text_content_history
import
TextContentHistoryMixin
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type
import
Permissions
import
zope.interface
from
Products.ERP5Type.interfaces.component
import
IComponent
class
ExtensionComponent
(
ComponentMixin
):
class
ExtensionComponent
(
ComponentMixin
,
TextContentHistoryMixin
):
"""
ZODB Component for Extensions previously defined in the bt5 and installed in
INSTANCE_HOME/Extensions
...
...
product/ERP5Type/Core/TestComponent.py
View file @
5c36a25d
...
...
@@ -28,13 +28,14 @@
##############################################################################
from
Products.ERP5Type.mixin.component
import
ComponentMixin
from
Products.ERP5Type.mixin.text_content_history
import
TextContentHistoryMixin
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type
import
Permissions
import
zope.interface
from
Products.ERP5Type.interfaces.component
import
IComponent
class
TestComponent
(
ComponentMixin
):
class
TestComponent
(
ComponentMixin
,
TextContentHistoryMixin
):
"""
ZODB Component for Live Tests only (previously defined in the bt5 and
installed in INSTANCE_HOME/tests) as other kind of Tests should be
...
...
product/ERP5Type/mixin/component.py
View file @
5c36a25d
...
...
@@ -385,48 +385,4 @@ class ComponentMixin(PropertyRecordableMixin, Base):
return
new_component
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'getTextContentHistoryRevisionDictList'
)
def
getTextContentHistoryRevisionDictList
(
self
,
limit
=
100
):
"""
TODO
"""
history_dict_list
=
self
.
_p_jar
.
db
().
history
(
self
.
_p_oid
,
size
=
limit
)
if
history_dict_list
is
None
:
# Storage doesn't support history
return
()
from
struct
import
unpack
from
OFS.History
import
historicalRevision
previous_text_content
=
None
result
=
[]
for
history_dict
in
history_dict_list
:
text_content
=
historicalRevision
(
self
,
history_dict
[
'tid'
]).
getTextContent
()
if
text_content
and
text_content
!=
previous_text_content
:
history_dict
[
'time'
]
=
history_dict
[
'time'
]
history_dict
[
'user_name'
]
=
history_dict
[
'user_name'
].
strip
()
history_dict
[
'key'
]
=
'.'
.
join
(
map
(
str
,
unpack
(
">HHHH"
,
history_dict
[
'tid'
])))
del
history_dict
[
'tid'
]
del
history_dict
[
'size'
]
result
.
append
(
history_dict
)
previous_text_content
=
text_content
return
result
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'getTextContentHistory'
)
def
getTextContentHistory
(
self
,
key
):
"""
TODO
"""
from
struct
import
pack
from
OFS.History
import
historicalRevision
serial
=
apply
(
pack
,
(
'>HHHH'
,)
+
tuple
(
map
(
int
,
key
.
split
(
'.'
))))
rev
=
historicalRevision
(
self
,
serial
)
return
rev
.
getTextContent
()
InitializeClass
(
ComponentMixin
)
product/ERP5Type/mixin/text_content_history.py
0 → 100644
View file @
5c36a25d
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2017 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type.Globals
import
InitializeClass
from
Products.ERP5Type
import
Permissions
class
TextContentHistoryMixin
:
security
=
ClassSecurityInfo
()
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'getTextContentHistoryRevisionDictList'
)
def
getTextContentHistoryRevisionDictList
(
self
,
limit
=
100
):
"""TODO
"""
history_dict_list
=
self
.
_p_jar
.
db
().
history
(
self
.
_p_oid
,
size
=
limit
)
if
history_dict_list
is
None
:
# Storage doesn't support history
return
()
from
struct
import
unpack
from
OFS.History
import
historicalRevision
previous_text_content
=
None
result
=
[]
for
history_dict
in
history_dict_list
:
text_content
=
historicalRevision
(
self
,
history_dict
[
'tid'
]).
getTextContent
()
if
text_content
and
text_content
!=
previous_text_content
:
history_dict
[
'time'
]
=
history_dict
[
'time'
]
history_dict
[
'user_name'
]
=
history_dict
[
'user_name'
].
strip
()
history_dict
[
'key'
]
=
'.'
.
join
(
map
(
str
,
unpack
(
">HHHH"
,
history_dict
[
'tid'
])))
del
history_dict
[
'tid'
]
del
history_dict
[
'size'
]
result
.
append
(
history_dict
)
previous_text_content
=
text_content
return
result
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'getTextContentHistory'
)
def
getTextContentHistory
(
self
,
key
):
"""TODO
"""
from
struct
import
pack
from
OFS.History
import
historicalRevision
serial
=
apply
(
pack
,
(
'>HHHH'
,)
+
tuple
(
map
(
int
,
key
.
split
(
'.'
))))
rev
=
historicalRevision
(
self
,
serial
)
return
rev
.
getTextContent
()
InitializeClass
(
TextContentHistoryMixin
)
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