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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
erp5
Commits
6a46887a
Commit
6a46887a
authored
Jun 22, 2016
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Web: redirect to the minimum URL if verbose languages exist in URL.
parent
38a53420
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
product/ERP5/Document/WebSite.py
product/ERP5/Document/WebSite.py
+14
-0
product/ERP5/tests/testERP5Web.py
product/ERP5/tests/testERP5Web.py
+42
-0
No files found.
product/ERP5/Document/WebSite.py
View file @
6a46887a
...
...
@@ -37,6 +37,7 @@ from Persistence import Persistent
from
ZPublisher
import
BeforeTraverse
from
ZPublisher.HTTPRequest
import
HTTPRequest
from
warnings
import
warn
from
zExceptions
import
Redirect
WEBSITE_KEY
=
'web_site_value'
WEBSITE_LANGUAGE_KEY
=
'web_site_language'
...
...
@@ -171,9 +172,16 @@ class WebSite(WebSection):
# as a language selection only if language_list
# was defined or set default language
if
name
in
language_list
:
default_language
=
self
.
getDefaultAvailableLanguage
()
if
request
.
get
(
'AcceptLanguage'
)
is
not
None
:
request
[
'AcceptLanguage'
].
set
(
name
,
100
)
request
.
set
(
WEBSITE_LANGUAGE_KEY
,
name
)
if
self
.
isTempObject
()
or
name
==
default_language
:
redirect_path_list
=
[
self
.
getOriginalDocument
().
absolute_url
()]
if
name
!=
default_language
:
redirect_path_list
.
append
(
name
)
redirect_path_list
.
extend
(
reversed
(
request
[
'TraversalRequestNameStack'
]))
request
[
'minimum_language_redirect_url'
]
=
'/'
.
join
(
redirect_path_list
)
return
self
.
getOriginalDocument
().
asContext
(
id
=
name
)
return
WebSection
.
getExtensibleContent
(
self
,
request
,
name
)
...
...
@@ -188,6 +196,12 @@ class WebSite(WebSection):
def
_getTraversalHookClass
(
self
):
return
WebSiteTraversalHook
def
__before_publishing_traverse__
(
self
,
self2
,
request
):
redirect_url
=
request
.
get
(
'minimum_language_redirect_url'
)
if
redirect_url
:
raise
Redirect
(
redirect_url
)
return
super
(
WebSite
,
self
).
__before_publishing_traverse__
(
self2
,
request
)
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getPermanentURLList'
)
def
getPermanentURLList
(
self
,
document
):
"""
...
...
product/ERP5/tests/testERP5Web.py
View file @
6a46887a
...
...
@@ -966,6 +966,48 @@ Hé Hé Hé!""", page.asText().strip())
request
[
'HTTP_REFERER'
]
=
webpage_bg_fr
.
absolute_url
()
self
.
assertEqual
(
webpage_bg_fr
.
Base_doLanguage
(
'de'
),
webpage_bg_fr
.
absolute_url
().
replace
(
'/bg/fr/'
,
'/de/'
))
# /bg/en/fr/xxx should be redirected to /fr/xxx
website_bg_en_fr
=
self
.
portal
.
restrictedTraverse
(
'web_site_module/%s/bg/en/fr'
%
website_id
)
websection_bg_en_fr
=
self
.
portal
.
restrictedTraverse
(
'web_site_module/%s/bg/en/fr/%s'
%
(
website_id
,
websection_id
))
webpage_bg_en_fr
=
self
.
portal
.
restrictedTraverse
(
'web_site_module/%s/bg/en/fr/%s/%s'
%
(
website_id
,
websection_id
,
page_ref
))
self
.
assertEqual
(
self
.
publish
(
website_bg_en_fr
.
absolute_url
(
relative
=
1
)).
getHeader
(
'location'
),
website_fr
.
absolute_url
())
self
.
assertEqual
(
self
.
publish
(
websection_bg_en_fr
.
absolute_url
(
relative
=
1
)).
getHeader
(
'location'
),
websection_fr
.
absolute_url
())
self
.
assertEqual
(
self
.
publish
(
webpage_bg_en_fr
.
absolute_url
(
relative
=
1
)).
getHeader
(
'location'
),
webpage_fr
.
absolute_url
())
# /bg/en/xxx should be redirected to /xxx where en is the default language
website_bg_en
=
self
.
portal
.
restrictedTraverse
(
'web_site_module/%s/bg/en'
%
website_id
)
websection_bg_en
=
self
.
portal
.
restrictedTraverse
(
'web_site_module/%s/bg/en/%s'
%
(
website_id
,
websection_id
))
webpage_bg_en
=
self
.
portal
.
restrictedTraverse
(
'web_site_module/%s/bg/en/%s/%s'
%
(
website_id
,
websection_id
,
page_ref
))
self
.
assertEqual
(
self
.
publish
(
website_bg_en
.
absolute_url
(
relative
=
1
)).
getHeader
(
'location'
),
website
.
absolute_url
())
self
.
assertEqual
(
self
.
publish
(
websection_bg_en
.
absolute_url
(
relative
=
1
)).
getHeader
(
'location'
),
websection
.
absolute_url
())
self
.
assertEqual
(
self
.
publish
(
webpage_bg_en
.
absolute_url
(
relative
=
1
)).
getHeader
(
'location'
),
webpage
.
absolute_url
())
# /en/xxx should be redirected to /xxx where en is the default language
website_en
=
self
.
portal
.
restrictedTraverse
(
'web_site_module/%s/en'
%
website_id
)
websection_en
=
self
.
portal
.
restrictedTraverse
(
'web_site_module/%s/en/%s'
%
(
website_id
,
websection_id
))
webpage_en
=
self
.
portal
.
restrictedTraverse
(
'web_site_module/%s/en/%s/%s'
%
(
website_id
,
websection_id
,
page_ref
))
self
.
assertEqual
(
self
.
publish
(
website_en
.
absolute_url
(
relative
=
1
)).
getHeader
(
'location'
),
website
.
absolute_url
())
self
.
assertEqual
(
self
.
publish
(
websection_en
.
absolute_url
(
relative
=
1
)).
getHeader
(
'location'
),
websection
.
absolute_url
())
self
.
assertEqual
(
self
.
publish
(
webpage_en
.
absolute_url
(
relative
=
1
)).
getHeader
(
'location'
),
webpage
.
absolute_url
())
def
test_13_DocumentCache
(
self
):
"""
Test that when a document is modified, it can be accessed through a
...
...
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