summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Vagelpohl <jens@dataflake.org>2009-06-23 10:57:31 +0000
committerJens Vagelpohl <jens@dataflake.org>2009-06-23 10:57:31 +0000
commit2ebcfd5b1d6e010779a177bf0ef9a6d0b8fe9fa1 (patch)
treee95886ed609517836a388b253b9a515e275fbbf7
parentbce8fbdcd2489290a424c6ab5f592602806434ad (diff)
downloadProducts.JRedirector-2ebcfd5b1d6e010779a177bf0ef9a6d0b8fe9fa1.zip
Products.JRedirector-2ebcfd5b1d6e010779a177bf0ef9a6d0b8fe9fa1.tar.gz
- more modernization
git-svn-id: file:///svn-public/Products.JRedirector/trunk@1810 835909ba-7c00-0410-bfa4-884f43845301
-rw-r--r--Products/JRedirector/JRedirector.py77
-rw-r--r--Products/JRedirector/__init__.py2
-rw-r--r--Products/JRedirector/interfaces.py22
3 files changed, 71 insertions, 30 deletions
diff --git a/Products/JRedirector/JRedirector.py b/Products/JRedirector/JRedirector.py
index 1f8ccea..2905eee 100644
--- a/Products/JRedirector/JRedirector.py
+++ b/Products/JRedirector/JRedirector.py
@@ -21,6 +21,7 @@ import time
from AccessControl import ClassSecurityInfo
from AccessControl.Permissions import manage_properties
from AccessControl.Permissions import view_management_screens
+from Acquisition import aq_base
from Acquisition import aq_inner
from Acquisition import aq_parent
from App.class_init import default__class_init__ as InitializeClass
@@ -29,16 +30,21 @@ from App.special_dtml import DTMLFile
from BTrees.OOBTree import OOBTree
from DateTime.DateTime import DateTime
from OFS.SimpleItem import SimpleItem
-from Globals import MessageDialog, PersistentMapping
+from Globals import PersistentMapping
+from zope.interface import implements
+
+from Products.JRedirector.interfaces import IJRedirector
_dtmldir = os.path.join(package_home(globals()), 'dtml')
addJRedirectorForm = DTMLFile('add', _dtmldir)
class JRedirector(SimpleItem):
- """ JRedirector """
+ """ JRedirector
+ """
security = ClassSecurityInfo()
meta_type = 'JRedirector'
+ implements(IJRedirector)
manage_log = DTMLFile('dtml/log', globals())
manage_map = DTMLFile('dtml/mappings', globals())
@@ -60,7 +66,6 @@ class JRedirector(SimpleItem):
def __init__(self, id, title='', default_redirect='', loglevel=3):
- """ Initialize a new JRedirector instance """
self.id = id
self.title = title
self._default_redirect = default_redirect
@@ -71,7 +76,8 @@ class JRedirector(SimpleItem):
security.declarePrivate('_getRedirectData')
def _getRedirectData(self, REQUEST):
- """ Get the redirect URL and log """
+ """ Get the redirect URL and log
+ """
wildcard_match = 0
server_url = REQUEST.get('SERVER_URL')
referrer = REQUEST.get('HTTP_REFERER', '').strip() or 'n/a'
@@ -145,7 +151,8 @@ class JRedirector(SimpleItem):
security.declarePublic('redirect')
def redirect(self, REQUEST):
- """ Handle a redirect for a given URL """
+ """ Handle a redirect for a given URL
+ """
redir_data = self._getRedirectData(REQUEST)
if redir_data:
@@ -162,7 +169,8 @@ class JRedirector(SimpleItem):
security.declarePublic('getRedirectURL')
def getRedirectURL(self, REQUEST):
- """ Get URL and status for a redirect """
+ """ Get URL and status for a redirect
+ """
redir_path = ''
redir_status = ''
@@ -182,7 +190,8 @@ class JRedirector(SimpleItem):
, loglevel=3
, REQUEST=None
):
- """ Edit the JRedirector folder properties """
+ """ Edit the JRedirector folder properties
+ """
self.title = title
self._default_redirect = default_redirect
self._loglevel = int(loglevel)
@@ -191,30 +200,35 @@ class JRedirector(SimpleItem):
msg = 'Properties changed.'
return self.manage_settings(manage_tabs_message=msg)
+
security.declareProtected(view_management_screens, 'getLoglevel')
def getLoglevel(self):
- """ Return the level of logging """
+ """ Return the level of logging
+ """
return getattr(self, '_loglevel', 3)
security.declareProtected(view_management_screens, 'getMappings')
def getMappings(self):
- """ Return the existing mappings """
+ """ Return the existing mappings
+ """
return self._redirects.items()
security.declareProtected(view_management_screens, 'getMapping')
def getMapping(self, old_url):
- """ Return a specific mapping """
+ """ Return a specific mapping
+ """
return self._redirects.get(old_url, {})
security.declarePrivate('_getLogStore')
def _getLogStore(self):
- """ Indirection to allow flexibility in backend stores """
+ """ Indirection to allow flexibility in backend stores
+ """
cur_log = self._log
- if isinstance(cur_log, PersistentMapping):
+ if not isinstance(cur_log, OOBTree):
self._log = OOBTree()
for key, value in cur_log.items():
@@ -225,10 +239,10 @@ class JRedirector(SimpleItem):
return cur_log
-
security.declareProtected(view_management_screens, 'getLog')
def getLog(self):
- """ Return the log """
+ """ Return the log
+ """
log = self._getLogStore()
log_items = list(log.items())
sort_f = lambda a, b: cmp(b[1]['total_count'], a[1]['total_count'])
@@ -239,7 +253,8 @@ class JRedirector(SimpleItem):
security.declareProtected(view_management_screens, 'clearLog')
def clearLog(self, REQUEST=None):
- """ Clear out the log """
+ """ Clear out the log
+ """
self._getLogStore().clear()
if REQUEST is not None:
@@ -247,10 +262,10 @@ class JRedirector(SimpleItem):
return self.manage_log(manage_tabs_message=msg)
-
security.declareProtected(view_management_screens, 'getDefaultRedirect')
def getDefaultRedirect(self):
- """ Return the default redirect path value """
+ """ Return the default redirect path value
+ """
return self._default_redirect
@@ -263,7 +278,8 @@ class JRedirector(SimpleItem):
, is_wildcard=0
, REQUEST=None
):
- """ Add a new redirector mapping """
+ """ Add a new redirector mapping
+ """
if old_path.endswith('/'):
old_path = old_path[:-1]
@@ -283,7 +299,8 @@ class JRedirector(SimpleItem):
security.declareProtected(manage_properties, 'deleteRedirectorMappings')
def deleteRedirectorMappings(self, old_paths, REQUEST=None):
- """ Delete a redirector mapping """
+ """ Delete a redirector mapping
+ """
for old_path in old_paths:
if self._redirects.has_key(old_path):
del self._redirects[old_path]
@@ -300,20 +317,22 @@ def manage_addJRedirector( self
, loglevel=3
, REQUEST=None
):
- """ Called by Zope if you create a JRedirector from the ZMI """
+ """ Called by Zope if you create a JRedirector from the ZMI
+ """
+ container = self.this()
- if hasattr(self.this().aq_base, id) and REQUEST is not None:
+ if getattr(aq_base(container), id, None) is not None:
msg = 'Object already contains an item with id %s' % id
- return MessageDialog( title = 'Item Exists'
- , message = msg
- , action ='%s/manage_main' % REQUEST['URL1']
- )
-
- jr = JRedirector(id, title, default_redirect, loglevel)
- self._setObject(jr.getId(), jr)
+ else:
+ jr = JRedirector(id, title, default_redirect, loglevel)
+ container._setObject(jr.getId(), jr)
+ msg = 'Added JRedirector'
if REQUEST is not None:
- return self.manage_main(self, REQUEST)
+ goto = container.absolute_url()
+ qs = 'manage_tabs_message=%s' % msg
+ REQUEST.RESPONSE.redirect('%s/manage_main?%s' % (goto, qs))
InitializeClass(JRedirector)
+
diff --git a/Products/JRedirector/__init__.py b/Products/JRedirector/__init__.py
index 909f5bb..b7dbcef 100644
--- a/Products/JRedirector/__init__.py
+++ b/Products/JRedirector/__init__.py
@@ -10,7 +10,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-""" WatermarkImage initialization
+""" JRedirector initialization
$Id$
"""
diff --git a/Products/JRedirector/interfaces.py b/Products/JRedirector/interfaces.py
new file mode 100644
index 0000000..b3c4698
--- /dev/null
+++ b/Products/JRedirector/interfaces.py
@@ -0,0 +1,22 @@
+##############################################################################
+#
+# Copyright (c) 2002-2009 Jens Vagelpohl 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.
+#
+##############################################################################
+""" JRedirector interfaces
+
+$Id$
+"""
+
+from zope.interface import Interface
+
+class IJRedirector(Interface):
+ """ Marker interface for JRedirector class
+ """