#10120 closed enhancement (fixed)
Add a `format` parameter to the RecentChanges macro
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Milestone: | 1.0 |
Component: | wiki system | Version: | 0.13dev |
Severity: | normal | Keywords: | bitesized, macro |
Cc: | Branch: | ||
Release Notes: |
|
||
API Changes: | |||
Internal Changes: |
Description
Add a format parameter to the RecentChanges macro with the following allowed values:
- groupbydate (default) - the current display format
- list - list each page on a separate line, a bullet ed list, same as the current display but without the date shown.
For reference, two macros accept a format parameter: WikiMacros#TitleIndex-macro and WikiMacros#TicketQuery-macro.
A patch will be provided shortly.
Attachments (5)
Change History (28)
by , 14 years ago
Attachment: | macros.r10668.patch added |
---|
comment:1 by , 14 years ago
There is an extra whitespace in the help text that should be corrected before committing the patch. The current behavior is that any value for format
other than format=groupbydate
Here are the test cases I used:
{{{ [[RecentChanges]] }}} [[RecentChanges]] {{{ [[RecentChanges(,3)]] }}} [[RecentChanges(,3)]] {{{ [[RecentChanges(SandBox,3)]] }}} [[RecentChanges(SandBox,3)]] {{{ [[RecentChanges(SandBox)]] }}} [[RecentChanges(SandBox)]] {{{ [[RecentChanges(SandBox,format=list)]] }}} [[RecentChanges(SandBox,format=list)]] {{{ [[RecentChanges(format=list)]] }}} [[RecentChanges(format=list)]] {{{ [[RecentChanges(, 5, format=list)]] }}} [[RecentChanges(, 5, format=list)]] {{{ [[RecentChanges(SandBox, 5, format=list)]] }}} [[RecentChanges(SandBox, 5, format=list)]] {{{ [[RecentChanges(SandBox, 5, format=groupbydate)]] }}} [[RecentChanges(SandBox, 5, format=groupbydate)]] {{{ [[RecentChanges(SandBox, format=groupbydate)]] }}} [[RecentChanges(SandBox, format=groupbydate)]] {{{ [[RecentChanges(format=groupbydate)]] }}} [[RecentChanges(format=groupbydate)]] {{{ [[RecentChanges(format=groupbydate, , 3)]] }}} [[RecentChanges(format=groupbydate, , 3)]] {{{ [[RecentChanges(format=groupbydate, SandBox, 3)]] }}} [[RecentChanges(format=groupbydate, SandBox, 3)]]
comment:2 by , 14 years ago
Submitted my previous comment before finishing what I was writing …
The current behavior is that any value for format
other than format=groupbydate
results in the list
format. I was thinking this might be expanded on in the future to add a format=compact
option.
follow-up: 5 comment:3 by , 14 years ago
Nice proposal, thanks!
Two remarks:
- as this is 0.13 material, please use the
x if b else y
style instead ofb and x or y
(see #9536) - for
format=list
, I think it would be more appropriate to generate a single list; even if this will probably make the patch a bit longer, it more important to have a semantically correct output
comment:4 by , 14 years ago
Milestone: | → 0.13 |
---|
follow-up: 6 comment:5 by , 14 years ago
Replying to cboos:
Nice proposal, thanks!
Two remarks:
- as this is 0.13 material, please use the
x if b else y
style instead ofb and x or y
(see #9536)- for
format=list
, I think it would be more appropriate to generate a single list; even if this will probably make the patch a bit longer, it more important to have a semantically correct output
I've incorporated those changes. I'm not super happy with the list generation … perhaps someone will be more clever than I have been in coding this. However, it seems to work correctly at least.
by , 14 years ago
Attachment: | macros.r10671.patch added |
---|
follow-up: 7 comment:6 by , 14 years ago
Replying to anonymous:
I've incorporated those changes.
Nice, thanks!
I'm not super happy with the list generation …
For example you could add an extra transformation step to entries_per_date
and factor out the part:
tag.li(tag.a(page, href=formatter.href.wiki(name)), ' ', ... ... for date, entries in entries_per_date
into:
items_per_date = [(date, [tag.li(...) for ...]) for ... in entries_per_date]
and from that produce either the (<h3>, <ul>) sequence or a single <ul>.
by , 14 years ago
Attachment: | macros.r10672.patch added |
---|
comment:7 by , 14 years ago
Replying to cboos:
For example you could add an extra transformation step to
entries_per_date
and factor out the part: …
Thank you for the pointers! I attempted to incorporate those changes into the latest patch.
comment:8 by , 14 years ago
I've been looking closely at the syntax of the TicketQuery macro and am thinking about some ways that we can make the new arguments to this macro more like the format
and group
arguments of the TicketQuery macro, for consistency. I'll post some more comments about this shortly.
comment:10 by , 13 years ago
Milestone: | next-stable-1.0.x → next-dev-1.1.x |
---|
Last patch looks good, I suppose it was not applied because in comment:8 you were talking about follow-up changes. But that was quite some time ago, so I suppose we can consider the patch as is for the next dev release.
comment:11 by , 13 years ago
One of many things I've unfortunately lost track of.
If I remember correctly, I was thinking the notation would be more consistent with the TicketQuery macro if we added a group
option, rather than adding a format
option. The default for the group
option would be date
(or perhaps we want to use day
, to allow for grouping by week
, month
, etc. in the future). We could add a none
option for the grouping, and in the future also allow for grouping by author
, alphabetically, etc.
I'm not sure which way is the better way to go. But if anyone has suggestions, I can quickly rework the patch.
comment:12 by , 13 years ago
Yes, group=date|none
(where date is interpreted as day, as a first step) sounds better and leaves the door opened for more grouping possibilities, as you said.
comment:13 by , 12 years ago
New patch against r11098 of the trunk:
- option added is
group=date|none
. - added unit tests.
by , 12 years ago
Attachment: | t10120-r11098-2.patch added |
---|
Patch described in comment:13. Previous patch had some garbage in it.
comment:15 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I've taken the occasion of reviewing and testing the patch to do a few more clean-ups in macros.py.
Detailed steps in repos:cboos.git:ticket10120/t10120-r11098-2.patch-review, committed as a whole in r11100 (+ there's a hidden bonus in that changeset ;-) ).
comment:16 by , 12 years ago
Owner: | changed from | to
---|
comment:17 by , 12 years ago
Release Notes: | modified (diff) |
---|
comment:19 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
The unit test in [11100] fails here, but strangely only if functional tests are run. If they aren't, it passes. It's obviously locale-related, but I don't understand what's happening.
====================================================================== FAIL: Test RecentChanges, group option ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/joe/src/trac/trunk/trac/wiki/tests/formatter.py", line 213, in test % (msg, self.file, self.line, self.title, formatter.flavor)) AssertionError: ========== expected: ========== <p> </p><div><h3>07/13/12</h3><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> </p><div><h3>07/13/12</h3><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> </p><div><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> </p><div><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li></ul></div><p> </p><div><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> </p><div><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li></ul></div><p> </p> ========== actual: ========== <p> </p><div><h3>2012-07-13</h3><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> </p><div><h3>2012-07-13</h3><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> </p><div><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> </p><div><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li></ul></div><p> </p><div><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> </p><div><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li></ul></div><p> </p> ========== wiki: ========== u' [[RecentChanges()]] [[RecentChanges(group=date)]] [[RecentChanges(group=none)]] [[RecentChanges(,2,group=none)]] [[RecentChanges(Wiki,group=none)]] [[RecentChanges(Wiki,1,group=none)]] ' ========== diff: ========== --- expected +++ actual @@ -1,9 +1,9 @@ <p> -</p><div><h3>07/13/12</h3><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> +</p><div><h3>2012-07-13</h3><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> -</p><div><h3>07/13/12</h3><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> +</p><div><h3>2012-07-13</h3><ul><li><a href="/wiki/WikiEnd">WikiEnd</a> </li><li><a href="/wiki/WikiMid">WikiMid</a> </li><li><a href="/wiki/WikiStart">WikiStart</a> </li></ul></div><p> /home/joe/src/trac/trunk/trac/wiki/tests/macros.py:1: "RecentChanges, group option" (default flavor) ---------------------------------------------------------------------- Ran 1392 tests in 257.481s FAILED (failures=1)
comment:20 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
follow-up: 22 comment:21 by , 12 years ago
I still get that unit test failure when the functional tests are run. (It also seems to have popped up in comment:57:ticket:10779.)
The problem can be described like this:
>>> import datetime >>> import locale >>> locale.getlocale() (None, None) >>> datetime.datetime.now().strftime("%x") '09/14/12' >>> locale.setlocale(locale.LC_ALL, "") 'German_Switzerland.1252' >>> locale.getlocale() ('German_Switzerland', '1252') >>> datetime.datetime.now().strftime("%x") '14.09.2012'
The strftime("%x")
calls are in trac.util.datefmt.format_time
. (At least without Babel.)
The setlocale(locale.LC_ALL, "")
call is in trac/tests/functional/testenv.py
.
I'm not sure what the best way to fix it is. Somehow remove the setlocale
call somehow? Call setlocale
earlier? Call format_date
later?
I only tried a somewhat crude trick to call format_date
later (and it seems to avoid the problem):
-
trac/wiki/tests/macros.py
diff -r 5f17cf0919aa trac/wiki/tests/macros.py
a b 361 361 </li></ul></div><p> 362 362 </p> 363 363 ------------------------------ 364 """ % {'date': format_date(tzinfo=utc, locale=locale_en)}364 """ 365 365 366 366 def recentchanges_setup(tc): 367 367 def add_pages(tc, names): … … 375 375 'WikiMid', 376 376 'WikiEnd', 377 377 ]) 378 tc.correct = tc.correct % {'date': format_date(tzinfo=utc, 379 locale=locale_en)} 378 380 379 381 def recentchanges_teardown(tc): 380 382 tc.env.reset_db()
comment:22 by , 12 years ago
Replying to psuter:
I still get that unit test failure when the functional tests are run. (It also seems to have popped up in comment:57:ticket:10779.)
Yes, at the time I thought it was due to my strange locale on Windows (I use an en_US locale but change the date and time formats back to Swiss ones).
I only tried a somewhat crude trick to call
format_date
later (and it seems to avoid the problem):
That actually sounds like the proper fix :) Let me check… Yes, that fixes the issue for me, too. Please apply!
First cut at a patch.