r252448 - in Products.Doormat/trunk: Products/Doormat/browser Products/Doormat/content docs

"Philip Bauer" <svn-changes-z4DKO/[email protected]>
Newsgroups gmane.comp.web.zope.plone.collective.cvs
Message-ID <[email protected]>
Author: pbauer
Date: Sat Jun  8 09:59:12 2013
New Revision: 252448

Modified:
   Products.Doormat/trunk/Products/Doormat/browser/views.py
   Products.Doormat/trunk/Products/Doormat/content/DoormatCollection.py
   Products.Doormat/trunk/Products/Doormat/content/DoormatReference.py
   Products.Doormat/trunk/docs/HISTORY.txt
Log:
Make compatible with Dexterity and new collections

 also subclass from ATCTContent instead of BaseContent


Modified: Products.Doormat/trunk/Products/Doormat/browser/views.py
==============================================================================
--- Products.Doormat/trunk/Products/Doormat/browser/views.py	(original)
+++ Products.Doormat/trunk/Products/Doormat/browser/views.py	Sat Jun  8 09:59:12 2013
@@ -4,6 +4,26 @@
 from zope.component import getMultiAdapter
 from plone.app.layout.viewlets.common import ViewletBase
 
+import pkg_resources
+try:
+    pkg_resources.get_distribution('plone.app.collection')
+except pkg_resources.DistributionNotFound:
+    HAS_COLLECTIONS = False
+else:
+    HAS_COLLECTIONS = True
+    from plone.app.collection.interfaces import ICollection
+
+try:
+    pkg_resources.get_distribution('plone.app.contenttypes>=1.0b2')
+except pkg_resources.VersionConflict:
+    # older versions don't have the dx-based-collections
+    HAS_PAC = False
+except pkg_resources.DistributionNotFound:
+    HAS_PAC = False
+else:
+    HAS_PAC = True
+    from plone.app.contentypes.interfaces import ICollection as IDXCollection
+
 
 class DoormatView(BrowserView):
     """
@@ -69,11 +89,19 @@
                             continue
                         url = linked_item.absolute_url()
                     elif item.portal_type == "Link":
-                        # Link is an Archetypes link
-                        url = item.getRemoteUrl
+                        if item.meta_type.startswith('Dexterity'):
+                            # A Dexterity-link
+                            url = item.remoteUrl
+                        else:
+                            # Link is an Archetypes link
+                            url = item.getRemoteUrl
                         link_class = "external-link"
                     elif item.portal_type == "Document":
-                        text = item.getText()
+                        if item.meta_type.startswith('Dexterity'):
+                            # A Dexterity-link
+                            text = item.text.output
+                        else:
+                            text = item.getText()
                     elif item.portal_type == "DoormatCollection":
                         if item.getCollection().portal_type == "Topic":
                             results = self.getCollection(item)
@@ -106,6 +134,37 @@
                                 })
 
                             continue
+                        elif item.getCollection().portal_type == "Collection":
+                            results = self.getCollection(item)
+
+                            # Add links from collections
+                            for nitem in results:
+                                obj = nitem.getObject()
+
+                                if (item.showTime):
+                                    title = self.localizedTime(obj.modified())\
+                                        + ' - ' + obj.title
+                                else:
+                                    title = obj.title
+
+                                section_links.append({
+                                    'content': '',
+                                    'link_url': obj.absolute_url(),
+                                    'link_title': title,
+                                    'link_class': 'collection-item',
+                                    })
+
+                            # Add the read more link if it is specified
+                            if item.getShowMoreLink():
+                                section_links.append({
+                                    'content': '',
+                                    'link_url': item.getShowMoreLink(
+                                        ).absolute_url(),
+                                    'link_title': item.showMoreText,
+                                    'link_class': 'read-more'
+                                })
+
+                            continue
                         else:
                             url = ''
                             text = ("%s: This is not a collection, but a %s "
@@ -130,11 +189,15 @@
         return data
 
     def getCollection(self, item):
+        col = item.getCollection()
         if item.limit > 0:
-            results = item.getCollection().queryCatalog(
-                sort_limit=item.limit)[:item.limit]
+            if HAS_COLLECTIONS and ICollection.providedBy(col) or \
+                    HAS_PAC and IDXCollection.providedBy(col):
+                results = col.queryCatalog(b_size=item.limit)
+            else:
+                results = col.queryCatalog(sort_limit=item.limit)[:item.limit]
         else:
-            results = item.getCollection().queryCatalog()
+            results = col.getCollection().queryCatalog()
 
         return results
 

Modified: Products.Doormat/trunk/Products/Doormat/content/DoormatCollection.py
==============================================================================
--- Products.Doormat/trunk/Products/Doormat/content/DoormatCollection.py	(original)
+++ Products.Doormat/trunk/Products/Doormat/content/DoormatCollection.py	Sat Jun  8 09:59:12 2013
@@ -14,6 +14,7 @@
 
 from AccessControl import ClassSecurityInfo
 from Products.Archetypes.atapi import *
+from Products.ATContentTypes.content.base import ATCTContent
 from zope.interface import implements
 import interfaces
 
@@ -25,7 +26,6 @@
 from archetypes.referencebrowserwidget.widget import ReferenceBrowserWidget
 
 ##code-section module-header #fill in your manual code here
-from zope import schema
 
 ##/code-section module-header
 
@@ -38,7 +38,7 @@
             label_msgid='Doormat_label_collection',
             i18n_domain='Doormat',
         ),
-        allowed_types="('Topic')",
+        allowed_types="('Topic', 'Collection')",
         relationship="internally_references_to_collection",
     ),
     ReferenceField(
@@ -95,7 +95,7 @@
 ##code-section after-schema #fill in your manual code here
 ##/code-section after-schema
 
-class DoormatCollection(BaseContent, BrowserDefaultMixin):
+class DoormatCollection(ATCTContent, BrowserDefaultMixin):
     """
     """
     security = ClassSecurityInfo()
@@ -118,4 +118,3 @@
 
 ##code-section module-footer #fill in your manual code here
 ##/code-section module-footer
-

Modified: Products.Doormat/trunk/Products/Doormat/content/DoormatReference.py
==============================================================================
--- Products.Doormat/trunk/Products/Doormat/content/DoormatReference.py	(original)
+++ Products.Doormat/trunk/Products/Doormat/content/DoormatReference.py	Sat Jun  8 09:59:12 2013
@@ -14,6 +14,7 @@
 
 from AccessControl import ClassSecurityInfo
 from Products.Archetypes.atapi import *
+from Products.ATContentTypes.content.base import ATCTContent
 from zope.interface import implements
 import interfaces
 
@@ -51,7 +52,7 @@
 ##code-section after-schema #fill in your manual code here
 ##/code-section after-schema
 
-class DoormatReference(BaseContent, BrowserDefaultMixin):
+class DoormatReference(ATCTContent, BrowserDefaultMixin):
     """
     """
     security = ClassSecurityInfo()
@@ -74,4 +75,3 @@
 
 ##code-section module-footer #fill in your manual code here
 ##/code-section module-footer
-

Modified: Products.Doormat/trunk/docs/HISTORY.txt
==============================================================================
--- Products.Doormat/trunk/docs/HISTORY.txt	(original)
+++ Products.Doormat/trunk/docs/HISTORY.txt	Sat Jun  8 09:59:12 2013
@@ -4,6 +4,12 @@
 0.8 (unreleased)
 ----------------
 
+- Make compatible with Dexterity and new collections
+  [pbauer]
+
+- Subclass from ATCTContent instead of BaseContent
+  (taken from https://github.com/pymilya/Products.Doormat)
+
 - Search for doormats only in the navigation root.  This allows to
   have a different doormat (or no doormat) in parts of the site.
   [maurits]
@@ -13,10 +19,10 @@
 
 Merged collections branch.
 
-- Add "DoormatCollection" type, which takes links from a Collection. 
+- Add "DoormatCollection" type, which takes links from a Collection.
   Thanks to Alessandro Vermeulen's branch at https://github.com/spockz/Products.Doormat.
 
-- Don't subclass DoormatCollection from DoormatMixin. 
+- Don't subclass DoormatCollection from DoormatMixin.
   [khink]
 
 - Add labels and description for fields, add a pointer in the documentation.
@@ -49,16 +55,16 @@
 0.4 (2010-10-05)
 ----------------
 
-- Allow adding text as well as links. 
+- Allow adding text as well as links.
   http://plone.org/products/doormat/issues/6
   [renskers]
 
-- Re-added skins folders, as these will be generated by AGX. 
+- Re-added skins folders, as these will be generated by AGX.
   (Make them not empty.)
   http://plone.org/products/doormat/issues/4
   [khink]
 
-- Add class on 'doormat-container' div for number of columns. 
+- Add class on 'doormat-container' div for number of columns.
   Add CSS so columns are equal width.
   [khink]
 

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.