Christoph Zwerschke wrote:
Am 15.04.2010 10:57 schrieb jo:
I suppose you tried without no values at all in the column data_fine
in all rows, in such case there's no error because it compares None
with None, try to insert a date in almost one row and you will see
the error.

No, I tested with 12 existing records to check that the pagination works, and one had data_fine=null. Tried with Postgres and SQLite, both worked. The record with data_fine=null was sorted last, and when I clicked again, it was sorted first.

I tried it with the original template of
widgets.PaginateDataGrid()


codice descrizione gruppo specie data_fine
0126 Equidi 0131 2010-04-15 00:00:00
0128 Coniglio 0130 2010-04-15 00:00:00
0121 Bovino 0130
0137 Oca 0127 2010-04-15 00:00:00
0138 Faraona 0127 2010-04-15 00:00:00
0139 Fagiano 0127 2010-04-15 00:00:00
0124 Ovino 0124 2010-04-15 00:00:00
0125 Caprino 0124 2010-04-15 00:00:00
0122 Suino 0122 2010-04-15 00:00:00
0129 Bufalino 0121 2010-04-15 00:00:00

when I click on data_fine...
----------------------------------------------
Module turbogears.controllers:? in _expose
Module peak.rules.core:153 in __call__
Module turbogears.controllers:389 in <lambda>
fragment, options, args, kw)))

Module turbogears.controllers:424 in _execute_func
output = errorhandling.try_call(func, *args, **kw)

Module turbogears.errorhandling:73 in try_call
return func(self, *args, **kw)

Module ?:3 in index
Module turbogears.paginate:191 in decorated
max_sort is None or 0 < row_count <= max_sort)

Module turbogears.paginate:529 in sort_data
keys = [reverse_key(*key) for key in keys]

Module turbogears.paginate:526 in reverse_key
keys.sort()

TypeError: ("can't compare datetime.datetime to NoneType", <bound method Controller.index of <sicer.BASE.controller.tabelleCodifica.specie.Controller object at 0x4e26b10>>)

furthermore, I'm trying to understand how sorting works,
(default_order without minus sign = ORDER BY ASC, rigth?)

Yes, you can set default_order='-data_fine' for instance.

http://tg11.sfera.com/specie/?grid_params_tgp_ordering=
> specie_cod_gruppo_specie&grid_params_tgp_limit=10&
> grid_params_tgp_order=specie_cod_gruppo_specie&
> grid_params_tgp_no=1
>
Here I expected -specie_cod_gruppo_specie instead of
specie_cod_gruppo_specie, infact the order by is desc
sql: select * from specie order by cod_gruppo_specie desc; (*)

The tgp_ordering parameter is used to pass the *current* ordering (as displayed), the tgp_order parameter passes the column you clicked. So if the ordering is currently ASC, and you click on the column, it will become DESC.

The mechanism is actually much simpler than it was before 1.0.5. Maybe you think too complicated ;-)

(*) paginate sorts the columns with None in a different way from Postgres.

You mean when it sorts in memory?

You can force sorting in memory by appending .all() to your query. Then SA will fetch all records, so it will be too late for sorting in the database, and TG resorts to sorting in memory. The only difference I see is that sorting datetime columns with None values does not work because Python does not want to do this.

If you really need to sort datetimes in memory, you can overcome this problem easily by adding a sortable column like this:

class Specie:
    @property
    def data_ordinare(self):
        return self.data_fine or datetime.max

-- Christoph



j


--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.

Reply via email to