Author: jmorliaguet
Date: Sun Dec 11 22:53:47 2005
New Revision: 2017

Modified:
   cpsskins/branches/jmo-perspectives/browser/editing/use_setting.pt
   cpsskins/branches/jmo-perspectives/browser/editing/views.py
   cpsskins/branches/jmo-perspectives/elements/format.py
Log:

- code simplifications / fixes 



Modified: cpsskins/branches/jmo-perspectives/browser/editing/use_setting.pt
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/use_setting.pt   
(original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/use_setting.pt   Sun Dec 
11 22:53:47 2005
@@ -10,7 +10,7 @@
             tal:repeat="info setting_info/?format_type">
           <tal:block define="name info/name">
             <a href=""
-               tal:attributes="href 
string:./@@useSettingAsFormat?setting_name=$name&format_type=$format_type"
+               tal:attributes="href string:./@@useSettingAsFormat?name=$name"
                tal:content="info/name" />
           </tal:block>
         </li>

Modified: cpsskins/branches/jmo-perspectives/browser/editing/views.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/editing/views.py (original)
+++ cpsskins/branches/jmo-perspectives/browser/editing/views.py Sun Dec 11 
22:53:47 2005
@@ -25,9 +25,9 @@
 from zope.interface import implements, Interface
 from zope.security.proxy import removeSecurityProxy
 
-from cpsskins.elements.interfaces import IDisplayable, IFormattable
-from cpsskins.elements.interfaces import IType, IDisplay
 from cpsskins.browser.negociation.interfaces import INegociation
+from cpsskins.elements.interfaces import IDisplayable, IFormattable
+from cpsskins.elements.interfaces import IType, IDisplay, IFormat
 from cpsskins.relations.interfaces import IRelationTool
 from cpsskins.relations.relations import DyadicRelation
 from cpsskins.setup.interfaces import IResourceManager, IResource, ISetting
@@ -107,7 +107,7 @@
 
         # Edited element
         element_info = {
-            'title': IType(context).getContentType().__name__,
+            'title': IType(context).contenttype,
             'url': '@@edit-menu.html?main_url=@@edit.html',
             'selected': not format_name,
             'icon': '',
@@ -133,7 +133,7 @@
                     main = format
 
             formats_info.append({
-                'title': IType(f).getContentType().__name__,
+                'title': IType(f).contenttype,
                 'url': './@@edit-menu.html?format=%s' % name,
                 'selected': selected,
                 })
@@ -208,19 +208,19 @@
             raise KeyError("Must specify a setting's name.")
 
         if not IDisplay.providedBy(context):
-            raise ValueError("The context must be a display.")
+            raise TypeError("The context must be a display.")
 
         setting = queryUtility(ISetting, name)
         if setting is None:
             raise KeyError("No such setting: '%s'." % name)
 
-        # remove existing display -- format relation
-        reltool = IRelationTool(context)
-
         resource = IResource(setting).getResource()
-        format_type = queryType(resource, IContentType)
-        predicate = format_type.getTaggedValue('predicate')
+        if not IFormat.providedBy(resource):
+            raise TypeError("The resource must be a format.")
 
+        # remove existing display -- format relation
+        reltool = IRelationTool(context)
+        predicate = resource.predicate
         old_rel = reltool.search(first=context, predicate=predicate)
         reltool.remove(old_rel)
 

Modified: cpsskins/branches/jmo-perspectives/elements/format.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/format.py       (original)
+++ cpsskins/branches/jmo-perspectives/elements/format.py       Sun Dec 11 
22:53:47 2005
@@ -41,9 +41,6 @@
     def __init__(self, type=u''):
         self.type = type
 
-    def _getFormatName(self):
-        return IType(self).getContentType().getTaggedValue('name')
-
     def findDisplays(self):
         """Return the list of display elements associated to this
         format.
@@ -51,8 +48,16 @@
         reltool = IRelationTool(self)
         return reltool.getFirsts(second=self, predicate=hasFormat)
 
+    def _getPredicate(self):
+        return IType(self).getContentType().getTaggedValue('predicate')
+
+    def _getFormatName(self):
+        return IType(self).getContentType().getTaggedValue('name')
+
     formatname = property(_getFormatName)
 
+    predicate = property(_getPredicate)
+
 class Formattable(object):
     """This adapter makes elements formattable.
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to