alecf at osafoundation.org
Thu Feb 9 10:33:52 PST 2006
Ok, its an awkward term. But here's the concept: It would be nice if
there were a well-known way of sorting, grouping, and comparing
particular attributes, and choosing a particular well-known method if
there are multiple ways.
I have a need for this in the Table Summary View's sections. Basically,
I'd like to be able to "group" by date - make sections for dates based
on an arbitrary, domain-specific grouping that is consistent with some
particular sorting. I'd like to create groups for "Today", "Yesterday",
"This week" and so forth.
The way I determine the "division points" for a list of items by passing
in a "key" function to a function called get_divisions(). The key()
function returns the grouping key. At the moment, the table code looks
exactly like this:
indexName = self.blockItem.contents.indexName
self.sectionIndexes = get_divisions(self.blockItem.contents, key=lambda
x: getattr(x, indexName))
What I'd like to do is have a function specifically for the "date"
column, something like:
date = item.date
if (isToday(date)): return "Today"
if (isThisWeek(date)): return "ThisWeek"
And then my call to get_divisions looks like this:
self.sectionIndexes = get_divisions(self.blockItem.contents,
Further, I need to be able to indicate to a sorting algorithm which
values come "First" - for example in triageStatus, the 'proper' order is
'now', 'later', 'done' even though alphabetically they are in a
different order (it so happens they are in reverse, but thats not
important.. and yes we also need to translate these into the appropriate
language - thats a separate but related problem)
What I want is a dynamic way to look up these functions based on some
set of criteria such as "I need to make sections" or "I need to sort
Anyone have ideas here? I'd like to leverage some of the AttributeEditor
getSingleton() stuff, even if only in concept.
More information about the Dev