I don't know if I am following this correctly, but it looks like you
want ordered queries on these ranked tables. There are a few ways to
accomplish this, pick the one you like:
1) Strait-up manual ordering in SQLObject:
For any queries in sqlobject use the parameter: orderby="-user" for
descending rank or orderby="user" for ascending rank
2) Automatic ordering in SQLObject:
You can also specify a default ordering in your model definition using
the sqlmeta class. Here is what your sample table would look like, in
sqlobject, with descending ordering by default:
class user(SQLObject):
class sqlmeta:
defaultOrder="-ranking"
username = StringCol()
metadata = StringCol()
ranking = IntCol()
3) Roll-your-own decorator:
This is similar to what you are seeing in RoR. Although there is
nothing like this for ordering results, there is something similar in
the @paginate decorator. Here is something that (I think) will do what
you need:
from turbogears.decorator import weak_signature_decorator
def rank_results(var_name, order=None):
def entangle(func):
def decorated(func, *args, **kw):
output = func(*args, **kw)
if not isinstance(output, dict):
return output
try:
var_data = output[var_name]
except KeyError:
raise "Didn't get expected variable"
if order:
# check to make sure the specified order column exists
if order.startswith('-'):
checkcol = order[1:]
else:
checkcol = order
col = getattr(var_data.sourceClass.q, checkcol, None):
if col:
var_data = var_data.orderBy(order)
else:
raise "The order column (%s) doesn't exist" %
checkcol
output[var_name] = var_data
return output
return decorated
return weak_signature_decorator(entangle)
I have not tested this, but I think it should work. A lot of it was
lifted from the implementation of @paginate. Note that you will must
return an unused SQLObject result as the var_name. See
http://docs.turbogears.org/1.0/PaginateDecorator for a general idea of
how this works. I do not know if using it multiple times per controller
will work, but it should.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---