[Checkins] SVN: zmi.core/trunk/s Copy browser package from zope.app.preference.
Yusei Tahara
yusei at domen.cx
Sat Nov 21 02:52:44 EST 2009
Log message for revision 105937:
Copy browser package from zope.app.preference.
Changed:
U zmi.core/trunk/setup.py
U zmi.core/trunk/src/zmi/core/configure.zcml
A zmi.core/trunk/src/zmi/core/preference/
A zmi.core/trunk/src/zmi/core/preference/__init__.py
A zmi.core/trunk/src/zmi/core/preference/browser.py
A zmi.core/trunk/src/zmi/core/preference/configure.zcml
A zmi.core/trunk/src/zmi/core/preference/edit.pt
A zmi.core/trunk/src/zmi/core/preference/index.pt
A zmi.core/trunk/src/zmi/core/preference/macros.pt
A zmi.core/trunk/src/zmi/core/preference/menu.pt
A zmi.core/trunk/src/zmi/core/preference/subgroup.pt
-=-
Modified: zmi.core/trunk/setup.py
===================================================================
--- zmi.core/trunk/setup.py 2009-11-21 07:37:10 UTC (rev 105936)
+++ zmi.core/trunk/setup.py 2009-11-21 07:52:43 UTC (rev 105937)
@@ -64,6 +64,7 @@
'zope.app.i18nfile',
'zope.app.intid',
'zope.app.onlinehelp',
+ 'zope.app.preference',
'zope.app.principalannotation',
'zope.app.securitypolicy',
'zope.app.session',
@@ -75,7 +76,6 @@
extras_require=dict(test=['zope.app.testing',
'zope.securitypolicy',
'zope.testbrowser',
- 'zope.app.preference',
'zope.app.apidoc',
]),
include_package_data = True,
Modified: zmi.core/trunk/src/zmi/core/configure.zcml
===================================================================
--- zmi.core/trunk/src/zmi/core/configure.zcml 2009-11-21 07:37:10 UTC (rev 105936)
+++ zmi.core/trunk/src/zmi/core/configure.zcml 2009-11-21 07:52:43 UTC (rev 105937)
@@ -15,6 +15,7 @@
<include package=".i18nfile" />
<include package=".intid" />
<include package=".onlinehelp" />
+ <include package=".preference" />
<include package=".principalannotation" />
<include package=".securitypolicy" />
<include package=".session" />
Added: zmi.core/trunk/src/zmi/core/preference/browser.py
===================================================================
--- zmi.core/trunk/src/zmi/core/preference/browser.py (rev 0)
+++ zmi.core/trunk/src/zmi/core/preference/browser.py 2009-11-21 07:52:43 UTC (rev 105937)
@@ -0,0 +1,106 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""User Preferences Browser Views
+
+$Id: browser.py 95496 2009-01-29 18:48:33Z thefunny42 $
+"""
+__docformat__ = 'restructuredtext'
+
+import re
+import zope.component
+import zope.interface
+import zope.schema
+from zope.container.interfaces import IObjectFindFilter
+from zope.i18n import translate
+from zope.i18nmessageid import Message
+from zope.security.proxy import removeSecurityProxy
+from zope.traversing.api import getParent, getRoot
+
+from zope.app.basicskin.standardmacros import StandardMacros
+from zope.app.form.browser.editview import EditView
+from zope.app.pagetemplate.simpleviewclass import simple
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zmi.core.tree.cookie import CookieTreeView
+from zope.i18nmessageid import ZopeMessageFactory as _
+
+from zope.app.preference import interfaces
+
+
+NoneInterface = zope.interface.interface.InterfaceClass('None')
+
+class PreferencesMacros(StandardMacros):
+ """Page Template METAL macros for preferences"""
+ macro_pages = ('preference_macro_definitions',)
+
+
+class PreferenceGroupFilter(object):
+ """A special filter for """
+ zope.interface.implements(IObjectFindFilter)
+
+ def matches(self, obj):
+ """Decide whether the object is shown in the tree."""
+ if interfaces.IPreferenceCategory.providedBy(obj):
+ return True
+
+ if interfaces.IPreferenceGroup.providedBy(obj):
+ parent = getParent(obj)
+ if interfaces.IPreferenceCategory.providedBy(parent):
+ return True
+
+ return False
+
+
+class PreferencesTree(CookieTreeView):
+ """Preferences Tree using the stateful cookie tree."""
+
+ def tree(self):
+ root = getRoot(self.context)
+ filter = PreferenceGroupFilter()
+ return self.cookieTree(root, filter)
+
+pref_msg = _("${name} Preferences")
+
+class EditPreferenceGroup(EditView):
+
+ def __init__(self, context, request):
+ self.__used_for__ = removeSecurityProxy(context.__schema__)
+ self.schema = removeSecurityProxy(context.__schema__)
+
+ if self.schema is None:
+ self.schema = NoneInterface
+ zope.interface.alsoProvides(removeSecurityProxy(context),
+ NoneInterface)
+
+ name = translate(context.__title__, context=request,
+ default=context.__title__)
+ self.label = Message(pref_msg, mapping={u'name': name})
+ super(EditPreferenceGroup, self).__init__(context, request)
+ self.setPrefix(context.__id__)
+
+ def getIntroduction(self):
+ text = self.context.__description__ or self.schema.__doc__
+ text = translate(text, context=self.request, default=text)
+
+ # Determine common whitespace ...
+ cols = len(re.match('^[ ]*', text).group())
+ # ... and clean it up.
+ text = re.sub('\n[ ]{%i}' %cols, '\n', text).strip()
+
+ if not text:
+ return u''
+
+ # Render the description as ReST.
+ source = zope.component.createObject('zope.source.rest', text)
+ renderer = zope.component.getMultiAdapter((source, self.request))
+ return renderer.render()
Added: zmi.core/trunk/src/zmi/core/preference/configure.zcml
===================================================================
--- zmi.core/trunk/src/zmi/core/preference/configure.zcml (rev 0)
+++ zmi.core/trunk/src/zmi/core/preference/configure.zcml 2009-11-21 07:52:43 UTC (rev 105937)
@@ -0,0 +1,57 @@
+<configure
+ xmlns:browser="http://namespaces.zope.org/browser"
+ i18n_domain="zope"
+ >
+
+ <!-- Preference Groups -->
+ <browser:page
+ name="index.html"
+ for=".interfaces.IPreferenceGroup"
+ class=".browser.EditPreferenceGroup"
+ template="index.pt"
+ permission="zope.Public"
+ />
+
+ <browser:page
+ name="editAsSubGroup"
+ for=".interfaces.IPreferenceGroup"
+ class=".browser.EditPreferenceGroup"
+ template="subgroup.pt"
+ permission="zope.Public"
+ />
+
+ <browser:addMenuItem
+ class="zope.app.preference.default.DefaultPreferenceProvider"
+ title="Default User Preferences Provider"
+ description="A Default User Preferences Provider"
+ permission="zope.ManageSite"
+ />
+
+ <!-- Preferences-specific macros -->
+ <browser:page
+ for="*"
+ name="preferences_macros"
+ permission="zope.View"
+ class=".browser.PreferencesMacros"
+ allowed_interface="zope.interface.common.mapping.IItemMapping"
+ />
+
+ <browser:page
+ for="*"
+ name="preference_macro_definitions"
+ permission="zope.View"
+ template="macros.pt"
+ />
+
+
+ <!-- Preferences Tree -->
+
+ <browser:page
+ name="tree"
+ for=".interfaces.IPreferenceGroup"
+ class=".browser.PreferencesTree"
+ permission="zope.View"
+ attribute="tree"
+ />
+
+</configure>
Added: zmi.core/trunk/src/zmi/core/preference/edit.pt
===================================================================
--- zmi.core/trunk/src/zmi/core/preference/edit.pt (rev 0)
+++ zmi.core/trunk/src/zmi/core/preference/edit.pt 2009-11-21 07:52:43 UTC (rev 105937)
@@ -0,0 +1,123 @@
+<html metal:use-macro="context/@@apidoc_macros/details">
+<head>
+ <style type="text/css" media="all"
+ metal:fill-slot="style_slot">
+
+table.prefs {
+ border: 0pt;
+ width: 80%;
+}
+
+tr {
+ margin: 0pt;
+ padding: 0pt;
+ border: 0pt;
+}
+
+tr.odd {
+ background: #fffbbe;
+}
+
+tr.first td {
+ border-top: 1pt solid #0000C0;
+}
+
+td {
+ padding: 3pt;
+ border-bottom: 1pt solid #0000C0;
+}
+
+td.input {
+ vertical-align: middle;
+ text-align: center;
+}
+
+td.description {
+
+}
+
+td.controls {
+ margin-top: 10pt;
+ border: 0pt;
+ padding: 4pt;
+ background: #ccf;
+ text-align: right;
+}
+
+td.spacer {
+ padding: 5pt;
+ border: 0pt;
+}
+
+div.documentation blockquote {
+ margin: 0pt;
+ padding: 0pt;
+}
+
+div.error {
+ font-weight: bold;
+ margin: 3pt 0pt;
+ color: #ffaa22;
+}
+ </style>
+</head>
+<body metal:fill-slot="contents">
+
+ <h1 tal:content="view/label">Edit something</h1>
+
+ <div class="documentation" tal:content="structure view/getIntroduction">
+ Here is the doc string
+ </div>
+
+ <p tal:define="status view/update"
+ tal:condition="status"
+ tal:content="status" />
+
+ <p tal:condition="view/errors" i18n:translate="">
+ There are <strong tal:content="python:len(view.errors)"
+ i18n:name="num_errors">6</strong> input errors.
+ </p>
+ <br />
+
+ <form action="." tal:attributes="action request/URL" method="post"
+ enctype="multipart/form-data">
+
+ <table class="prefs" cellspacing="0" cellpadding="0">
+ <tal:block repeat="widget view/widgets" >
+ <tr class=""
+ tal:define="parity repeat/widget/parity;
+ firstrow repeat/widget/start"
+ tal:attributes="class python: parity +
+ (firstrow and ' first' or '')">
+ <td class="description">
+ <b tal:content="widget/label">Option</b>
+ <div class="indent small">
+ <div tal:content="widget/hint">
+ Explanation
+ </div>
+ <div class="error" tal:define="error widget/error"
+ tal:condition="error" tal:content="structure error">
+ The Error
+ </div>
+ </div>
+ </td>
+ <td class="input" tal:content="structure widget">
+ <input type="text" style="width:100%"/>
+ </td>
+ </tr>
+ </tal:block>
+ <tr><td class="spacer"></td></tr>
+ <tr>
+ <td colspan="2" class="controls">
+ <input type="submit" value="Refresh"
+ i18n:attributes="value refresh-button" />
+ <input type="submit" name="UPDATE_SUBMIT" value="Change"
+ i18n:attributes="value submit-button"/>
+ </td>
+ </tr>
+ </table>
+
+ </form>
+
+</body>
+</html>
Added: zmi.core/trunk/src/zmi/core/preference/index.pt
===================================================================
--- zmi.core/trunk/src/zmi/core/preference/index.pt (rev 0)
+++ zmi.core/trunk/src/zmi/core/preference/index.pt 2009-11-21 07:52:43 UTC (rev 105937)
@@ -0,0 +1,26 @@
+<html metal:use-macro="context/@@preferences_macros/pref_view">
+
+<div metal:fill-slot="body">
+
+ <form action="." tal:attributes="action request/URL" method="post"
+ enctype="multipart/form-data">
+
+ <div metal:use-macro="context/@@preferences_macros/edit_pref_group" />
+
+ <table class="prefs" cellspacing="0" cellpadding="0">
+ <tr><td class="spacer"></td></tr>
+ <tr>
+ <td colspan="2" class="controls">
+ <input type="submit" value="Refresh"
+ i18n:attributes="value refresh-button" />
+ <input type="submit" name="UPDATE_SUBMIT" value="Change"
+ i18n:attributes="value submit-button"/>
+ </td>
+ </tr>
+ </table>
+
+ </form>
+
+</div>
+
+</html>
Added: zmi.core/trunk/src/zmi/core/preference/macros.pt
===================================================================
--- zmi.core/trunk/src/zmi/core/preference/macros.pt (rev 0)
+++ zmi.core/trunk/src/zmi/core/preference/macros.pt 2009-11-21 07:52:43 UTC (rev 105937)
@@ -0,0 +1,153 @@
+<metal:block define-macro="tree">
+
+<table cellspacing="0" cellpadding="0"
+ tal:define="root context/@@tree;
+ result root/getFlatDicts;
+ nodeDictList python:result[0];
+ maxDepth python:result[1]">
+
+<tr>
+ <td class="list-item"
+ tal:attributes="colspan python:maxDepth+2">
+ Preferences
+ </td>
+</tr>
+
+<tr tal:repeat="nodeInfo nodeDictList">
+<tal:block tal:define="node nodeInfo/node">
+
+ <td style="width:16px" tal:repeat="state nodeInfo/row-state">
+ <img tal:attributes="src context/++resource++tree_images/vline.png"
+ tal:condition="state" alt="|" border="0" />
+ </td>
+
+ <td style="width:16px">
+ <a href=""
+ tal:attributes="href string:?tree-state=${nodeInfo/tree-state}"
+ tal:condition="node/hasChildren">
+ <tal:block condition="not:nodeInfo/last-level-node">
+ <img tal:attributes="src context/++resource++tree_images/plus_vline.png"
+ tal:condition="not:node/expanded" alt="+" border="0" />
+ <img tal:attributes="src context/++resource++tree_images/minus_vline.png"
+ tal:condition="node/expanded" alt="-" border="0" />
+ </tal:block>
+ <tal:block condition="nodeInfo/last-level-node">
+ <img tal:attributes="src context/++resource++tree_images/plus.png"
+ tal:condition="not:node/expanded" alt="+" border="0" />
+ <img tal:attributes="src context/++resource++tree_images/minus.png"
+ tal:condition="node/expanded" alt="-" border="0" />
+ </tal:block>
+ </a>
+ <tal:block condition="not:node/hasChildren">
+ <img tal:attributes="src context/++resource++tree_images/tline.png"
+ tal:condition="not:nodeInfo/last-level-node" alt="" border="0" />
+ <img tal:attributes="src context/++resource++tree_images/lline.png"
+ tal:condition="nodeInfo/last-level-node" alt="" border="0" />
+ </tal:block>
+ </td>
+
+ <td class="list-item"
+ tal:attributes="colspan python:maxDepth-len(nodeInfo['row-state'])+1">
+ <a href=""
+ tal:attributes="href
+ string:${node/context/@@absolute_url}/@@index.html"
+ tal:content="node/context/zope:name">
+ node/id
+ </a>
+ </td>
+
+</tal:block>
+</tr>
+
+</table>
+
+</metal:block>
+
+
+<metal:block define-macro="pref_view">
+
+<html metal:use-macro="context/@@standard_macros/view">
+<body>
+
+<div id="navigators" metal:fill-slot="navigators">
+ <div class="box">
+ <h4>Preferences</h4>
+ <div class="body">
+ <metal:block use-macro="context/@@preferences_macros/tree" />
+ </div>
+ </div>
+</div>
+
+<div metal:fill-slot="tabs">
+ <h1 tal:content="context/__title__">User Preferences</h1>
+</div>
+
+<div metal:fill-slot="body">
+
+ <div metal:define-slot="body">
+ <p>Body here</p>
+ </div>
+
+</div>
+
+</body>
+
+</html>
+</metal:block>
+
+
+<metal:block define-macro="edit_pref_group">
+
+ <div tal:content="structure view/getIntroduction">
+ Category Description goes here.
+ </div>
+ <br/>
+
+ <p tal:define="status view/update"
+ tal:condition="status"
+ tal:content="status" />
+
+ <p tal:condition="view/errors" i18n:translate="">
+ There are <strong tal:content="python:len(view.errors)"
+ i18n:name="num_errors">6</strong> input errors.
+ </p>
+
+ <table class="listing" width="90%" cellspacing="0" cellpadding="0"
+ tal:condition="view/widgets">
+
+ <thead>
+ <tr>
+ <th i18n:translate="">Description</th>
+ <th i18n:translate="">Value</th>
+ </tr>
+ </thead>
+
+ <tal:block repeat="widget view/widgets" >
+ <tr class=""
+ tal:define="oddrow repeat/widget/odd;
+ firstrow repeat/widget/start"
+ tal:attributes="class python:oddrow and 'even' or 'odd'">
+ <td class="description">
+ <b tal:content="widget/label">Option</b>
+ <div class="indent small">
+ <div tal:content="widget/hint">
+ Explanation
+ </div>
+ <div class="error" tal:define="error widget/error"
+ tal:condition="error" tal:content="structure error">
+ The Error
+ </div>
+ </div>
+ </td>
+ <td class="input" tal:content="structure widget">
+ <input type="text" style="width:100%"/>
+ </td>
+ </tr>
+ </tal:block>
+ </table>
+
+ <div tal:repeat="subgroup context/values">
+ <tal:block replace="structure subgroup/@@editAsSubGroup" />
+ </div>
+
+</metal:block>
Added: zmi.core/trunk/src/zmi/core/preference/menu.pt
===================================================================
--- zmi.core/trunk/src/zmi/core/preference/menu.pt (rev 0)
+++ zmi.core/trunk/src/zmi/core/preference/menu.pt 2009-11-21 07:52:43 UTC (rev 105937)
@@ -0,0 +1,20 @@
+<html metal:use-macro="views/apidoc_macros/menu"
+ i18n:domain="zope">
+<body>
+
+ <div class="menu" metal:fill-slot="menu-title" i18n:translate="">
+ Preferences
+ </div>
+
+ <div metal:fill-slot="menu" class="small">
+ <ul>
+ <li tal:repeat="group context/values">
+ <a href="" target="main"
+ tal:attributes="href string:./${group/name}/edit.html"
+ tal:content="group/title" />
+ </li>
+ </ul>
+ </div>
+
+</body>
+</html>
Added: zmi.core/trunk/src/zmi/core/preference/subgroup.pt
===================================================================
--- zmi.core/trunk/src/zmi/core/preference/subgroup.pt (rev 0)
+++ zmi.core/trunk/src/zmi/core/preference/subgroup.pt 2009-11-21 07:52:43 UTC (rev 105937)
@@ -0,0 +1,6 @@
+<fieldset>
+ <legend tal:content="context/__title__">Title</legend>
+
+ <div metal:use-macro="context/@@preferences_macros/edit_pref_group" />
+
+</fieldset>
\ No newline at end of file
More information about the checkins
mailing list