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
42861d94
Commit
42861d94
authored
May 23, 2016
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5: factorize WebSectionTraversalHook and WebSiteTraversalHook
parent
21f7f035
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
56 deletions
+27
-56
product/ERP5/Document/WebSection.py
product/ERP5/Document/WebSection.py
+15
-6
product/ERP5/Document/WebSite.py
product/ERP5/Document/WebSite.py
+12
-50
No files found.
product/ERP5/Document/WebSection.py
View file @
42861d94
...
...
@@ -46,6 +46,8 @@ WEBSECTION_KEY = 'web_section_value'
MARKER
=
[]
class
WebSectionTraversalHook
(
Persistent
):
"""Traversal hook to change the skin selection for this websection.
"""
def
__call__
(
self
,
container
,
request
):
if
not
request
.
get
(
'ignore_layout'
,
None
):
# If a skin selection is defined in this web section, change the skin now.
...
...
@@ -139,16 +141,16 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
security
.
declarePrivate
(
'manage_beforeDelete'
)
def
manage_beforeDelete
(
self
,
item
,
container
):
if
item
is
self
and
self
.
getPortalType
()
==
'Web Section'
:
if
item
is
self
:
handle
=
self
.
meta_type
+
'/'
+
self
.
getId
()
BeforeTraverse
.
unregisterBeforeTraverse
(
item
,
handle
)
super
(
WebSection
,
self
).
manage_beforeDelete
(
item
,
container
)
security
.
declarePrivate
(
'manage_afterAdd'
)
def
manage_afterAdd
(
self
,
item
,
container
):
if
item
is
self
and
self
.
getPortalType
()
==
'Web Section'
:
if
item
is
self
:
handle
=
self
.
meta_type
+
'/'
+
self
.
getId
()
BeforeTraverse
.
registerBeforeTraverse
(
item
,
WebSectionTraversalHook
(),
handle
)
BeforeTraverse
.
registerBeforeTraverse
(
item
,
self
.
_getTraversalHookClass
()
(),
handle
)
super
(
WebSection
,
self
).
manage_afterAdd
(
item
,
container
)
security
.
declarePrivate
(
'manage_afterClone'
)
...
...
@@ -156,12 +158,17 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
self
.
_cleanupBeforeTraverseHooks
()
super
(
WebSection
,
self
).
manage_afterClone
(
item
)
def
_getTraversalHookClass
(
self
):
return
WebSectionTraversalHook
_traversal_hook_class
=
WebSectionTraversalHook
def
_cleanupBeforeTraverseHooks
(
self
):
# unregister all before traversal hooks that do not belong to us.
my_handle
=
self
.
meta_type
+
'/'
+
self
.
getId
()
handle_to_unregister_list
=
[]
for
(
priority
,
handle
),
hook
in
self
.
__before_traverse__
.
items
():
if
isinstance
(
hook
,
WebSectionTraversalHook
)
and
handle
!=
my_handle
:
if
isinstance
(
hook
,
self
.
_getTraversalHookClass
()
)
and
handle
!=
my_handle
:
handle_to_unregister_list
.
append
(
handle
)
for
handle
in
handle_to_unregister_list
:
BeforeTraverse
.
unregisterBeforeTraverse
(
self
,
handle
)
...
...
@@ -442,11 +449,13 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
return
result
def
_edit
(
self
,
**
kw
):
if
self
.
getPortalType
()
==
'Web Section'
:
# XXX it is unclear if we should keep this behavior in other potential subclasses.
# Probably yes.
if
self
.
getPortalType
()
in
(
'Web Section'
,
'Web Site'
):
if
getattr
(
self
,
'__before_traverse__'
,
None
)
is
None
:
# migrate beforeTraverse hook if missing
handle
=
self
.
meta_type
+
'/'
+
self
.
getId
()
BeforeTraverse
.
registerBeforeTraverse
(
self
,
WebSectionTraversalHook
(),
handle
)
BeforeTraverse
.
registerBeforeTraverse
(
self
,
self
.
_getTraversalHookClass
()
(),
handle
)
else
:
# cleanup beforeTraverse hooks that may exist after this document was cloned.
self
.
_cleanupBeforeTraverseHooks
()
...
...
product/ERP5/Document/WebSite.py
View file @
42861d94
...
...
@@ -28,6 +28,7 @@
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5.Document.WebSection
import
WebSection
from
Products.ERP5.Document.WebSection
import
WebSectionTraversalHook
from
Products.ERP5Type
import
Permissions
,
PropertySheet
from
Products.ERP5Type.Cache
import
CachingMethod
...
...
@@ -40,12 +41,13 @@ from warnings import warn
WEBSITE_KEY
=
'web_site_value'
WEBSITE_LANGUAGE_KEY
=
'web_site_language'
class
WebSiteTraversalHook
(
Persistent
):
"""
This is used by WebSite to rewrite URLs in such way
that once a user gets into a Web Site object, all
documents referenced by the web site are accessed
through the web site rather than directly.
class
WebSiteTraversalHook
(
WebSectionTraversalHook
):
"""Traversal Hook for websites
* Change the skin selection to the one defined on the website (same as websection)
* Select default website language
* Change URL generation so that content URLs includes the website in the URL
We inherit for persistent, so that pickle mechanism ignores _v_request .
"""
...
...
@@ -110,11 +112,8 @@ class WebSiteTraversalHook(Persistent):
self
.
_v_request
=
request
request
.
physicalPathToVirtualPath
=
self
.
_physicalPathToVirtualPath
if
not
request
.
get
(
'ignore_layout'
,
None
):
# If a skin selection is defined in this web site, change the skin now.
skin_selection_name
=
container
.
getSkinSelectionName
()
if
skin_selection_name
and
request
.
get
(
'portal_skin'
,
None
)
is
None
:
container
.
getPortalObject
().
changeSkin
(
skin_selection_name
)
# Set skin selection
WebSectionTraversalHook
.
__call__
(
self
,
container
,
request
)
# Set default language if any
default_language
=
container
.
getDefaultAvailableLanguage
()
...
...
@@ -186,35 +185,8 @@ class WebSite(WebSection):
DeprecationWarning
,
stacklevel
=
2
)
return
self
.
getExtensibleContent
(
request
,
name
)
# Virtual Hosting Support
security
.
declarePrivate
(
'manage_beforeDelete'
)
def
manage_beforeDelete
(
self
,
item
,
container
):
if
item
is
self
:
handle
=
self
.
meta_type
+
'/'
+
self
.
getId
()
BeforeTraverse
.
unregisterBeforeTraverse
(
item
,
handle
)
WebSection
.
manage_beforeDelete
(
self
,
item
,
container
)
security
.
declarePrivate
(
'manage_afterAdd'
)
def
manage_afterAdd
(
self
,
item
,
container
):
if
item
is
self
:
handle
=
self
.
meta_type
+
'/'
+
self
.
getId
()
BeforeTraverse
.
registerBeforeTraverse
(
item
,
WebSiteTraversalHook
(),
handle
)
WebSection
.
manage_afterAdd
(
self
,
item
,
container
)
security
.
declarePrivate
(
'manage_afterClone'
)
def
manage_afterClone
(
self
,
item
):
self
.
_cleanupBeforeTraverseHooks
()
WebSection
.
manage_afterClone
(
self
,
item
)
def
_cleanupBeforeTraverseHooks
(
self
):
# unregister all before traversal hooks that do not belong to us.
my_handle
=
self
.
meta_type
+
'/'
+
self
.
getId
()
handle_to_unregister_list
=
[]
for
(
priority
,
handle
),
hook
in
self
.
__before_traverse__
.
items
():
if
isinstance
(
hook
,
WebSiteTraversalHook
)
and
handle
!=
my_handle
:
handle_to_unregister_list
.
append
(
handle
)
for
handle
in
handle_to_unregister_list
:
BeforeTraverse
.
unregisterBeforeTraverse
(
self
,
handle
)
def
_getTraversalHookClass
(
self
):
return
WebSiteTraversalHook
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getPermanentURLList'
)
def
getPermanentURLList
(
self
,
document
):
...
...
@@ -280,13 +252,3 @@ class WebSite(WebSection):
else
:
return
[]
def
_edit
(
self
,
**
kw
):
if
self
.
getPortalType
()
==
'Web Site'
:
if
getattr
(
self
,
'__before_traverse__'
,
None
)
is
None
:
# migrate beforeTraverse hook if missing
handle
=
self
.
meta_type
+
'/'
+
self
.
getId
()
BeforeTraverse
.
registerBeforeTraverse
(
self
,
WebSiteTraversalHook
(),
handle
)
else
:
# cleanup beforeTraverse hooks that may exist after this document was cloned.
self
.
_cleanupBeforeTraverseHooks
()
super
(
WebSite
,
self
).
_edit
(
**
kw
)
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