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()
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)))
<<
rulefunc=lambda _func,
accept, allow_json,
*args, **kw:
_execute_func(_func, template,
format, content_type,
fragment, options,
args, kw)))
if allow_json:
Module turbogears.controllers:424
in _execute_func
output
= errorhandling.try_call(func,
*args, **kw)
<<
log.debug("Calling %s with *(%s), **(%s)", func, args, kw)
output =
errorhandling.try_call(func, *args, **kw)
if str(getattr(response, 'status', '')).startswith('204'):
Module turbogears.errorhandling:73
in try_call
return
func(self,
*args, **kw)
<<
from turbogears.database import
restart_transaction
try:
return
func(self,
*args, **kw)
except Exception, e:
if isinstance(e,
cherrypy.HTTPRedirect)
or
Module ?:3 in index
Module turbogears.paginate:191
in decorated
max_sort
is None
or 0
< row_count <= max_sort)
<<
if ordering:
var_data = sort_data(var_data,
ordering,
max_sort is
None or
0 < row_count <= max_sort)
# If limit is zero then return
all our rows
Module turbogears.paginate:529
in sort_data
keys
= [reverse_key(*key) for
key in
keys]
<<
keys = dict((k, -n) for n, k in
enumerate(keys))
return lambda row: keys[key(row)]
keys =
[reverse_key(*key) for key in keys]
key = lambda row: [key(row) for key in keys]
data.sort(key=key, reverse=reverse)
Module turbogears.paginate:526
in reverse_key
keys.sort()
<<
return lambda row: -keys.index(key(row))
else:
keys.sort()
keys = dict((k, -n) for n, k in
enumerate(keys))
return lambda row: keys[key(row)]
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.
|