Commits

Anonymous committed 86464a0

Add code to work with other iterable containers, by Martin Kuzminski.

Comments (0)

Files changed (2)

    nothing with them, so it shouldn't allow them.
  - Import ``sqlalchemy.orm`` as well as ``sqlalchemy``. User Sybiam reports an
    error otherwise.
+ - Add code to work with other iterable containers, contributed by Marcin
+   Kuzminski.
 
 * webhelpers.pylonslib.flash:
 

webhelpers/paginate.py

     Auto-detect the kind of object and return a list/tuple
     to access items from the collection.
     """
-    # See if the collection is a sequence
+    # If the collection is a sequence we can use it directly
     if isinstance(obj, (list, tuple)):
         return obj
+
+    # If object is iterable we can use it directly
+    if hasattr(obj, "__iter__") and hasattr(obj, "__len__"):
+        return obj
+
     # Is SQLAlchemy 0.4 or better available? (0.3 is not supported - sorry)
     if sqlalchemy_available[:3] != '0.3':
         # Is the collection a query?
             or isinstance(obj, sqlalchemy.sql.expression.Select):
                 return _SQLAlchemySelect(obj, sqlalchemy_session)
 
-    raise TypeError("Sorry, your collection type is not supported by the paginate module. "
-            "You can either provide a list, a tuple, an SQLAlchemy 0.4 select object or an "
-            "SQLAlchemy 0.4 ORM-query object.")
+    raise TypeError("Sorry, your collection type is not supported by the "
+        "paginate module. You can provide a list, a tuple, a SQLAlchemy "
+        "select object or a SQLAlchemy ORM-query object.")
 
 class _SQLAlchemySelect(object):
     """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.