Re: Search template: How can I check "Sort Descending" by default?
"John P. Rouillard" <[email protected]>
| Newsgroups | gmane.comp.bug-tracking.roundup.user |
|---|---|
| Message-ID | <[email protected]> |
Hi David: In message <[email protected]>, "Hancock, David (DHANCOCK)" writes: >Apologies in advance for the simplicity of this question. Actually it wasn't that simple. I outline my initial fix and the one I finally came up with. >I’m trying to make a lightly customized issue.search.html template >default “Sort Descending” to checked. I’m afraid I don’t understand >the form abstractions enough to know what to change. The user >documentation didn’t see to cover this, and I didn’t find anything on >the wiki that was relevant. I’m sure there’s something easy that I’m >missing. I’d be grateful if someone could point me in the right >direction (code or documentation or both). Hmm, this had me stumped for a minute. While I was typing up one answer, I got another one. The best answer TL;DR is to change the tal:define near the top of issue.search.html for: sort_desc python:sort_on and sort_on[0] == '-'; to sort_desc python:(sort_on and sort_on[0] == '-') or (not sort_on); This was the second solution I came up with as I was unhappy with my initial solution. Here is how I figured out my various solutions. The tal for the checkbox you want to set is: <td><input type="checkbox" name="@sortdir" tal:attributes="checked sort_desc"> </td> This says set the checked attribute to the value of sort_desc. So if sort_desc is true, the box is checked. So I searched backwards to see where sort_desc was set. Searching backwards in issue.search.html I found: sort_desc python:sort_on and sort_on[0] == '-'; then searching backwards for sort_on I found the line sort_on python:request.sort and request.sort[0] or nothing; What this does is set the checked attribute if the request has a sort parameter and if there is a [0]th element. If there is no sort attribute set, then sort_on is set to nothing (which is boolean false). So I tried replacing "nothing" with "-". This sets sort_desc properly but I get a run time error in following line. Namely: sort_on python:(sort_on and sort_on[1]) or 'activity'; because sort_on is true, but there is no element 1. So I tried "-activity" in place of "-". This passed syntactically (I think because sort_on[0] and sort_on[1] when sort_on is a string is respectively the first/second character). But it didn't set the sort_by radio button for activity. My guess is sort_on was set to 'a' rather than the string 'activity'. So I tried setting sort_on to an array ['-', 'activity']. When I displayed the issue.search.html page without any arguments this value showed a checked "sort descending" with activity selected as the sort order. So my original solution was to change: sort_on python:request.sort and request.sort[0] or nothing; to sort_on python:request.sort and request.sort[0] or ['-', 'activity']; in issue.search.html. I tested it by editing saved searches that had "sort descending" set and "sort descending" unset. All tests displayed as expected. The array replicates the default settings where sort_on[1] is 'activity' to match the expected value for the sort field. However I had a feeling this should be easier. The initial solution is not DRY as I am repeating the 'activity' default sort order. A change to sort_desc python:sort_on and sort_on[0] == '-'; should work, but I couldn't initially come up with a suitable boolean expression. E.G.: sort_desc python:sort_on and (sort_on[0] == '-' or true) didn't work. Nor did a couple of other things I tried. Hence the sort_on "solution" above. However I finally realized that: sort_desc python:(sort_on and sort_on[0] == '-') or (not sort_on); would work. So it sets sort_desc to true only if sort_on is not set. This happens only when the query doesn't have a valid sort order. AFAICT this only happens when you are creating a new search. In all other cases, it preserves the sort order from the query. (Note that the issue.search.html page is used when editing any saved search. It is not just used when creating a search.) Hopefully my initial issues with coming up with the final solution will prove educational. Have a great week. -- -- rouilj John Rouillard =========================================================================== My employers don't acknowledge my existence much less my opinions. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Roundup-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/roundup-users