Mercurial > p > roundup > code
changeset 3696:790363e96852
Sorting/grouping by multiple properties.
- Implement sorting/grouping by multiple properties for the web
interface. I'm now using @sort0/@sortdir0,@sort1/@sortdir1,... and
@group0/@groupdir0,... when generating URLs from a search template.
These are converted to a list internally. When saving URLs (e.g. when
storing queries) I'm using @sort=prop1,prop2,... and @group=... with
optional '-' prepended to individual props.
This means saved URLs are backward compatible with existing trackers
(and yes, this was a design goal).
I need the clumsy version with @sort0,@sort1 etc, because I'm
currently using several selectors and checkboxes (as the classic
template does, too). I don't think there is a way around that in HTML?
- Updated (hopefully all) documentation to reflect the new URL format
and the consequences in the web-interface.
- I've set the number of sort/group properties in the classic template
to two -- this can easily be reverted by changing n_sort to 1.
Richard, would you look over these changes? I've set a tag before and
(will set) after commit, so that it would be easy to merge out.
Don't be too scared about the size of the change, most is documentation,
the guts are in cgi/templating.py and small changes in the classic
template.
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Wed, 30 Aug 2006 20:28:26 +0000 |
| parents | 01ea89743311 |
| children | af6eeba3a3f3 |
| files | CHANGES.txt doc/customizing.txt doc/design.txt doc/upgrading.txt doc/user_guide.txt roundup/cgi/templating.py templates/classic/html/home.html templates/classic/html/issue.index.html |
| diffstat | 8 files changed, 197 insertions(+), 103 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Wed Aug 30 09:35:31 2006 +0000 +++ b/CHANGES.txt Wed Aug 30 20:28:26 2006 +0000 @@ -17,7 +17,7 @@ - new "exporttables" command in roundup-admin (sf bug 1533791) - roundup-admin "export" may specify classes to exclude (sf bug 1533791) - sorting and grouping by multiple properties is now supported by the - backends + backends *and* the classic template. - sorting, grouping, and searching by transitive properties (e.g., messages.author.supervisor) is now supported in all backends - added filter_sql to SQL backends which takes an arbitrary SQL statement
--- a/doc/customizing.txt Wed Aug 30 09:35:31 2006 +0000 +++ b/doc/customizing.txt Wed Aug 30 20:28:26 2006 +0000 @@ -2,7 +2,7 @@ Customising Roundup =================== -:Version: $Revision: 1.205 $ +:Version: $Revision: 1.206 $ .. This document borrows from the ZopeBook section on ZPT. The original is at: http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx @@ -1865,7 +1865,8 @@ 1. by the current *request* filterspec/filter/sort/group args 2. by the "filterspec", "sort" and "group" keyword args. "filterspec" is ``{propname: value(s)}``. "sort" and - "group" are ``(dir, prop)`` where dir is '+', '-' or None + "group" are an optionally empty list ``[(dir, prop)]`` + where dir is '+', '-' or None and prop is a prop name or None. eg. ``issue.filter(filterspec={"priority": "1"}, @@ -2195,8 +2196,8 @@ columns dictionary of the columns to display in an index page show a convenience access to columns - request/show/colname will be true if the columns should be displayed, false otherwise -sort index sort column (direction, column name) -group index grouping property (direction, column name) +sort index sort columns [(direction, column name)] +group index grouping properties [(direction, column name)] filter properties to filter the index on filterspec values to filter the index on search_text text to perform a full-text search on for an index @@ -2432,7 +2433,7 @@ /issue?status=unread,in-progress,resolved& topic=security,ui& - @group=priority& + @group=priority,-status& @sort=-activity& @filters=status,topic& @columns=title,status,fixer @@ -2454,19 +2455,30 @@ The example specifies an index of "issue" items. Only items with a "status" of either "unread" or "in-progress" or "resolved" are displayed, and only items with "topic" values including both "security" -and "ui" are displayed. The items are grouped by priority, arranged in -ascending order; and within groups, sorted by activity, arranged in -descending order. The filter section shows filters for the "status" and -"topic" properties, and the table includes columns for the "title", -"status", and "fixer" properties. +and "ui" are displayed. The items are grouped by priority arranged in +ascending order and in descending order by status; and within +groups, sorted by activity, arranged in descending order. The filter +section shows filters for the "status" and "topic" properties, and the +table includes columns for the "title", "status", and "fixer" +properties. ============ ============================================================= Argument Description ============ ============================================================= @sort sort by prop name, optionally preceeded with '-' to give - descending or nothing for ascending sorting. + descending or nothing for ascending sorting. Several + properties can be specified delimited with comma. + Internally a search-page using several sort properties may + use @sort0, @sort1 etc. with option @sortdir0, @sortdir1 + etc. for the direction of sorting (a non-empty value of + sortdir0 specifies reverse order). @group group by prop name, optionally preceeded with '-' or to sort - in descending or nothing for ascending order. + in descending or nothing for ascending order. Several + properties can be specified delimited with comma. + Internally a search-page using several grouping properties may + use @group0, @group1 etc. with option @groupdir0, @groupdir1 + etc. for the direction of grouping (a non-empty value of + groupdir0 specifies reverse order). @columns selects the columns that should be displayed. Default is all. @filter indicates which properties are being used in filtering. @@ -3248,8 +3260,8 @@ </select> </td> <td><input type="checkbox" name=":columns" value="category"></td> - <td><input type="radio" name=":sort" value="category"></td> - <td><input type="radio" name=":group" value="category"></td> + <td><input type="radio" name=":sort0" value="category"></td> + <td><input type="radio" name=":group0" value="category"></td> </tr> Adding category to the default view
--- a/doc/design.txt Wed Aug 30 09:35:31 2006 +0000 +++ b/doc/design.txt Wed Aug 30 20:28:26 2006 +0000 @@ -1251,7 +1251,7 @@ /issue?status=unread,in-progress,resolved& topic=security,ui& - :group=priority& + :group=priority,-status& :sort=-activity& :filters=status,topic& :columns=title,status,fixer @@ -1275,11 +1275,11 @@ The example specifies an index of "issue" items. Only issues with a "status" of either "unread" or "in-progres" or "resolved" are displayed, and only issues with "topic" values including both "security" and "ui" -are displayed. The issues are grouped by priority, arranged in -ascending order; and within groups, sorted by activity, arranged in -descending order. The filter section shows filters for the "status" and -"topic" properties, and the table includes columns for the "title", -"status", and "fixer" properties. +are displayed. The items are grouped by priority arranged in ascending +order and in descending order by status; and within groups, sorted by +activity, arranged in descending order. The filter section shows +filters for the "status" and "topic" properties, and the table includes +columns for the "title", "status", and "fixer" properties. Associated with each issue class is a default layout specifier. The layout specifier in the above example is the default layout to be
--- a/doc/upgrading.txt Wed Aug 30 09:35:31 2006 +0000 +++ b/doc/upgrading.txt Wed Aug 30 20:28:26 2006 +0000 @@ -13,6 +13,37 @@ .. contents:: +Migrating from 1.1.2 to 1.X.X +============================= + +1.X.X Sorting and grouping by multiple properties +------------------------------------------------- + +Starting with this version, sorting and grouping by multiple properties +is possible. This means that request.sort and request.group are now +lists. This is reflected in several places: + + * ``renderWith`` now has list attributes for ``sort`` and ``group``, + where you previously wrote:: + + renderWith(... sort=('-', 'activity'), group=('+', 'priority') + + you write now:: + + renderWith(... sort=[('-', 'activity')], group=[('+', 'priority')] + + * In templates that permit to edit sorting/grouping, request.sort and + request.group are (possibly empty) lists. You can now sort and group + by multiple attributes. For an example, see the classic template. You + may want search for the variable ``n_sort`` which can be set to the + number of sort/group properties. + + * Templates that diplay new headlines for each group of items with + equal group properties can now use the modified ``batch.propchanged`` + method that can take several properties which are checked for + changes. See the example in the classic template which makes use of + ``batch.propchanged``. + Migrating from 1.1.0 to 1.1.1 =============================
--- a/doc/user_guide.txt Wed Aug 30 09:35:31 2006 +0000 +++ b/doc/user_guide.txt Wed Aug 30 20:28:26 2006 +0000 @@ -2,7 +2,7 @@ User Guide ========== -:Version: $Revision: 1.33 $ +:Version: $Revision: 1.34 $ .. contents:: @@ -338,9 +338,11 @@ Argument Description ============ ============================================================= @sort sort by prop name, optionally preceeded with '-' to give - descending or nothing for ascending sorting. + descending or nothing for ascending sorting. The sort + argument can have several props separated with comma. @group group by prop name, optionally preceeded with '-' or to sort - in descending or nothing for ascending order. + in descending or nothing for ascending order. The group + argument can have several props separated with comma. @columns selects the columns that should be displayed. Default is all. @filter indicates which properties are being used in filtering. @@ -356,7 +358,7 @@ /issue?status=unread,in-progress,resolved& topic=security,ui& - @group=priority& + @group=priority,-status& @sort=-activity& @filters=status,topic& @columns=title,status,fixer
--- a/roundup/cgi/templating.py Wed Aug 30 09:35:31 2006 +0000 +++ b/roundup/cgi/templating.py Wed Aug 30 20:28:26 2006 +0000 @@ -604,8 +604,7 @@ idlessprops.sort() return ['id'] + idlessprops - def filter(self, request=None, filterspec={}, sort=(None,None), - group=(None,None)): + def filter(self, request=None, filterspec={}, sort=[], group=[]): ''' Return a list of items from this class, filtered and sorted by the current requested filterspec/filter/sort/group args @@ -769,27 +768,40 @@ def __getitem__(self, item): ''' return an HTMLProperty instance + this now can handle transitive lookups where item is of the + form x.y.z ''' #print 'HTMLItem.getitem', (self, item) if item == 'id': return self._nodeid + items = item.split('.', 1) + has_rest = len(items) > 1 + # get the property - prop = self._props[item] + prop = self._props[items[0]] + + if has_rest and not isinstance(prop, (hyperdb.Link, hyperdb.Multilink)): + raise KeyError, item # get the value, handling missing values value = None if int(self._nodeid) > 0: - value = self._klass.get(self._nodeid, item, None) + value = self._klass.get(self._nodeid, items[0], None) if value is None: - if isinstance(self._props[item], hyperdb.Multilink): + if isinstance(prop, hyperdb.Multilink): value = [] # look up the correct HTMLProperty class + htmlprop = None for klass, htmlklass in propclasses: if isinstance(prop, klass): - return htmlklass(self._client, self._classname, - self._nodeid, prop, item, value, self._anonymous) + htmlprop = htmlklass(self._client, self._classname, + self._nodeid, prop, items[0], value, self._anonymous) + if htmlprop is not None: + if has_rest: + return htmlprop[items[1]] + return htmlprop raise KeyError, item @@ -2118,6 +2130,43 @@ args['@template'] = self.template return self.indexargs_url(url, args) + def _parse_sort(self, var, name): + ''' Parse sort/group options. Append to var + ''' + fields = [] + dirs = [] + for special in ':@': + idx = 0 + key = '%s%s%d'%(special, name, idx) + while key in self.form: + self.special_char = special + fields.append (self.form[key].value) + dirkey = '%s%sdir%d'%(special, name, idx) + if dirkey in self.form: + dirs.append(self.form[dirkey].value) + else: + dirs.append(None) + idx += 1 + key = '%s%s%d'%(special, name, idx) + # backward compatible (and query) URL format + key = special + name + dirkey = key + 'dir' + if key in self.form and not fields: + fields = handleListCGIValue(self.form[key]) + if dirkey in self.form: + dirs.append(self.form[dirkey].value) + else: + dirs.append(None) + if fields: + break + for f, d in map(None, fields, dirs): + if f.startswith('-'): + var.append(('-', f[1:])) + elif d: + var.append(('-', f)) + else: + var.append(('+', f)) + def _post_init(self): ''' Set attributes based on self.form ''' @@ -2130,31 +2179,11 @@ break self.show = support.TruthDict(self.columns) - # sorting - self.sort = (None, None) - for name in ':sort @sort'.split(): - if self.form.has_key(name): - self.special_char = name[0] - sort = self.form[name].value - if sort.startswith('-'): - self.sort = ('-', sort[1:]) - else: - self.sort = ('+', sort) - if self.form.has_key(self.special_char+'sortdir'): - self.sort = ('-', self.sort[1]) - - # grouping - self.group = (None, None) - for name in ':group @group'.split(): - if self.form.has_key(name): - self.special_char = name[0] - group = self.form[name].value - if group.startswith('-'): - self.group = ('-', group[1:]) - else: - self.group = ('+', group) - if self.form.has_key(self.special_char+'groupdir'): - self.group = ('-', self.group[1]) + # sorting and grouping + self.sort = [] + self.group = [] + self._parse_sort(self.sort, 'sort') + self._parse_sort(self.group, 'group') # filtering self.filter = [] @@ -2280,18 +2309,22 @@ s = self.input(type="hidden",name="%s",value="%s") if columns and self.columns: l.append(s%(sc+'columns', ','.join(self.columns))) - if sort and self.sort[1] is not None: - if self.sort[0] == '-': - val = '-'+self.sort[1] - else: - val = self.sort[1] - l.append(s%(sc+'sort', val)) - if group and self.group[1] is not None: - if self.group[0] == '-': - val = '-'+self.group[1] - else: - val = self.group[1] - l.append(s%(sc+'group', val)) + if sort: + val = [] + for dir, attr in self.sort: + if dir == '-': + val.append('-'+attr) + else: + val.append(attr) + l.append(s%(sc+'sort', ','.join (val))) + if group: + val = [] + for dir, attr in self.group: + if dir == '-': + val.append('-'+attr) + else: + val.append(attr) + l.append(s%(sc+'group', ','.join (val))) if filter and self.filter: l.append(s%(sc+'filter', ','.join(self.filter))) if self.classname and filterspec: @@ -2326,18 +2359,22 @@ # ok, now handle the specials we received in the request if self.columns and not specials.has_key('columns'): l.append(sc+'columns=%s'%(','.join(self.columns))) - if self.sort[1] is not None and not specials.has_key('sort'): - if self.sort[0] == '-': - val = '-'+self.sort[1] - else: - val = self.sort[1] - l.append(sc+'sort=%s'%val) - if self.group[1] is not None and not specials.has_key('group'): - if self.group[0] == '-': - val = '-'+self.group[1] - else: - val = self.group[1] - l.append(sc+'group=%s'%val) + if self.sort and not specials.has_key('sort'): + val = [] + for dir, attr in self.sort: + if dir == '-': + val.append('-'+attr) + else: + val.append(attr) + l.append(sc+'sort=%s'%(','.join(val))) + if self.group and not specials.has_key('group'): + val = [] + for dir, attr in self.group: + if dir == '-': + val.append('-'+attr) + else: + val.append(attr) + l.append(sc+'group=%s'%(','.join(val))) if self.filter and not specials.has_key('filter'): l.append(sc+'filter=%s'%(','.join(self.filter))) if self.search_text and not specials.has_key('search_text'): @@ -2469,16 +2506,18 @@ self.current_item = item return item - def propchanged(self, property): - ''' Detect if the property marked as being the group property - changed in the last iteration fetch + def propchanged(self, *properties): + ''' Detect if one of the properties marked as being a group + property changed in the last iteration fetch ''' # we poke directly at the _value here since MissingValue can screw # us up and cause Nones to compare strangely - if (self.last_item is None or - self.last_item[property]._value != + if self.last_item is None: + return 1 + for property in properties: + if (self.last_item[property]._value != self.current_item[property]._value): - return 1 + return 1 return 0 # override these 'cos we don't have access to acquisition
--- a/templates/classic/html/home.html Wed Aug 30 09:35:31 2006 +0000 +++ b/templates/classic/html/home.html Wed Aug 30 20:28:26 2006 +0000 @@ -5,6 +5,6 @@ whatever. It's a good idea to have the issues on the front page though --> <span tal:replace="structure python:db.issue.renderWith('index', - sort=('-', 'activity'), group=('+', 'priority'), filter=['status'], + sort=[('-', 'activity')], group=[('+', 'priority')], filter=['status'], columns=['id','activity','title','creator','assignedto', 'status'], filterspec={'status':['-1','1','2','3','4','5','6','7']})" />
--- a/templates/classic/html/issue.index.html Wed Aug 30 09:35:31 2006 +0000 +++ b/templates/classic/html/issue.index.html Wed Aug 30 20:28:26 2006 +0000 @@ -31,10 +31,12 @@ <th tal:condition="request/show/assignedto" i18n:translate="">Assigned To</th> </tr> <tal:block tal:repeat="i batch"> - <tr tal:define="group python:request.group[1]" - tal:condition="python:group and batch.propchanged(group)"> - <th tal:attributes="colspan python:len(request.columns)" - tal:content="python:str(i[group]) or '(no %s set)'%group" class="group"> + <tr tal:define="group python:[r[1] for r in request.group]" + tal:condition="python:group and batch.propchanged(*group)"> + <th tal:attributes="colspan python:len(request.columns)" class="group"> + <tal:block tal:repeat="g group"> + <tal:block tal:content="python:str(i[g]) or '(no %s set)'%g"/> + </tal:block> </th> </tr> @@ -100,41 +102,49 @@ <form method="GET" class="index-controls" tal:attributes="action request/classname"> - <table class="form"> - <tr tal:condition="batch"> - <th i18n:translate="">Sort on:</th> + <table class="form" tal:define="n_sort python:2"> + <tal:block tal:repeat="n python:range(n_sort)" tal:condition="batch"> + <tr tal:define="key python:len(request.sort)>n and request.sort[n]"> + <th> + <tal:block tal:condition="not:n" i18n:translate="">Sort on:</tal:block> + </th> <td> - <select name="@sort"> + <select tal:attributes="name python:'@sort%d'%n"> <option value="" i18n:translate="">- nothing -</option> <option tal:repeat="col context/properties" tal:attributes="value col/_name; - selected python:col._name == request.sort[1]" + selected python:key and col._name == key[1]" tal:content="col/_name" i18n:translate="">column</option> </select> </td> <th i18n:translate="">Descending:</th> <td><input type="checkbox" name="@sortdir" - tal:attributes="checked python:request.sort[0] == '-'"> + tal:attributes="checked python:key and key[0] == '-'"> </td> </tr> - <tr> - <th i18n:translate="">Group on:</th> + </tal:block> + <tal:block tal:repeat="n python:range(n_sort)" tal:condition="batch"> + <tr tal:define="key python:len(request.group)>n and request.group[n]"> + <th> + <tal:block tal:condition="not:n" i18n:translate="">Group on:</tal:block> + </th> <td> - <select name="@group"> + <select tal:attributes="name python:'@group%d'%n"> <option value="" i18n:translate="">- nothing -</option> <option tal:repeat="col context/properties" tal:attributes="value col/_name; - selected python:col._name == request.group[1]" + selected python:key and col._name == key[1]" tal:content="col/_name" i18n:translate="">column</option> </select> </td> <th i18n:translate="">Descending:</th> <td><input type="checkbox" name="@groupdir" - tal:attributes="checked python:request.group[0] == '-'"> + tal:attributes="checked python:key and key[0] == '-'"> </td> </tr> + </tal:block> <tr><td colspan="4"> <input type="submit" value="Redisplay" i18n:attributes="value"> <tal:block tal:replace="structure
