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