Author: floguy
Date: Mon Sep 22 02:25:05 2008
New Revision: 34
Modified:
trunk/things/options.py
trunk/things/sites.py
Log:
Added custom aggregate support (version 1.0)
Modified: trunk/things/options.py
==============================================================================
--- trunk/things/options.py (original)
+++ trunk/things/options.py Mon Sep 22 02:25:05 2008
@@ -9,8 +9,6 @@
from django.db.models import Q
from things.fields import BaseField, OrderCountField, AggregateBase
-DETAIL_RE = re.compile('^(\d+)/$')
-
class BaseThingMetaclass(type):
def __new__(cls, name, bases, attrs):
fields = {}
@@ -57,16 +55,13 @@
items = items.filter(reduce(or_, q_list))
if field is not None:
pre = ''
- if descending == True:
+ if (descending ^ field.reverse) == True:
pre = '-'
- # Make this code more pretty when you get time. Redundancy
abound.
- if field.reverse == True:
- if pre == '':
- pre = '-'
- else:
- pre = ''
if field.custom_aggregate_function is not None:
- pass # TODO: Don't forget to implement me!
+ 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)]
elif isinstance(field, AggregateBase):
items = items.order_by('%s%s' % (pre,
field.get_aggregate_name()))
else:
Modified: trunk/things/sites.py
==============================================================================
--- trunk/things/sites.py (original)
+++ trunk/things/sites.py Mon Sep 22 02:25:05 2008
@@ -53,7 +53,7 @@
If a model isn't already registered, this will raise NotRegistered.
"""
- if isinstance(mdoel_or_iterable, ModelBase):
+ if isinstance(model_or_iterable, ModelBase):
model_or_iterable = (model_or_iterable,)
for model in model_or_iterable:
if model not in self._registry:
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---