Opened 14 years ago
Last modified 4 years ago
#10323 new enhancement
Enable sorting in TitleIndex macro
| Reported by: | Owned by: | ||
|---|---|---|---|
| Priority: | normal | Milestone: | next-major-releases | 
| Component: | wiki system | Version: | |
| Severity: | normal | Keywords: | Macro TitleIndex order desc bitesized | 
| Cc: | Branch: | ||
| Release Notes: | |||
| API Changes: | |||
| Internal Changes: | |||
Description
The goal is to be allowed to order the result of the macro TitleIndex in the same way that RepositoryIndex with the addition of the parameters order and desc.
Orderpossible values: [title|date]Descpossible values: [0|1], same repositoryindex.
For example:
[[TitleIndex(order=title, desc=1)]]
Attachments (7)
Change History (26)
follow-up: 2 comment:1 by , 14 years ago
| Keywords: | bitesized added | 
|---|---|
| Milestone: | 0.13 → next-major-0.1X | 
by , 13 years ago
| Attachment: | TitleIndex_reverse.patch added | 
|---|
comment:2 by , 13 years ago
I guess what I did is kind of related to this… I wanted to "reverse" the results of the TitleIndex so I added a "reverse" option to do this. I guess this is a very limited version of what this ticket is proposing.
Usage:
[[TitleIndex(reverse=True)]]
comment:3 by , 12 years ago
I used Benjamin's patch and it basically works, but subgroups will be in wrong order if grouping is enabled. I was able to get my intended ordering to work by adding some additional sort() changes similar to Benjamin's.
by , 10 years ago
| Attachment: | #10323_new_enhancement_Enable_sorting_in_TitleIndex_macro_added_two_parameters.patch added | 
|---|
added two parameters order(title|date) and desc(0|1) to the TitleIndex macro. Used sql query to get date information.
comment:4 by , 10 years ago
| Milestone: | next-major-releases → 1.2 | 
|---|---|
| Owner: | set to | 
| Status: | new → assigned | 
comment:5 by , 10 years ago
The patch seems title sorts by case-insensitive and that is incompatible behavior. We should sort by case-sensitive since WikiPageName is case-sensitive.
by , 10 years ago
| Attachment: | #10323_new_enhancement_Enable_sorting_in_TitleIndex_macro_added_two_parameters_2.patch added | 
|---|
Thanks, I removed the case insensitivity for title sorting
comment:6 by , 10 years ago
Thanks for the patch!
The _description string should be updated to mention these new parameters.
Should WikiSystem.get_pages() maybe query and cache the time as well? But then the cache would get invalidated much more often.
by , 10 years ago
| Attachment: | #10323_new_enhancement_Enable_sorting_in_TitleIndex_macro_added_two_parameters_3.patch added | 
|---|
Thanks, I updated the description. About the WikiSystem I don't think it cache the time. Is there any other way to get time more efficiently
follow-up: 10 comment:7 by , 10 years ago
About the WikiSystem I don't think it cache the time. Is there any other way to get time more efficiently?
Another cached property could be added to the WikiSystem class, perhaps named pages_modtime: tags/trac-1.1.6/trac/wiki/api.py@:288-292#L254. Or should we aim to generalize and add a pages_metadata cached property that returns all of the page metadata (basically, everything except the text)?
In addition to caching the modtime, the aim is to keep SQL out of macros.py. Ideally the SQL would be in model.py, but for now it's fine to extend the existing functions in api.py.
An order_by parameter could then be added to WikiSystem.get_pages.
I'm probably overlooking something, but for what case is p a tuple in index_order?
Unit tests can be added in tags/trac-1.1.6/trac/wiki/tests/macros.py.
Lines need to wrap at 79 chars, per TracDev/CodingStyle.
comment:8 by , 10 years ago
For some reason I thought env.get_known_users(last_visit=True) (as proposed in comment:8:ticket:10736) was now allowed, and WikiSystem.get_pages(time=True) would be a logical continuation of that. (But now I see that has not happened.)
A general page metadata solution seems desirable.
An order_by parameter looks clean, but might not allow sorting format=group or format=hierarchy by time.
In those format cases p is a tuple (path_elements, page_name). See tree_group() and tree_hierarchy().
follow-up: 14 comment:9 by , 10 years ago
We could really use a smart "natural" sort mode where in wiki pages like wiki:Meeting/2015/Aug/10 etc. the Aug part is detected as a month abbreviation and sorted "correctly" between similar page names with Jul and Sep.
Sorry, if this is too specific / out-of-scope. A plugin would be fine, but macros don't offer any extension points.
follow-up: 11 comment:10 by , 10 years ago
Replying to Ryan J Ollos:
Or should we aim to generalize and add a
pages_metadatacached property that returns all of the page metadata (basically, everything except thetext)?
Maybe even the text or at least the extracted page title for #10523.
by , 10 years ago
| Attachment: | 10323_monthsort.patch added | 
|---|
comment:11 by , 10 years ago
by , 10 years ago
| Attachment: | #10323_new_enhancement_Enable_sorting_in_TitleIndex_macro_use_pages_metadata_and_testing.patch added | 
|---|
added pages_metadata to get date of wiki pages and added new test cases
comment:12 by , 10 years ago
Thanks for revising the patch. One suggestion - use a namedtuple in get_pages_metadata.
by , 10 years ago
| Attachment: | t10323-index_order.diff added | 
|---|
comment:13 by , 10 years ago
Quick review:
- The 
pages_metadatais incorrect. The latest version of each page should be cached. Also, we shouldn't use costlyDISTINCTwith all fields in the general cases. - Using both 
pages_metadataandWikiSystem.get_pages()is race. Theget_pages()usespagesdecorated@cached. I think we should use onlypages_metadata. - We should invalidate the cache of 
pages_metadatawhen a page is saved, renamed and deleted. Seedel WikiSystem(self.env).pagesintrac/wiki/model.pyandtrac/wiki/admin.py. UnboundLocalErrorwhenorder=xxxxxparameter is passed.- In the latest patch, uses of 
index_orderfortree_groupandtree_hierarchyare removed. Is that intentional? - I don't think that 
if type(p) is tupleinindex_orderis elegant. How about t10323-index_order.diff? - More tests. That tests don't cover the added features.
 
comment:14 by , 10 years ago
Replying to anonymous:
We could really use a smart "natural" sort mode where in wiki pages like
wiki:Meeting/2015/Aug/10etc. theAugpart is detected as a month abbreviation and sorted "correctly" between similar page names withJulandSep.Sorry, if this is too specific / out-of-scope. A plugin would be fine, but macros don't offer any extension points.
-1 but please create a new ticket for that if you want the feature.
That feature isn't useful for non-English users. Also, the smartsort parameter naming is not smart. At least, I don't know what kind of sort is used by smartsort.
comment:15 by , 10 years ago
| Milestone: | 1.2 → next-major-releases | 
|---|
Unscheduling until comment:13 issues are addressed.
comment:17 by , 10 years ago
| Owner: | removed | 
|---|---|
| Status: | assigned → new | 
comment:19 by , 4 years ago
If you implement this enhancement, it would be useful to be able to specify that Trac should attempt to sort numerically if a page name ends with a number. Currently page names like Atl1 and Alt10 come before Alt9.
Following the description, perhaps the Order parameter could have a third option titlenumeric or similar.



  
patch to reverse the TitleIndex list.