From patchwork Fri Mar 2 03:18:14 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: 7046 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 AB3FE23EA8 for ; Fri, 2 Mar 2012 03:18:17 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 37D2FA182A0 for ; Fri, 2 Mar 2012 03:18:17 +0000 (UTC) Received: by iage36 with SMTP id e36so2316470iag.11 for ; Thu, 01 Mar 2012 19:18:16 -0800 (PST) Received: from mr.google.com ([10.50.170.41]) by 10.50.170.41 with SMTP id aj9mr421436igc.0.1330658296750 (num_hops = 1); Thu, 01 Mar 2012 19:18:16 -0800 (PST) Received: by 10.50.170.41 with SMTP id aj9mr350759igc.0.1330658296703; Thu, 01 Mar 2012 19:18:16 -0800 (PST) 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.231.53.18 with SMTP id k18csp337ibg; Thu, 1 Mar 2012 19:18:15 -0800 (PST) Received: by 10.180.24.7 with SMTP id q7mr840777wif.14.1330658295321; Thu, 01 Mar 2012 19:18:15 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id k19si395001wiv.14.2012.03.01.19.18.14 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 01 Mar 2012 19:18:15 -0800 (PST) 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 1S3J0Y-00072f-Oo for ; Fri, 02 Mar 2012 03:18:14 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id AAE60E04F5 for ; Fri, 2 Mar 2012 03:18:14 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-scheduler X-Launchpad-Branch: ~linaro-validation/lava-scheduler/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 136 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 136: * add infrastructure to make it really easy to have ajax-backed tables Message-Id: <20120302031814.4041.8277.launchpad@ackee.canonical.com> Date: Fri, 02 Mar 2012 03:18:14 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14886"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: de541b2c1447512286c5767f7f76a34892106555 X-Gm-Message-State: ALoCoQm9OelBPb32KmQevOox7cXDV7LyA9fGl6uQL9AO/ycy1CFPB8FmEXMGfpbDo6QszxemFlZ7 Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-scheduler/ajax-tables/+merge/95311 proposed by: Michael Hudson-Doyle (mwhudson) ------------------------------------------------------------ revno: 136 [merge] committer: Michael Hudson-Doyle branch nick: trunk timestamp: Fri 2012-03-02 16:16:26 +1300 message: * add infrastructure to make it really easy to have ajax-backed tables * convert all existing tables to be ajax-backed added: lava_scheduler_app/tables.py lava_scheduler_app/templates/lava_scheduler_app/ajax_table.html modified: .bzrignore lava_scheduler_app/extension.py lava_scheduler_app/templates/lava_scheduler_app/_content.html lava_scheduler_app/templates/lava_scheduler_app/alljobs.html lava_scheduler_app/templates/lava_scheduler_app/device.html lava_scheduler_app/templates/lava_scheduler_app/health_jobs.html lava_scheduler_app/templates/lava_scheduler_app/index.html lava_scheduler_app/templates/lava_scheduler_app/labhealth.html lava_scheduler_app/urls.py lava_scheduler_app/views.py setup.py --- lp:lava-scheduler https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk You are subscribed to branch lp:lava-scheduler. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription === modified file '.bzrignore' --- .bzrignore 2011-11-26 21:49:36 +0000 +++ .bzrignore 2012-03-02 03:16:26 +0000 @@ -4,3 +4,4 @@ ./_trial_temp ./twisted/plugins/dropin.cache ./dist +./build === modified file 'lava_scheduler_app/extension.py' --- lava_scheduler_app/extension.py 2011-12-01 12:33:01 +0000 +++ lava_scheduler_app/extension.py 2012-02-29 23:59:27 +0000 @@ -61,3 +61,7 @@ import lava_scheduler_app return versiontools.format_version( lava_scheduler_app.__version__, lava_scheduler_app) + + def contribute_to_settings(self, settings_module): + super(SchedulerExtension, self).contribute_to_settings(settings_module) + settings_module['INSTALLED_APPS'].append('django_tables2') === added file 'lava_scheduler_app/tables.py' --- lava_scheduler_app/tables.py 1970-01-01 00:00:00 +0000 +++ lava_scheduler_app/tables.py 2012-03-01 22:02:21 +0000 @@ -0,0 +1,85 @@ +import simplejson + +import django_tables2 as tables +from django_tables2.rows import BoundRow +from django_tables2.utils import AttributeDict + +from lava.utils.data_tables.views import DataTableView +from lava.utils.data_tables.backends import QuerySetBackend + + +class AjaxColumn(tables.Column): + + def __init__(self, *args, **kw): + sort_expr = kw.pop('sort_expr', None) + width = kw.pop('width', None) + super(AjaxColumn, self).__init__(*args, **kw) + self.sort_expr = sort_expr + self.width = width + + +class _ColWrapper(object): + + def __init__(self, name, sort_expr, table): + self.name = name + if sort_expr is not None: + self.sort_expr = sort_expr + else: + self.sort_expr = name + self.table = table + + def callback(self, record): + # It _might_ make life more convenient to handle certain non-JSONable + # datatypes here -- particularly, applying unicode() to model objects + # would be more consistent with the way templates work. + return BoundRow(self.table, record)[self.name] + + +class AjaxTable(tables.Table): + datatable_opts = None + searchable_columns = [] + + def __init__(self, id, source, **kw): + if 'template' not in kw: + kw['template'] = 'lava_scheduler_app/ajax_table.html' + super(AjaxTable, self).__init__(data=[], **kw) + self.source = source + self.attrs = AttributeDict({ + 'id': id, + 'class': 'display', + }) + + @classmethod + def json(cls, request, queryset): + table = cls(None, None) + our_cols = [_ColWrapper(name, col.sort_expr, table) + for name, col in cls.base_columns.iteritems()] + return DataTableView.as_view( + backend=QuerySetBackend( + queryset=queryset, + columns=our_cols, + searching_columns=cls.searchable_columns) + )(request) + + def datatable_options(self): + if self.datatable_opts: + opts = self.datatable_opts.copy() + else: + opts = {} + opts.update({ + 'bJQueryUI': True, + 'bServerSide': True, + 'bProcessing': True, + 'sAjaxSource': self.source, + 'bFilter': bool(self.searchable_columns) + }) + aoColumnDefs = opts['aoColumnDefs'] = [] + for col in self.columns: + aoColumnDefs.append({ + 'bSortable': bool(col.sortable), + 'mDataProp': col.name, + 'aTargets': [col.name], + }) + if col.column.width: + aoColumnDefs[-1]['sWidth'] = col.column.width + return simplejson.dumps(opts) === modified file 'lava_scheduler_app/templates/lava_scheduler_app/_content.html' --- lava_scheduler_app/templates/lava_scheduler_app/_content.html 2011-10-28 00:24:13 +0000 +++ lava_scheduler_app/templates/lava_scheduler_app/_content.html 2012-03-02 00:04:07 +0000 @@ -3,23 +3,6 @@ {% block extrahead %} {{ block.super }} - - - + + {% endblock %} === added file 'lava_scheduler_app/templates/lava_scheduler_app/ajax_table.html' --- lava_scheduler_app/templates/lava_scheduler_app/ajax_table.html 1970-01-01 00:00:00 +0000 +++ lava_scheduler_app/templates/lava_scheduler_app/ajax_table.html 2012-03-01 04:04:21 +0000 @@ -0,0 +1,25 @@ +{% extends "django_tables2/table.html" %} + +{% block table.thead %} + + + {% for column in table.columns %} + {{ column.header }} + {% endfor %} + + +{% endblock table.thead %} + +{% block table %} +{{ block.super }} +{% comment %} +The div below is a ridiculous hack to avoid the jQuery.details.js +setting the display: of the script element to "block" when showing a +table that is in a
element. +{% endcomment %} +
+ +
+{% endblock %} === modified file 'lava_scheduler_app/templates/lava_scheduler_app/alljobs.html' --- lava_scheduler_app/templates/lava_scheduler_app/alljobs.html 2012-02-10 19:44:59 +0000 +++ lava_scheduler_app/templates/lava_scheduler_app/alljobs.html 2012-03-01 04:30:48 +0000 @@ -1,62 +1,10 @@ {% extends "lava_scheduler_app/_content.html" %} +{% load django_tables2 %} {% block content %}

All Jobs

- - - - - - - - - - - - - -
IDStatusDeviceDescriptionSubmitterSubmit Time
- - +{% render_table alljobs_table %} {% endblock %} === modified file 'lava_scheduler_app/templates/lava_scheduler_app/device.html' --- lava_scheduler_app/templates/lava_scheduler_app/device.html 2012-02-16 02:27:05 +0000 +++ lava_scheduler_app/templates/lava_scheduler_app/device.html 2012-03-01 04:04:21 +0000 @@ -1,5 +1,7 @@ {% extends "lava_scheduler_app/_content.html" %} +{% load django_tables2 %} + {% block extrahead %} {{ block.super }}