From patchwork Sat Aug 18 07:07:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael-Doyle Hudson X-Patchwork-Id: 10794 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3011F23E56 for ; Sat, 18 Aug 2012 07:07:17 +0000 (UTC) Received: from mail-ob0-f180.google.com (mail-ob0-f180.google.com [209.85.214.180]) by fiordland.canonical.com (Postfix) with ESMTP id CF702A1900C for ; Sat, 18 Aug 2012 07:07:16 +0000 (UTC) Received: by obceq6 with SMTP id eq6so6366957obc.11 for ; Sat, 18 Aug 2012 00:07:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=EROteKU2GiufboYYdC+VuJ4kLcuT1L97kt+POV9j5dw=; b=TSWyuGQu7X5M3pCAe2kHuzSqDcXVMlcB6jb6srHOEUUCjAprmyHbNGjuYTk4XpFqT8 mMVpIWuVZvttCkSfsTqHqrKbVAagIk+zFOgIu2mSJb6iBHEbAZM1YTNDLI4JBoYnq+le QmkmpE6RlrzSp2hlJQYgwSB26efS8yQx1wMBnQ8T55DivWzur0v577dNJROqa9KUh81n ali6rWDkUoe4nPhN6vbQaUivLf05f5i1EGyj7C6N+bGjaTx5aKO9G3ctzIAfoScfxsko S1UCRX734OQVIzqxJHV7R8WuRZVLi1r/MLu49YdWBcCe85ixDQVWBJ/lUYmkHP2q1Nx+ efYA== Received: by 10.50.10.201 with SMTP id k9mr4185434igb.28.1345273636180; Sat, 18 Aug 2012 00:07:16 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp143939igc; Sat, 18 Aug 2012 00:07:14 -0700 (PDT) Received: by 10.180.92.9 with SMTP id ci9mr11239564wib.22.1345273634218; Sat, 18 Aug 2012 00:07:14 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id m4si13359033wea.123.2012.08.18.00.07.13 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 18 Aug 2012 00:07:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1T2d7p-0000tQ-Dy for ; Sat, 18 Aug 2012 07:07:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 46620E0194 for ; Sat, 18 Aug 2012 07:07:13 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-server X-Launchpad-Branch: ~linaro-validation/lava-server/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 387 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-server/trunk] Rev 387: provide a hook to recompute the queryset after the table columns have changed Message-Id: <20120818070713.29152.46268.launchpad@ackee.canonical.com> Date: Sat, 18 Aug 2012 07:07:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15810"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 5b9a118047a55fe31712a1c48b62cc315ab96664 X-Gm-Message-State: ALoCoQlmLsjS0sDgsG5nIKyUMlOAGhbmkOfy23WF69EeBVwNLoccfijBjfoZCpAzQMqx3yM7GNxr ------------------------------------------------------------ revno: 387 committer: Michael Hudson-Doyle branch nick: trunk timestamp: Sat 2012-08-18 12:06:05 +1200 message: provide a hook to recompute the queryset after the table columns have changed modified: lava/utils/data_tables/backends.py lava/utils/data_tables/tables.py --- lp:lava-server https://code.launchpad.net/~linaro-validation/lava-server/trunk You are subscribed to branch lp:lava-server. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-server/trunk/+edit-subscription === modified file 'lava/utils/data_tables/backends.py' --- lava/utils/data_tables/backends.py 2012-08-17 05:52:39 +0000 +++ lava/utils/data_tables/backends.py 2012-08-18 00:06:05 +0000 @@ -240,6 +240,7 @@ "{asc_desc}{column}".format( asc_desc="-" if order == 'desc' else '', column=accessor.replace('.', '__'))) + print order_by return queryset.order_by(*order_by) def process(self, query): === modified file 'lava/utils/data_tables/tables.py' --- lava/utils/data_tables/tables.py 2012-05-29 01:33:39 +0000 +++ lava/utils/data_tables/tables.py 2012-08-18 00:06:05 +0000 @@ -152,15 +152,9 @@ super(DataTablesTable, self).__init__( data=data, sortable=sortable, empty_text=empty_text, attrs=attrs, template=template) + self._full_length = None if not data_backed_table: - self.full_queryset = self.get_queryset(*params) - self.full_length = self.full_queryset.count() - ordering = self.datatable_opts.get('aaSorting', [[0, 'asc']]) - sorted_queryset = TableBackend(self).apply_sorting_columns( - self.full_queryset, ordering) - display_length = self.datatable_opts.get('iDisplayLength', 10) - del self.data.list - self.data.queryset = sorted_queryset[:display_length] + self._compute_queryset(params) # We are careful about modifying the attrs here -- if it comes from # class Meta:-type options, we don't want to modify the original # value! @@ -175,6 +169,22 @@ }) self.attrs = attrs + def _compute_queryset(self, params): + self.full_queryset = self.get_queryset(*params) + ordering = self.datatable_opts.get('aaSorting', [[0, 'asc']]) + sorted_queryset = TableBackend(self).apply_sorting_columns( + self.full_queryset, ordering) + display_length = self.datatable_opts.get('iDisplayLength', 10) + if getattr(self.data, 'list', None) is not None: + del self.data.list + self.data.queryset = sorted_queryset[:display_length] + + @property + def full_length(self): + if self._full_length is None: + self._full_length = self.full_queryset.count() + return self._full_length + @classmethod def json(cls, request, params=()): """Format table data according to request. @@ -211,7 +221,7 @@ 'bServerSide': True, 'sAjaxSource': self.source, 'bFilter': bool(self.searchable_columns), - 'iDeferLoading': self.full_length, + 'iDeferLoading': self.full_queryset.count(), }) aoColumnDefs = opts['aoColumnDefs'] = [] for col in self.columns: