Ticket #1605 (closed defect: fixed)
[PATCH] Paginate.get_href method shouldn't change instance inner state
|Reported by:||droc||Owned by:||roger.demetrescu|
There is a bug in Paginate's get_href method:
class Paginate: ... def get_href(self, page, order=None, reverse_order=None): # Note that reverse_order is not used. It should be cleaned up here # and in the template. I'm not removing it now because I don't want # to break the API. order = order or None self.input_values[self.var_name + '_tgp_no'] = page if order: self.input_values[self.var_name + '_tgp_order'] = order return turbogears.url('', self.input_values)
Now, this code is used in the default template first to output the pagination links (previous, next, and a range of pages), and then is used to output the table headers, including the sortable ones. When getting the href for a sortable column, the inner state of the objects is changed (self.input_values[self.var_name + '_tgp_order'] is redefined because order is not None).
I think this is unnecessary/incorrect and it fires a bug if you don't use the default template and do something as simple as moving the pagination links below the table (the order is now that set when the header for the last column of the table was generated, as it was the last change made to self.input_values).
Attached are a Demo project and my patch solving this issue. It exposes two methods in its root controller: demo and demo_template. Both render a paginated data grid with enough data to require two pages so the pagination links are shown. The second method, demo_template, changes the template for the data grid, just by moving the pagination links from above to below the table. If you compare the link generated for the two methods you'll see they differ, with the pagination links in the demo_template call defining a new ordering for the table.
The pagination links should be the same whether they are generated before or after the table (or: get_href should return always the same result for the same set of parameters)
The pagination links change if they are generated below the table (or: get_href returns a different value if a previous call has been made with a the second parameter -order- not None)