Hello,
so here's my problem and the solution:
When using TG for forums and blogs or pretty much anything the like, it's
useful to be able to allow external references (links from another page) to
jump to the latest post - meaning the last page unless you sort in reverse.
However, TG2 pagination has no easy way to do this. TG1 used to have a literal
"page=last" possibility, which didn't require you to know what the last page
number of the collection actually is.
That got me thinking: current tg.decorators.paginate catches negative numbers.
What if it wouldn't? One could page to "page=-1" and end at the last page,
page-2 would be second last and so on.
I quickly hacked the decorators.py file and commented the page < 0 catch out
and added 2 lines in support.paginate.py looking like
...
self.last_page = self.first_page + self.page_count - 1
if self.page < 0:
self.page = self.last_page + 1 - abs(self.page)
# Make sure that the requested page number is the range of ...
...
This works nicely. Negative values count from the end of the collection and if
the negative number given is larger than the number of pages the integrity
tests set it to the first page. The only issue I see is what to do with page=0.
Counting the last page as 0 is counter-intuitive, but it also isn't the first
page. The current code (with or without my change) will simply set it at 0=1,
which I guess is reasonable since nobody would expect page 0 to be anything
but the first page.
Would this be something considered for a patch? If so, how would I submit said
patch?
Uwe
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.