Christopher Kelly wrote:
> I'm build a web front end for a system where the model is defined by a
> server I communicate with via SOAP and soaplib. Most of the data I
> need to display are flat lists of objects returned by a remote
> procedure call. The paginate decorator is working well for this except
> that column sorting doesn't work.
>
> I fixed my problem by applying the following patch, essentially it
> uses the sort method build into list objects and promotes the check
> for non-select results objects to the first made (as I do have
> SQLAlchemy and SQLObject installed). Is this something you would be
> interested in incorporating, or is there a better way to achieve
> sorting simple lists?
>
> Index: paginate.py
> ===================================================================
> --- paginate.py (revision 3512)
> +++ paginate.py (working copy)
> @@ -125,7 +125,18 @@
> log.debug('ordering %s' % ordering)
>
> row_count = 0
> - if (SelectResults and isinstance(var_data,
> SelectResults)) or \
> + if isinstance(var_data, list) or (sqlalchemy and
> isinstance(
> + var_data,
> sqlalchemy.orm.attributes.InstrumentedList)):
> + row_count = len(var_data)
> + o = [(index, key, default_reverse) for (key, (index,
> + default_reverse)) in ordering.iteritems()]
> + o.sort( reverse = True )
> + for (index, key, default_reverse) in o:
> + log.debug("sorting by %s, reverse: %s" % (key,
> default_reverse))
> + var_data.sort( key = lambda item: getattr( item,
> key ),
> + reverse = default_reverse )
> +
> + elif (SelectResults and isinstance(var_data,
> SelectResults)) or \
> (SASelectResults and isinstance(var_data,
> SASelectResults)) or \
> (Query and isinstance(var_data, Query)):
> row_count = var_data.count()
> @@ -148,9 +159,6 @@
> else:
> var_data = var_data.order_by(order_cols)
>
> - elif isinstance(var_data, list) or (sqlalchemy and
> isinstance(
> - var_data,
> sqlalchemy.orm.attributes.InstrumentedList)):
> - row_count = len(var_data)
>
> else:
> raise StandardError(
>
>
Thanks for the patch! Could you please attach it to a new ticket at
trac.turbogears.org? It's much easier for commiters to evaluate it and
apply it from there.
Alberto
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---