summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Vagelpohl <jens@netz.ooo>2003-04-04 21:33:35 +0000
committerJens Vagelpohl <jens@netz.ooo>2003-04-04 21:33:35 +0000
commitc726a273a959a16a9fc3a7f9a72187ba92af55c6 (patch)
tree54e534a22fcb96677f29d146cdcc8ba0b9776055
parent5ee320924d16d29714403335dea8ac0349b0415b (diff)
downloadViewsManager-c726a273a959a16a9fc3a7f9a72187ba92af55c6.zip
ViewsManager-c726a273a959a16a9fc3a7f9a72187ba92af55c6.tar.gz
Initial revision
-rw-r--r--CHANGES.txt8
-rw-r--r--INSTALL.txt18
-rw-r--r--LICENSE.txt77
-rw-r--r--Permissions.py13
-rw-r--r--README.txt8
-rw-r--r--VERSION.txt1
-rw-r--r--ViewsManager.py171
-rw-r--r--__init__.py27
-rw-r--r--help/Add.stx15
-rw-r--r--help/Mappings.stx27
-rw-r--r--www/addViewsManager.pt40
-rw-r--r--www/views.pt140
-rw-r--r--www/viewsmanager.gifbin0 -> 146 bytes
13 files changed, 545 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
new file mode 100644
index 0000000..33031ca
--- /dev/null
+++ b/CHANGES.txt
@@ -0,0 +1,8 @@
+CHANGES.txt for the ViewsManager
+
+ This file contains change information for the ViewsManager product.
+
+ 0.5
+
+ First version
+
diff --git a/INSTALL.txt b/INSTALL.txt
new file mode 100644
index 0000000..474afd0
--- /dev/null
+++ b/INSTALL.txt
@@ -0,0 +1,18 @@
+Installing the ViewsManager Product
+
+ This product does not require any special handling after unzipping
+ and untarring it in the Zope Products directory. You should do
+ something like::
+
+ $ cp ViewsManager-xyz.tgz <zope_root>/lib/python/Products
+ $ cd <zope_root>/lib/python/Products
+ $ tar zxvf ViewsManager-xyz.tgz
+ <watch files being decompressed>
+
+ Windows users can use WinZip or similar, it can handle tarred
+ gzip files. Make sure to move the extracted ViewsManager
+ folder to your Zope installation's lib/python/Products-folder.
+
+ That's all. Do not forget to restart Zope afterwards.
+
+ See README.txt for any other dependencies and requirements.
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..c471cdb
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# License
+# -------
+#
+# Copyright (c) Jens Vagelpohl. All right reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions in source code must retain the above copyright
+# notice, this list of conditions, and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions, and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# 3. Jens Vagelpohl requests that attribution be given to Zope
+# in any manner possible. A significant investment has been put
+# into Zope, and this effort will continue if the Zope community
+# continues to grow. This is one way to assure that growth.
+#
+# 4. All advertising materials and documentation mentioning
+# features derived from or use of this software must display
+# the following acknowledgement:
+#
+# "This product includes software developed by Jens Vagelpohl
+# for use in the Z Object Publishing Environment
+# (http://www.zope.org/)."
+#
+# In the event that the product being advertised includes an
+# intact JTracker distribution (with copyright and license
+# included) then this clause is waived
+#
+# 5. Names associated with Jens Vagelpohl must not be used to
+# endorse or promote products derived from this software without
+# prior written permission from Jens Vagelpohl.
+#
+# 6. Modified redistributions of any form whatsoever must retain
+# the following acknowledgment:
+#
+# "This product includes software developed by Jens Vagelpohl
+# for use in the Z Object Publishing Environment
+# (http://www.zope.org/)."
+#
+# Intact (re-)distributions of any official JTracker
+# release do not require an external acknowledgement.
+#
+# 7. Modifications are encouraged but must be packaged separately as
+# patches to official software releases. Distributions that do not
+# clearly separate the patches from the original work must be clearly
+# labeled as unofficial distributions.
+#
+# 8. In the interest of improving this product the author requests that
+# changes be made available to him. This is not mandatory but part
+# of good open source development etiquette.
+#
+#
+# Disclaimer
+#
+# THIS SOFTWARE IS PROVIDED BY JENS VAGELPOHL ``AS IS'' AND ANY
+# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JENS VAGELPOHL OR HIS
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+##############################################################################
+
diff --git a/Permissions.py b/Permissions.py
new file mode 100644
index 0000000..1958a5f
--- /dev/null
+++ b/Permissions.py
@@ -0,0 +1,13 @@
+##############################################################################
+#
+# Permissions.py Permissions defined for use with the ViewsManager Product
+#
+# This software is governed by a license. See
+# LICENSE.txt for the terms of this license.
+#
+##############################################################################
+
+__doc__ = """ ViewsManager Permission definitions """
+__version__ = '$Revision$'[11:-2]
+
+ManageViews = 'Manage Views'
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..6f5ec92
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,8 @@
+README for the ViewsManager Product
+
+ This product models software and software releases
+
+ **Tested Platforms**
+
+ This version of the ViewsManager has been written on and for
+ Zope 2.6 and up.
diff --git a/VERSION.txt b/VERSION.txt
new file mode 100644
index 0000000..2eb3c4f
--- /dev/null
+++ b/VERSION.txt
@@ -0,0 +1 @@
+0.5
diff --git a/ViewsManager.py b/ViewsManager.py
new file mode 100644
index 0000000..6d07265
--- /dev/null
+++ b/ViewsManager.py
@@ -0,0 +1,171 @@
+#####################################################################
+#
+# ViewsManager A module modeling a software package
+#
+# This software is governed by a license. See
+# LICENSE.txt for the terms of this license.
+#
+#####################################################################
+__version__='$Revision$'[11:-2]
+
+# General python imports
+import os
+
+# Zope imports
+from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+from Globals import InitializeClass, package_home, PersistentMapping
+from AccessControl import ClassSecurityInfo
+from AccessControl.Permissions import view_management_screens
+from OFS.Folder import Folder
+from BTrees.OOBTree import OOBTree
+from Acquisition import aq_base
+
+# Zoftware package imports
+from Permissions import ManageViews
+
+_registered_types = PersistentMapping()
+
+_wwwdir = os.path.join(package_home(globals()), 'www')
+addViewsManagerForm = PageTemplateFile('addViewsManager.pt', _wwwdir)
+
+
+def registerType(meta_type, view_info):
+ """ Register a product with the ViewsManager """
+ _registered_types[meta_type] = view_info.values()
+
+
+class ViewsManager(Folder):
+ """ ViewsManager - A tool to manage views """
+ meta_type = 'ViewsManager'
+ security = ClassSecurityInfo()
+ id = 'views_manager'
+
+ manage_options = ( (Folder.manage_options[0],)
+ + ( { 'label' : 'Mappings'
+ , 'action' : 'manage_views'
+ , 'help' : ('ViewsManager', 'Mappings.stx')
+ }, )
+ + Folder.manage_options[2:]
+ )
+
+ security.declareProtected(view_management_screens, 'manage_views')
+ manage_views = PageTemplateFile('views.pt', _wwwdir)
+
+
+ def __init__(self , id , title=''):
+ """ Create a new ViewsManager instance """
+ self.title = title
+ self._mapping = OOBTree()
+
+
+ security.declareProtected(ManageViews, 'manage_edit')
+ def manage_edit(self, title):
+ """ Edit the ViewsManager Object """
+ self.title = title
+
+
+ security.declareProtected(ManageViews, 'getRegisteredViews')
+ def getRegisteredViews(self):
+ """ Show all currently registered views """
+ registered = []
+ reg_keys = _registered_types.keys()
+ reg_keys.sort()
+
+ for key in reg_keys:
+ for view in _registered_types.get(key):
+ v_label = view.get('view_label')
+
+ registered.append( { 'map_key' : '%s:%s' % (key, v_label)
+ , 'meta_type' : key
+ , 'view_label' : v_label
+ , 'view_id' : view.get('view_id')
+ } )
+
+ return tuple(registered)
+
+
+ security.declareProtected(ManageViews, 'getViewMapping')
+ def getViewMapping(self):
+ """ Return the complete views mapping """
+ mapping = []
+ keys = list(self._mapping.keys())
+ keys.sort()
+
+ for key in keys:
+ mapping.append(self._mapping.get(key))
+
+ return mapping
+
+
+ security.declareProtected(ManageViews, 'setViewMapping')
+ def setViewMapping(self, map_key, internal_id, REQUEST=None):
+ """ Set a view for a specific meta_type and view label """
+ elems = map_key.split(':')
+ meta_type = elems[0]
+ view_label = ''.join(elems[1:])
+
+ self._mapping[map_key] = { 'map_key' : map_key
+ , 'meta_type' : meta_type
+ , 'view_label' : view_label
+ , 'internal_id' : internal_id
+ }
+
+ if REQUEST is not None:
+ msg = 'View mapping added'
+ return self.manage_views(manage_tabs_message=msg)
+
+
+ security.declareProtected(ManageViews, 'deleteViewMappings')
+ def deleteViewMappings(self, keys=[], REQUEST=None):
+ """ Remove view mappings """
+ for key in keys:
+ if self._mapping.has_key(key):
+ del self._mapping[key]
+
+ if REQUEST is not None:
+ msg = 'View mapping(s) deleted'
+ return self.manage_views(manage_tabs_message=msg)
+
+
+ security.declareProtected(ManageViews, 'getViewId')
+ def getViewId(self, meta_type, view_label):
+ """ Get a view ID by meta_type and view label """
+ view_data = self._mapping.get('%s:%s' % (meta_type, view_label), None)
+
+ if view_data is not None:
+ return view_data.get('internal_id')
+ else:
+ return None
+
+
+ security.declarePrivate('getViewObject')
+ def getViewObject(self, object, view_label):
+ """ Retrieve a view by meta_type and view label """
+ id = self.getViewId(getattr(object, 'meta_type', None), view_label)
+ view_ob = id and self._getOb(id, default=None) or None
+
+ if view_ob is None:
+ return None
+
+ return aq_base(view_ob).__of__(object)
+
+
+InitializeClass(ViewsManager)
+
+
+def manage_addViewsManager(self, title='', REQUEST=None):
+ """ Factory used to install new ViewsManager instances """
+ real_self = self.this()
+
+ if id in real_self.objectIds():
+ msg = 'Duplicate+ID+%s' % id
+ else:
+ vm = ViewsManager(id, title)
+ self._setObject(vm.getId(), vm)
+ msg = 'ViewsManager+added'
+
+ if REQUEST is not None:
+ ret_url = '%s/manage_main' % REQUEST['URL1']
+ REQUEST.RESPONSE.redirect('%s?manage_tabs_message=%s' % (ret_url, msg))
+
+
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..07fabf4
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# __init__.py Initialization code for the Zoftware Product
+#
+# This software is governed by a license. See
+# LICENSE.txt for the terms of this license.
+#
+##############################################################################
+
+__doc__ = """ Zoftware initialization module """
+__version__ = '$Revision$'[11:-2]
+
+from Permissions import ManageViews
+from ViewsManager import addViewsManagerForm, \
+ manage_addViewsManager, \
+ ViewsManager
+
+def initialize(context):
+ context.registerClass( ViewsManager
+ , permission=ManageViews
+ , constructors=( addViewsManagerForm
+ , manage_addViewsManager
+ )
+ , icon='www/viewsmanager.gif'
+ )
+
+ context.registerHelp()
diff --git a/help/Add.stx b/help/Add.stx
new file mode 100644
index 0000000..08efdf6
--- /dev/null
+++ b/help/Add.stx
@@ -0,0 +1,15 @@
+ViewsManager - Add: Create a new ViewsManager object
+
+ Description
+
+ The ViewsManager is an object that can be used to manage
+ views for objects. Products that are ViewsManager-aware can
+ register with the ViewsManager which will then allow the
+ site admin to customize views and forms used for the given
+ product in one place.
+
+ Controls
+
+ 'Title' -- The title for this ViewsManager.
+
+ 'Add' -- Instantiate the ViewsManager.
diff --git a/help/Mappings.stx b/help/Mappings.stx
new file mode 100644
index 0000000..67ae486
--- /dev/null
+++ b/help/Mappings.stx
@@ -0,0 +1,27 @@
+ViewsManager - Mappings: Map registered views to views in the ViewsManager
+
+ Description
+
+ The Mappings form is used to map registered views from
+ ViewsManager-aware products to views defined inside the ViewsManager
+ itself.
+
+ The top part of the form shows existing mappings and allows the site
+ admin to delete a mapping.
+
+ The 'Add new mapping' form at the bottom is used for defining new
+ mappings.
+
+ Controls
+
+ 'Registered view' -- A view in a ViewsManager-aware Zope product that
+ has registered itself with the ViewsManager product.
+
+ 'ViewsManager View' -- An object inside the ViewsManager (see the
+ 'Content' tab) that can act as a view.
+
+ 'Delete' -- Remove an existing mapping
+
+ 'Add' -- Add a new mapping (or replace an existing mapping)
+
+
diff --git a/www/addViewsManager.pt b/www/addViewsManager.pt
new file mode 100644
index 0000000..0022f04
--- /dev/null
+++ b/www/addViewsManager.pt
@@ -0,0 +1,40 @@
+<h1 tal:replace="structure here/manage_page_header">Header</h1>
+<h1 tal:replace="structure python: here.manage_form_title( here
+ , form_title='Add ViewsManager'
+ , help_product='ViewsManager'
+ , help_topic='Add.stx'
+ )">
+ Form Title Bar
+</h1>
+
+<p class="form-help">
+ Add a new ViewsManager using this form
+</p>
+
+<form action="manage_addViewsManager" method="post">
+
+ <table>
+
+ <tr>
+ <td align="left" valign="top"><div class="form-label">
+ Title
+ </div></td>
+ <td align="left" valign="top"><div class="form-element">
+ <input type="text" name="title" size="40" />
+ </div></td>
+ </tr>
+
+ <tr>
+ <td align="left" valign="top">&nbsp;</td>
+ <td align="left" valign="top"><div class="form-element">
+ <input class="form-element" type="submit" name="submit"
+ value=" Add " />
+ </div></td>
+ </tr>
+
+ </table>
+
+</form>
+
+<h1 tal:replace="structure here/manage_page_footer">Footer</h1>
+
diff --git a/www/views.pt b/www/views.pt
new file mode 100644
index 0000000..f63fb70
--- /dev/null
+++ b/www/views.pt
@@ -0,0 +1,140 @@
+<h1 tal:replace="structure here/manage_page_header">Header</h1>
+<h1 tal:define="tabs nocall: here/manage_tabs"
+ tal:replace="structure python: tabs(management_view='Mappings')">
+ Form Title Bar
+</h1>
+
+<p class="form-help">
+ Use this form to associate views with products.
+</p>
+
+<form method="post" action="deleteViewMappings"
+ tal:define="global map here/getViewMapping"
+ tal:condition="map">
+
+ <table width="98%" cellpadding="3" cellspacing="0">
+
+ <tr class="list-header">
+ <td align="left" valign="top" width="16"> &nbsp; </td>
+ <td align="left" valign="top"><div class="form-label">
+ Registered View
+ </div></td>
+ <td align="left" valign="top"><div class="form-label">
+ ViewsManager View
+ </div></td>
+ </tr>
+
+ <tbody tal:repeat="view map">
+
+ <tr class=""
+ tal:define="odd repeat/view/odd"
+ tal:attributes="class python: test(odd==1,'row-hilite','row-normal')">
+
+ <td align="left" valign="top">
+ <input type="checkbox" name="keys:list" value=""
+ tal:attributes="value view/map_key" />
+ </td>
+ <td align="left" valign="top">
+ <div class="list-item"
+ tal:content="string: ${view/meta_type}: ${view/view_label}">
+ My Type: Main View
+ </div>
+ </td>
+ <td align="left" valign="top"><div class="list-item">
+ <a href=""
+ tal:define="view_id view/internal_id;
+ view_url string:${here/absolute_url}/${view_id}"
+ tal:attributes="href string:${view_url}/manage_workspace"
+ tal:content="view_id">
+ my_view
+ </a>
+ </div></td>
+ </tr>
+
+ </tbody>
+
+ <tr>
+ <td align="left" valign="top" width="16"> &nbsp; </td>
+ <td colspan="2" align="left" valign="right"><div class="form-element">
+ <input type="submit" value=" Delete " />
+ </div></td>
+ </tr>
+
+ </table>
+
+</form>
+
+<div class="form-label"
+ tal:condition="not: map">
+ No mappings defined.
+</div>
+
+<p> &nbsp; </p>
+
+<form method="post" action="setViewMapping"
+ tal:define="global regs here/getRegisteredViews;
+ global obs here/objectValues"
+ tal:condition="regs">
+
+ <table cellpadding="3" cellspacing="0" width="98%">
+
+ <tr class="list-header">
+ <td colspan="2" align="left" valign="top"><div class="form-label">
+ Add new mapping
+ </div></td>
+ </tr>
+
+ <tr>
+ <td align="left" valign="top"><div class="form-label">
+ Registered View
+ </div></td>
+ <td align="left" valign="top"><div class="form-element">
+ <select name="map_key">
+ <option value=""
+ tal:repeat="reg regs"
+ tal:attributes="value reg/map_key"
+ tal:content="string: ${reg/meta_type}: ${reg/view_label}">
+ My Type: My View
+ </option>
+ </select>
+ </td>
+ </tr>
+
+ <tr>
+ <td align="left" valign="top"><div class="form-label">
+ ViewsManager View
+ </div></td>
+ <td align="left" valign="top"><div class="form-element">
+ <select name="internal_id"
+ tal:condition="obs">
+ <option value=""
+ tal:repeat="ob obs"
+ tal:attributes="value ob/getId"
+ tal:content="string:${ob/getId} (${ob/meta_type})">
+ my_view (Page Template)
+ </option>
+ </select>
+ <span tal:condition="not: obs">
+ No templates defined in this ViewsManager
+ </span>
+ </div></td>
+ </tr>
+
+ <tr>
+ <td align="left" valign="top" colspan="2"><div class="form-element">
+ <input type="submit" value=" Add "
+ tal:condition="obs" />
+ </div></td>
+ </tr>
+
+ </table>
+
+</form>
+
+<div class="form-label"
+ tal:condition="not: regs">
+ No products have registered themselves with the ViewsManager
+</div>
+
+<h1 tal:replace="structure here/manage_page_footer">Footer</h1>
+
diff --git a/www/viewsmanager.gif b/www/viewsmanager.gif
new file mode 100644
index 0000000..eb5bb2f
--- /dev/null
+++ b/www/viewsmanager.gif
Binary files differ