Author: floguy
Date: Mon Sep 22 02:36:54 2008
New Revision: 35
Modified:
trunk/things/fields.py
trunk/things/options.py
Log:
Added custom aggregate suport (version 2.0)
Modified: trunk/things/fields.py
==============================================================================
--- trunk/things/fields.py (original)
+++ trunk/things/fields.py Mon Sep 22 02:36:54 2008
@@ -22,7 +22,7 @@
def __init__(self, verbose_name_asc=None, verbose_name_desc=None,
url_asc=None, url_desc=None, field_url=None,
custom_aggregate_function=None,
default_sort_descending=True,
- reverse=False):
+ reverse=False, custom_aggregate_dict_function=None):
self._verbose_name_asc = verbose_name_asc
self._verbose_name_desc = verbose_name_desc
self._url_asc = url_asc
@@ -31,6 +31,7 @@
self.reverse = reverse
self.default_sort_descending = default_sort_descending
self.custom_aggregate_function = custom_aggregate_function
+ self.custom_aggregate_dict_function =
custom_aggregate_dict_function
def _get_verbose_name_asc(self):
if self._verbose_name_asc:
Modified: trunk/things/options.py
==============================================================================
--- trunk/things/options.py (original)
+++ trunk/things/options.py Mon Sep 22 02:36:54 2008
@@ -54,14 +54,20 @@
q_list = [Q(**{'%s__icontains' % s: terms}) for s in
self.search]
items = items.filter(reduce(or_, q_list))
if field is not None:
+ reverse = descending ^ field.reverse
pre = ''
- if (descending ^ field.reverse) == True:
+ if reverse:
pre = '-'
if field.custom_aggregate_function is not None:
caf = field.custom_aggregate_function
- reverse = descending ^ field.reverse
vgetter = lambda val: val[1]
- items = [i[0] for i in sorted([(j, caf(j)) for j in
items], key=vgetter, reverse=reverse)]
+ items = [i[0] for i in sorted([(j, caf(j)) for j in items],
+ key=vgetter, reverse=reverse)]
+ elif field.custom_aggregate_dict_function is not None:
+ cadf = field.custom_aggregate_dict_function
+ pk_sort_dict = field.custom_aggregate_dict_function()
+ items = list(items.filter(pk__in=pk_sort_dict.keys()))
+ items.sort(key=lambda val: pk_sort_dict[val.id],
reverse=reverse)
elif isinstance(field, AggregateBase):
items = items.order_by('%s%s' % (pre,
field.get_aggregate_name()))
else:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-updates" 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/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---