From: <al...@us...> - 2009-12-29 20:18:17
|
Revision: 13569 http://translate.svn.sourceforge.net/translate/?rev=13569&view=rev Author: alaaosh Date: 2009-12-29 20:18:02 +0000 (Tue, 29 Dec 2009) Log Message: ----------- another aggregate function Modified Paths: -------------- src/trunk/Pootle/local_apps/pootle_misc/aggregate.py Modified: src/trunk/Pootle/local_apps/pootle_misc/aggregate.py =================================================================== --- src/trunk/Pootle/local_apps/pootle_misc/aggregate.py 2009-12-29 20:16:38 UTC (rev 13568) +++ src/trunk/Pootle/local_apps/pootle_misc/aggregate.py 2009-12-29 20:18:02 UTC (rev 13569) @@ -19,7 +19,14 @@ # along with this program; if not, see <http://www.gnu.org/licenses/>. try: - from django.db.models import Sum, Count + from django.db.models import Sum, Count, Max + + def max_column(queryset, column, default): + result = queryset.aggregate(result=Max(column))['result'] + if result is None: + return default + else: + return result def sum_column(queryset, columns, count=False): arg_dict = {} @@ -31,8 +38,16 @@ return queryset.aggregate(**arg_dict) + except ImportError: from pootle_store.util import dictsum + + def max_column(queryset, column, default): + try: + return max(queryset.values_list(column, flat=True)) + except ValueError: + return default + def sum_column(queryset, columns, count=False): initial = {} @@ -43,3 +58,4 @@ result['count'] = queryset.count() return result + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |