Florent Aide schrieb:
> this means a maintenance release for 1.0.4 :-)
Yes, but please wait a bit. While I am at it, and since I'm now using
PaginateGrid in one of my projects, I want fix some more problems with
paginate. For instance, I don't understand why the current ordering is
passed in the form of a Python dict. This is visible in the URL and not
only looks very ugly, but brings no advantage, since it needs to be
parsed in a cumbersome way anyway (eval would be sercurity problem). I
would use a much simpler format for storing the current ordering.
There are some other issues with sorting.
For example, take the following simple controller for displaying the
list of groups, with corresponding permissions and number of memers.
###############################################################
# groups.kid template contains <div py:replace="grid(groups)"/>
@expose(template=".templates.groups")
@paginate('groups', default_order='group_name')
def groups(self):
from model import Group
from turbogears.widgets import PaginateDataGrid as G
C = G.Column
sortable = dict(sortable=True)
members = lambda group: len(group.users)
grid = G(fields=[
C('group_name', 'group_name', 'Group Name', sortable),
C('silly_name', 'display_name', 'Description', sortable),
C('permissions', 'permissions', 'Permissions', sortable),
C('users', members, 'Members', sortable)])
return dict(grid=grid, groups=Group.query)
###############################################################
While column 1 can be sorted properly, the other 3 have problems:
2) The second column cannot be sorted, since paginate tries to get the
column 'silly_name' which does not exist. 'silly_name' is only the
internal name of that PaginateDataGrid.Column, it must not have anything
to do with the real query, for instance in the case where you use a
tuple for specifying the column, when it is created automatically.
It would be better if paginate would use the getter instead of name,
since that is the real database column name.
This could be solved by replacing col.name in paginate_datagrid.kid with
the name of the database column. Currently it can only be retrieved with
the somewhat complicated expression col.getter.__dict__.get('name').
3) The third column cannot be sorted (gives an error) because
'permissions' is not a real database column, but only a ORM property.
4) The fourth column cannot be sorted because it is not even a ORM
property, but based on a custom getter function.
Problems 3 and 4 could be solved if paginate would sort internally
(using Python's sort) if there is no corresponding database column.
Shall I add such support to paginate? Or am I missing something?
(One problem here is that this would not work with ordering like [d, c]
where d is a database column and c a custom getter. We could only do [d]
in this case. [c, d] would work, however, since Python sort is stable,
so it retains the subordinate ordering by d. But I think we can live
with this limitation.)
Yet another problem is that sometimes I want to sort case insensitive or
have a different "nulls first/last" behavior. Should paginate provide
some support for this? E.g. "~name" means "sort name case insensitive",
or "?name" means "nulls first", just like "-name" already means "sort
name descending"?
-- Christoph
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" 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-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---