Author: jmorliaguet
Date: Sun Nov 27 23:03:03 2005
New Revision: 1946

Added:
   cpsskins/branches/jmo-perspectives/setup/configure.zcml   (contents, props 
changed)
Modified:
   cpsskins/branches/jmo-perspectives/browser/editing/configure.zcml
   cpsskins/branches/jmo-perspectives/browser/editing/edit_menu.pt
   cpsskins/branches/jmo-perspectives/browser/editing/edit_settings.pt
   cpsskins/branches/jmo-perspectives/browser/editing/editing.py
   cpsskins/branches/jmo-perspectives/browser/editing/settings.py
   cpsskins/branches/jmo-perspectives/configure.zcml
   
cpsskins/branches/jmo-perspectives/engines/default/filters/style/style_editor.pt
   cpsskins/branches/jmo-perspectives/setup/settings.py
Log:

- styles can be converted to settings

- moved some page template logic to views



Modified: cpsskins/branches/jmo-perspectives/browser/editing/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/configure.zcml   
(original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/configure.zcml   Sun Nov 
27 23:03:03 2005
@@ -41,6 +41,14 @@
       template="edit_settings.pt"
   />
 
+  <view
+      name="editpanel"
+      layer="cpsskins"
+      for="cpsskins.elements.interfaces.IElement"
+      permission="zope.ManageContent"
+      class=".editing.EditPanel"
+  />
+
   <pages
       for="cpsskins.elements.interfaces.IElement"
       layer="cpsskins"
@@ -80,6 +88,11 @@
           attribute="createSetting"
       />
 
+      <page
+          name="useSettingAsFormat"
+          attribute="useSettingAsFormat"
+      />
+
   </pages>
 
   <include package=".icons" />

Modified: cpsskins/branches/jmo-perspectives/browser/editing/edit_menu.pt
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/edit_menu.pt     
(original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/edit_menu.pt     Sun Nov 
27 23:03:03 2005
@@ -5,14 +5,12 @@
                 negociation nocall:context/@@negociation;
                 perspective negociation/getPerspective;
                 format_name request/form/format|string:;
-                effective_theme negociation/getTheme;
                 displayable context/displayable:this;
                 display python: displayable.getEffectiveDisplay(perspective);
                 formattable display/formattable:this|nothing;
                 here_url context/@@absolute_url;
                 edited_url formattable/?format_name/@@absolute_url|here_url;
-                edit_url string:${edited_url}/@@edit.html;
-                main_url request/form/main_url|edit_url"
+                main_url context/@@editpanel/getMainUrl"
     tal:attributes="onload python: main_url and
                    'parent.main.location.href = \'%s\'' % main_url
                     or 'parent.main.location.reload()'">
@@ -59,6 +57,8 @@
                          class info/selected"
          tal:content="info/title"
          i18n:translate="" />
+      <a tal:condition="format_name"
+         tal:attributes="href 
string:@@edit-menu.html?action=@@edit-settings.html&format=$format_name">Settings</a>
     </div>
 
   </body>

Modified: cpsskins/branches/jmo-perspectives/browser/editing/edit_settings.pt
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/edit_settings.pt 
(original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/edit_settings.pt Sun Nov 
27 23:03:03 2005
@@ -1,7 +1,9 @@
 <html metal:use-macro="context/@@popup_macros/page">
   <body metal:fill-slot="body" i18n:domain="cpsskins">
-    <div class="editArea">
-      <h1>Create setting</h1>
+    <div class="editArea"
+      tal:define="id request/form/id|nothing">
+      <h1>Settings</h1>
+      <h2>Create setting</h2>
 
       <div class="main">
         <form enctype="multipart/form-data" method="post"
@@ -21,6 +23,19 @@
         </form>
       </div>
 
+      <h2>Use setting</h2>
+
+      <!-- For testing -->
+      <ul tal:define="setting_info context/@@getSettingInfo">
+        <li tal:repeat="info setting_info/IStyle">
+          <tal:block define="name info/name">
+            <a href=""
+               tal:attributes="href string:./@@useSettingAsFormat?name=$name"
+               tal:content="info/name" />
+          </tal:block>
+        </li>
+      </ul>
+
     </div>
   </body>
 </html>

Modified: cpsskins/branches/jmo-perspectives/browser/editing/editing.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/editing.py       
(original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/editing.py       Sun Nov 
27 23:03:03 2005
@@ -20,11 +20,12 @@
 from zope.app.location.traversing import LocationPhysicallyLocatable
 from zope.app.publisher.browser import BrowserView
 from zope.app.traversing.api import getParent
-from zope.app.zapi import queryMultiAdapter
+from zope.app.zapi import queryMultiAdapter, getMultiAdapter
 from zope.component import adapts
 from zope.interface import implements, Interface
 
-from cpsskins.elements.interfaces import IElement
+from cpsskins.elements.interfaces import IElement, IDisplayable, IFormattable
+from cpsskins.browser.negociation.interfaces import INegociation
 
 class IEditing(Interface):
 
@@ -69,3 +70,31 @@
             icon_url = icon.url()
         return icon_url
 
+class EditPanel(BrowserView):
+
+    def getMainUrl(self):
+        context = self.context
+        request = self.request
+
+        form = request.form
+        if 'main_url' in form:
+            return form['main_url']
+
+        negociation = getMultiAdapter((context, request),
+                                      INegociation, 'negociation')
+        perspective = negociation.getPerspective()
+
+        main = context
+
+        if 'format' in form:
+            format_name = form['format']
+            display = IDisplayable(context).getEffectiveDisplay(perspective)
+            format = IFormattable(display).getFormat(format_name)
+            if format is not None:
+                main = format
+
+        base_url = getMultiAdapter((main, request),
+                                    name='absolute_url')() + '/'
+
+        main_url = base_url + form.get('action', '@@edit.html')
+        return main_url

Modified: cpsskins/branches/jmo-perspectives/browser/editing/settings.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/settings.py      
(original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/settings.py      Sun Nov 
27 23:03:03 2005
@@ -19,16 +19,24 @@
 
 from zope.app.location.pickling import locationCopy
 from zope.app.publisher.browser import BrowserView
+from zope.component import queryUtility, getUtility
 from zope.interface import implements, Interface
 from zope.security.proxy import removeSecurityProxy
 
-from cpsskins.setup.interfaces import IResourceManager
+from cpsskins import configuration
+from cpsskins.setup.interfaces import IResourceManager, ISetting
+from cpsskins.relations.relations import DyadicRelation
+from cpsskins.relations.interfaces import IRelationTool
+from cpsskins.ontology import hasFormat
 
 class ISettingsView(Interface):
 
     def createSetting(title):
         """Create a setting from an object considered as a resource."""
 
+    def useSettingAsFormat(name):
+        """Replace an existing format with a setting."""
+
 class SettingsView(BrowserView):
 
     implements(ISettingsView)
@@ -39,3 +47,34 @@
         resources.register(title=title, resource=resource, 
context=self.context)
         target = self.request.get('HTTP_REFERER', '.')
         self.request.response.redirect(target)
+
+    def useSettingAsFormat(self, name=u''):
+        if not name:
+            raise KeyError("Must specify a setting's name.")
+
+        context = self.context
+        setting = queryUtility(ISetting, name)
+        if setting is None:
+            raise KeyError("No such setting.")
+
+        reltool = IRelationTool(context)
+        displays = reltool.getFirsts(second=context, predicate=hasFormat)
+        if len(displays) > 1:
+            raise KeyError("The format is used by several displays.")
+        display = displays[0]
+
+        # create a display -- setting relation
+        predicate = getUtility(configuration.IFormat,
+                               context.formatname).predicate
+        relation = DyadicRelation(first=display, second=setting,
+                                  predicate=predicate)
+        reltool.add(relation)
+
+        # remove existing display -- format relation
+        old_rel = reltool.search(first=display, second=context,
+                                 predicate=hasFormat)
+        reltool.remove(old_rel)
+
+        target = self.request.get('HTTP_REFERER', '.')
+        self.request.response.redirect(target)
+

Modified: cpsskins/branches/jmo-perspectives/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/configure.zcml   (original)
+++ cpsskins/branches/jmo-perspectives/configure.zcml   Sun Nov 27 23:03:03 2005
@@ -94,4 +94,6 @@
 
   <include package=".profiles" />
 
+  <include package=".setup" />
+
 </configure>

Modified: 
cpsskins/branches/jmo-perspectives/engines/default/filters/style/style_editor.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/engines/default/filters/style/style_editor.pt
    (original)
+++ 
cpsskins/branches/jmo-perspectives/engines/default/filters/style/style_editor.pt
    Sun Nov 27 23:03:03 2005
@@ -26,11 +26,6 @@
                widget_id widget/id">
 
     <div class="editArea">
-      <!-- TODO: move to a macro -->
-      <div class="actions">
-        <a href="@@edit-settings.html">Settings</a>
-      </div>
-
       <h1>Style editor</h1>
 
       <p i18n:translate=""

Added: cpsskins/branches/jmo-perspectives/setup/configure.zcml
==============================================================================
--- (empty file)
+++ cpsskins/branches/jmo-perspectives/setup/configure.zcml     Sun Nov 27 
23:03:03 2005
@@ -0,0 +1,15 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope";
+    xmlns:i18n="http://namespaces.zope.org/i18n";
+    i18n_domain="cpsskins"
+    >
+
+  <!-- this adapter makes settings relatable -->
+
+  <adapter
+      for=".interfaces.ISetting"
+      factory=".settings.Relatable"
+      provides="cpsskins.relations.interfaces.IRelatable"
+  />
+
+</configure>

Modified: cpsskins/branches/jmo-perspectives/setup/settings.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/setup/settings.py        (original)
+++ cpsskins/branches/jmo-perspectives/setup/settings.py        Sun Nov 27 
23:03:03 2005
@@ -39,3 +39,13 @@
     def getResource(self):
         return self.context.resource
 
+class Relatable(object):
+    """This adapter makes settings relatable.
+    """
+    def __init__(self, context):
+        self.context = context
+
+    def __str__(self):
+        return str(self.context.resource)
+
+
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to