Fwd: r23837 - in ATContentTypes/branches/photoimagemerge-branch: adapters interface skins/ATContentTypes

"Martin Aspeli" <[email protected]> Tue, 23 May 2006 08:41:38 +0100
Newsgroups gmane.comp.web.zope.plone.archetypes.devel
Message-ID <[email protected]>
Bear with me here, but I seem to remember that this doesn't work as you  
may think:

photo = zapi.queryAdapter(obj,IScalable,default=None)

will return None if obj directly provides or its class implements the  
interface. I believe the better syntax (which also avoids the import of  
(soon-)deprecated zapi) is:

photo = IScalable(obj, None)

... which is also easier to read. :)

Martin

---- Forwarded Usenet-message ----
From: gawel <svn-changes-z4DKO/[email protected]>
Newsgroups: gmane.comp.web.zope.plone.collective.cvs
Subject: r23837 - in ATContentTypes/branches/photoimagemerge-branch:  
adapters interface skins/ATContentTypes
Date: Mon, 22 May 2006 22:36:23 +0100
URL: news://<E1FiI4d-0005Lq-GJ-L3KAqWRvItOmomBsMVY0kR2eb7JE58TQ@public.gmane.org>

Author: gawel
Date: Mon May 22 21:36:21 2006
New Revision: 23837

Modified:
    ATContentTypes/branches/photoimagemerge-branch/adapters/image.py
    ATContentTypes/branches/photoimagemerge-branch/interface/image.py
    ATContentTypes/branches/photoimagemerge-branch/skins/ATContentTypes/atphotoalbum.js
    ATContentTypes/branches/photoimagemerge-branch/skins/ATContentTypes/atslideshow.js
Log:
use zapi.queryAdapter instead of calling the interface herself
fix redirect views in js


Modified: ATContentTypes/branches/photoimagemerge-branch/adapters/image.py
==============================================================================
---  
ATContentTypes/branches/photoimagemerge-branch/adapters/image.py	(original)
+++ ATContentTypes/branches/photoimagemerge-branch/adapters/image.py	Mon  
May 22 21:36:21 2006
@@ -8,6 +8,7 @@

  from Products.ATContentTypes.content.folder import ATFolder

+from zope.app import zapi
  from zope.interface import implements
  from Products.Archetypes.public import Schema
  from Products.Archetypes.atapi import ReferenceField
@@ -125,20 +126,14 @@
          # create a js object for each batch item
          for i,p in enumerate(batch):
              obj = p.getObject()
-            if IPossibleScalable.providedBy(obj):
-                #photo = IScalable(obj).getScalable()
-                photo = obj
-                # GAWEL this one i dont understand!
-                # getScalable just return context!?
-            else:
+            photo = zapi.queryAdapter(obj,IScalable,default=None)
+            if not photo:
                  continue
- #               pass
- #               photo = obj
- #               continue
+
              # init BaseContent
              title = p.Title or p.getId
              url = p.getURL()
-            out.append(BaseContent % (url, p.getId,
+            out.append(BaseContent % (url + '/view', p.getId,
                                  title.replace("'","\\\'"),
                                  p.Description.replace("'","\\\'"),
                                  p.meta_type,
@@ -167,8 +162,22 @@
      implements(IScalable)

      field = 'image'
+
      def __init__(self,context):
          self.context = context
+        self.content_type = context.content_type
+
+    def getWidth(self,scale=None):
+        """
+        return scaled width
+        """
+        return self.context.getWidth(scale=scale)
+
+    def getHeight(self,scale=None):
+        """
+        return scaled height
+        """
+        return self.context.getHeight(scale=None)

      def getScalable(self):
          """
@@ -213,6 +222,7 @@
      meta_types = ['ATImage']

      def __init__(self,container):
+        self.content_type = ''
          context = None
          container = aq_inner(container)
          try:
@@ -228,4 +238,6 @@
                  if brains:
                      context = brains[0].getObject()
          self.context = context
+        if context:
+            self.content_type = getattr(context,'content_type','')


Modified: ATContentTypes/branches/photoimagemerge-branch/interface/image.py
==============================================================================
---  
ATContentTypes/branches/photoimagemerge-branch/interface/image.py	(original)
+++ ATContentTypes/branches/photoimagemerge-branch/interface/image.py	Mon  
May 22 21:36:21 2006
@@ -42,6 +42,16 @@
      """
      object with scalable image
      """
+
+    def getWidth(scale=None):
+        """
+        return scaled width
+        """
+
+    def getHeight(scale=None):
+        """
+        return scaled height
+        """

      def getScale(scale=None):
          """

Modified:  
ATContentTypes/branches/photoimagemerge-branch/skins/ATContentTypes/atphotoalbum.js
==============================================================================
---  
ATContentTypes/branches/photoimagemerge-branch/skins/ATContentTypes/atphotoalbum.js	(original)
+++ ATContentTypes/branches/photoimagemerge-branch/skins/ATContentTypes/atphotoalbum.js	Mon  
May 22 21:36:21 2006
@@ -26,7 +26,7 @@
      }
      newNode.id = photo.getId;

-    var linkNode =  
this.createNode('a',null,photo.Title,photo.getURL+'/view');
+    var linkNode = this.createNode('a',null,photo.Title,photo.getURL);
      var textNode = this.createNode('span','photoAlbumEntryWrapper')
      var imageNode =  
this.createNode('img',null,photo.Title,photo.getScaleUrl(this.getScale()));
      textNode.appendChild(imageNode);
@@ -80,7 +80,7 @@

      if (!W3CDOM) {
          /* redirect to the standard album view */
-        window.location = context.getURL + '/atphotoalbum_view';
+        window.location = context.getURL + '/atct_album_view';
          return;
      }


Modified:  
ATContentTypes/branches/photoimagemerge-branch/skins/ATContentTypes/atslideshow.js
==============================================================================
---  
ATContentTypes/branches/photoimagemerge-branch/skins/ATContentTypes/atslideshow.js	(original)
+++ ATContentTypes/branches/photoimagemerge-branch/skins/ATContentTypes/atslideshow.js	Mon  
May 22 21:36:21 2006
@@ -321,7 +321,7 @@

      if (!W3CDOM) {
          /* redirect to the standard album view */
-        window.location = context.getURL + '/atphotoalbum_view';
+        window.location = context.getURL + '/atct_album_view';
          return;
      }



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job  
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642



-- 
"You can just adapt yourself out of it..." // Archipelago sprint 26/04/2006



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642