I'm currently 0-for-5 in my attempts to open a ticket on Trac, so I'm attaching
the updated patch, in case anyone wants to take a look.
- Joel
--
Joel Pearson
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---
Index: paginate.py
===================================================================
--- paginate.py (revision 3580)
+++ paginate.py (working copy)
@@ -31,6 +31,14 @@
log = logging.getLogger("turbogears.paginate")
+# lists of databases that lack support for OFFSET
+# this will need to be updated periodically as modules change
+_so_no_offset = 'mssql maxdb sybase'.split()
+_sa_no_offset = 'mssql maxdb access'.split()
+
+# this is a global that is set the first time paginate() is called
+_simulate_offset = None
+
def paginate(var_name, default_order='', default_reversed=False, limit=10,
allow_limit_override=False, max_pages=5, dynamic_limit=None):
'''
@@ -200,8 +208,31 @@
# we replace the var with the sliced one
endpoint = offset + limit_
log.debug("slicing data between %d and %d", offset, endpoint)
- output[var_name] = var_data[offset:endpoint]
+ global _simulate_offset
+ get = turbogears.config.get
+ if _simulate_offset is None:
+ _simulate_offset = get('paginate.simulate_offset', None)
+ if _simulate_offset is None:
+ _simulate_offset = False
+ so_db = get('sqlobject.dburi', 'NOMATCH:').split(':', 1)[0]
+ sa_db = get('sqlalchemy.dburi', 'NOMATCH:').split(':',
1)[0]
+ if so_db in _so_no_offset or sa_db in _sa_no_offset:
+ _simulate_offset = True
+ log.warning("simulating OFFSET, paginate may be slow")
+ log.warning("to turn off, set "
+ "paginate.simulate_offset=False")
+
+ if _simulate_offset:
+ var_data_iter = iter(var_data[:endpoint])
+ # skip over the number of records specified by offset
+ for i in range(offset):
+ var_data_iter.next()
+ # return the records that remain
+ output[var_name] = list(var_data_iter)
+ else:
+ output[var_name] = var_data[offset:endpoint]
+
return output
return decorated
return weak_signature_decorator(entangle)