I've been playing around with ZPatterns, and I must say it's very cool -
finally you can mix ZCatalog and SQL storage.  CatalogAwareness is slightly
different than regular Zope objects in that you have to find the ZCatalog in
the Rack's acquisition path, but that's about it.

The absolute_url function I define here should be moved to the RackMountable
class since it may be useful in other situations.

---------------------------------------------------------

from Products.ZCatalog.CatalogAwareness import CatalogAware
from Products.ZPatterns.Rack import _v_rack, RackMountable

class RMCatalogAwareMixIn(CatalogAware):
    """ 
    CatalogAwareness for RackMountables.
    You need to inherit from this class before RackMountable.

    Objects are NOT automatically indexed, because no rack has
    been defined when we're in __init__.
    """
    
    def absolute_url(self, relative=0):
        """ URL for catalog-awareness """
        return "%s/%s" % (self._v_rack.absolute_url(relative), self.id)
    
    def index_object(self):
        """A common method to allow Findables to index themselves."""
        if hasattr(self._v_rack, self.default_catalog):
            getattr(self._v_rack, self.default_catalog).catalog_object(self,
self.url())
            
    def unindex_object(self):
        """A common method to allow Findables to unindex themselves."""
        if hasattr(self._v_rack, self.default_catalog):
            try:
                getattr(self._v_rack,
self.default_catalog).uncatalog_object(self.url())
            except:
                pass
                
    def manage_delete(self, _v_rack=_v_rack):
        """ Uncatalog this object and then delete it """
        self.unindex_object()
        return RackMountable.manage_delete(self, _v_rack)

_______________________________________________
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to