Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
823ba251
Commit
823ba251
authored
Mar 30, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved the ``absoluteurl`` views into the OFS package.
parent
88ea141c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
200 additions
and
173 deletions
+200
-173
doc/CHANGES.rst
doc/CHANGES.rst
+2
-0
src/OFS/absoluteurl.py
src/OFS/absoluteurl.py
+139
-0
src/OFS/absoluteurl.zcml
src/OFS/absoluteurl.zcml
+52
-0
src/Products/Five/browser/absoluteurl.py
src/Products/Five/browser/absoluteurl.py
+6
-126
src/Products/Five/browser/configure.zcml
src/Products/Five/browser/configure.zcml
+1
-47
No files found.
doc/CHANGES.rst
View file @
823ba251
...
...
@@ -11,6 +11,8 @@ Trunk (unreleased)
Restructuring
+++++++++++++
-
Moved
the
``
absoluteurl
``
views
into
the
OFS
package
.
-
Moved
``
testbrowser
``
module
into
the
Testing
package
.
-
Moved
the
code
handling
ZCML
loading
into
the
``
Zope2
.
App
``
package
.
The
...
...
src/OFS/absoluteurl.py
0 → 100644
View file @
823ba251
##############################################################################
#
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import
urllib
from
Acquisition
import
aq_parent
from
OFS.interfaces
import
ITraversable
from
zope.component
import
getMultiAdapter
from
zope.interface
import
implements
from
zope.traversing.browser.interfaces
import
IAbsoluteURL
from
zope.traversing.browser.absoluteurl
import
_insufficientContext
,
_safe
from
zope.publisher.browser
import
BrowserView
class
AbsoluteURL
(
BrowserView
):
"""An absolute_url adapter for generic objects in Zope 2 that
aren't OFS.Traversable (e.g. views, resources, etc.).
This is very close to the generic implementation from
zope.traversing.browser, but the Zope 2 request doesn't support
all the methods that it uses yet.
"""
implements
(
IAbsoluteURL
)
def
__unicode__
(
self
):
return
urllib
.
unquote
(
self
.
__str__
()).
decode
(
'utf-8'
)
def
__str__
(
self
):
context
=
self
.
context
request
=
self
.
request
container
=
aq_parent
(
context
)
if
container
is
None
:
raise
TypeError
(
_insufficientContext
)
url
=
str
(
getMultiAdapter
((
container
,
request
),
name
=
'absolute_url'
))
name
=
self
.
_getContextName
(
context
)
if
name
is
None
:
raise
TypeError
(
_insufficientContext
)
if
name
:
url
+=
'/'
+
urllib
.
quote
(
name
.
encode
(
'utf-8'
),
_safe
)
return
url
__call__
=
__str__
def
_getContextName
(
self
,
context
):
if
getattr
(
context
,
'getId'
,
None
)
is
not
None
:
return
context
.
getId
()
return
getattr
(
context
,
'__name__'
,
None
)
def
breadcrumbs
(
self
):
context
=
self
.
context
request
=
self
.
request
# We do this here do maintain the rule that we must be wrapped
container
=
aq_parent
(
context
)
if
container
is
None
:
raise
TypeError
(
_insufficientContext
)
base
=
tuple
(
getMultiAdapter
((
container
,
request
),
name
=
'absolute_url'
).
breadcrumbs
())
name
=
self
.
_getContextName
(
context
)
if
name
is
None
:
raise
TypeError
(
_insufficientContext
)
if
name
:
base
+=
({
'name'
:
name
,
'url'
:
(
"%s/%s"
%
(
base
[
-
1
][
'url'
],
urllib
.
quote
(
name
.
encode
(
'utf-8'
),
_safe
)))
},
)
return
base
class
OFSTraversableAbsoluteURL
(
BrowserView
):
"""An absolute_url adapter for OFS.Traversable subclasses
"""
implements
(
IAbsoluteURL
)
def
__unicode__
(
self
):
return
urllib
.
unquote
(
self
.
__str__
()).
decode
(
'utf-8'
)
def
__str__
(
self
):
return
self
.
context
.
absolute_url
()
__call__
=
__str__
def
breadcrumbs
(
self
):
context
=
self
.
context
container
=
aq_parent
(
context
)
request
=
self
.
request
name
=
context
.
getId
()
if
(
container
is
None
or
self
.
_isVirtualHostRoot
()
or
not
ITraversable
.
providedBy
(
container
)):
return
({
'name'
:
name
,
'url'
:
context
.
absolute_url
()},)
view
=
getMultiAdapter
((
container
,
request
),
IAbsoluteURL
)
base
=
tuple
(
view
.
breadcrumbs
())
base
+=
(
{
'name'
:
name
,
'url'
:
(
"%s/%s"
%
(
base
[
-
1
][
'url'
],
name
))},)
return
base
def
_isVirtualHostRoot
(
self
):
virtualrootpath
=
self
.
request
.
get
(
'VirtualRootPhysicalPath'
,
None
)
if
virtualrootpath
is
None
:
return
False
context
=
self
.
context
return
context
.
restrictedTraverse
(
virtualrootpath
)
==
context
class
RootAbsoluteURL
(
OFSTraversableAbsoluteURL
):
"""An absolute_url adapter for the root object (OFS.Application)
"""
def
breadcrumbs
(
self
):
context
=
self
.
context
request
=
self
.
request
return
({
'name'
:
context
.
getId
(),
'url'
:
context
.
absolute_url
()
},)
src/OFS/absoluteurl.zcml
0 → 100644
View file @
823ba251
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
for="*"
name="absolute_url"
class=".absoluteurl.AbsoluteURL"
permission="zope.Public"
allowed_interface="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<view
for="*"
factory=".absoluteurl.AbsoluteURL"
type="zope.publisher.interfaces.http.IHTTPRequest"
permission="zope.Public"
provides="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<browser:page
for=".interfaces.ITraversable"
name="absolute_url"
class=".absoluteurl.OFSTraversableAbsoluteURL"
permission="zope.Public"
allowed_interface="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<view
for=".interfaces.ITraversable"
factory=".absoluteurl.OFSTraversableAbsoluteURL"
type="zope.publisher.interfaces.http.IHTTPRequest"
permission="zope.Public"
provides="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<browser:page
for=".interfaces.IApplication"
name="absolute_url"
class=".absoluteurl.RootAbsoluteURL"
permission="zope.Public"
allowed_interface="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<view
for=".interfaces.IApplication"
factory=".absoluteurl.RootAbsoluteURL"
type="zope.publisher.interfaces.http.IHTTPRequest"
permission="zope.Public"
provides="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
</configure>
src/Products/Five/browser/absoluteurl.py
View file @
823ba251
...
...
@@ -11,131 +11,11 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Absolute URL
$Id$
"""
import
urllib
from
Acquisition
import
aq_inner
,
aq_parent
from
OFS.interfaces
import
ITraversable
from
zope.deferredimport
import
deprecated
from
zope.interface
import
implements
from
zope.component
import
getMultiAdapter
from
zope.traversing.browser.interfaces
import
IAbsoluteURL
from
zope.traversing.browser.absoluteurl
import
_insufficientContext
,
_safe
from
Products.Five.browser
import
BrowserView
class
AbsoluteURL
(
BrowserView
):
"""An absolute_url adapter for generic objects in Zope 2 that
aren't OFS.Traversable (e.g. views, resources, etc.).
This is very close to the generic implementation from
zope.traversing.browser, but the Zope 2 request doesn't support
all the methods that it uses yet.
"""
implements
(
IAbsoluteURL
)
def
__unicode__
(
self
):
return
urllib
.
unquote
(
self
.
__str__
()).
decode
(
'utf-8'
)
def
__str__
(
self
):
context
=
self
.
context
request
=
self
.
request
container
=
aq_parent
(
context
)
if
container
is
None
:
raise
TypeError
(
_insufficientContext
)
url
=
str
(
getMultiAdapter
((
container
,
request
),
name
=
'absolute_url'
))
name
=
self
.
_getContextName
(
context
)
if
name
is
None
:
raise
TypeError
(
_insufficientContext
)
if
name
:
url
+=
'/'
+
urllib
.
quote
(
name
.
encode
(
'utf-8'
),
_safe
)
return
url
__call__
=
__str__
def
_getContextName
(
self
,
context
):
if
getattr
(
context
,
'getId'
,
None
)
is
not
None
:
return
context
.
getId
()
return
getattr
(
context
,
'__name__'
,
None
)
def
breadcrumbs
(
self
):
context
=
self
.
context
request
=
self
.
request
# We do this here do maintain the rule that we must be wrapped
container
=
aq_parent
(
context
)
if
container
is
None
:
raise
TypeError
(
_insufficientContext
)
base
=
tuple
(
getMultiAdapter
((
container
,
request
),
name
=
'absolute_url'
).
breadcrumbs
())
name
=
self
.
_getContextName
(
context
)
if
name
is
None
:
raise
TypeError
(
_insufficientContext
)
if
name
:
base
+=
({
'name'
:
name
,
'url'
:
(
"%s/%s"
%
(
base
[
-
1
][
'url'
],
urllib
.
quote
(
name
.
encode
(
'utf-8'
),
_safe
)))
},
)
return
base
class
OFSTraversableAbsoluteURL
(
BrowserView
):
"""An absolute_url adapter for OFS.Traversable subclasses
"""
implements
(
IAbsoluteURL
)
def
__unicode__
(
self
):
return
urllib
.
unquote
(
self
.
__str__
()).
decode
(
'utf-8'
)
def
__str__
(
self
):
context
=
aq_inner
(
self
.
context
)
return
context
.
absolute_url
()
__call__
=
__str__
def
breadcrumbs
(
self
):
context
=
aq_inner
(
self
.
context
)
container
=
aq_parent
(
context
)
request
=
self
.
request
name
=
context
.
getId
()
if
(
container
is
None
or
self
.
_isVirtualHostRoot
()
or
not
ITraversable
.
providedBy
(
container
)):
return
({
'name'
:
name
,
'url'
:
context
.
absolute_url
()},)
view
=
getMultiAdapter
((
container
,
request
),
IAbsoluteURL
)
base
=
tuple
(
view
.
breadcrumbs
())
base
+=
(
{
'name'
:
name
,
'url'
:
(
"%s/%s"
%
(
base
[
-
1
][
'url'
],
name
))},)
return
base
def
_isVirtualHostRoot
(
self
):
virtualrootpath
=
self
.
request
.
get
(
'VirtualRootPhysicalPath'
,
None
)
if
virtualrootpath
is
None
:
return
False
context
=
aq_inner
(
self
.
context
)
return
context
.
restrictedTraverse
(
virtualrootpath
)
==
context
class
RootAbsoluteURL
(
OFSTraversableAbsoluteURL
):
"""An absolute_url adapter for the root object (OFS.Application)
"""
def
breadcrumbs
(
self
):
context
=
self
.
context
request
=
self
.
request
return
({
'name'
:
context
.
getId
(),
'url'
:
context
.
absolute_url
()
},)
deprecated
(
"Please import from OFS.absoluteurl"
,
AbsoluteURL
=
'OFS.absoluteurl:AbsoluteURL'
,
OFSTraversableAbsoluteURL
=
'OFS.absoluteurl:OFSTraversableAbsoluteURL'
,
RootAbsoluteURL
=
'OFS.absoluteurl:RootAbsoluteURL'
,
)
src/Products/Five/browser/configure.zcml
View file @
823ba251
...
...
@@ -5,53 +5,7 @@
interface="zope.browsermenu.interfaces.IMenuItemType"
/>
<browser:page
for="*"
name="absolute_url"
class=".absoluteurl.AbsoluteURL"
permission="zope.Public"
allowed_interface="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<view
for="*"
factory=".absoluteurl.AbsoluteURL"
type="zope.publisher.interfaces.http.IHTTPRequest"
permission="zope.Public"
provides="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<browser:page
for="OFS.interfaces.ITraversable"
name="absolute_url"
class=".absoluteurl.OFSTraversableAbsoluteURL"
permission="zope.Public"
allowed_interface="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<view
for="OFS.interfaces.ITraversable"
factory=".absoluteurl.OFSTraversableAbsoluteURL"
type="zope.publisher.interfaces.http.IHTTPRequest"
permission="zope.Public"
provides="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<browser:page
for="OFS.interfaces.IApplication"
name="absolute_url"
class=".absoluteurl.RootAbsoluteURL"
permission="zope.Public"
allowed_interface="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<view
for="OFS.interfaces.IApplication"
factory=".absoluteurl.RootAbsoluteURL"
type="zope.publisher.interfaces.http.IHTTPRequest"
permission="zope.Public"
provides="zope.traversing.browser.interfaces.IAbsoluteURL"
/>
<include package="OFS" file="absoluteurl.zcml"/>
<browser:view
for="OFS.interfaces.IObjectManager"
...
...
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