From patchwork Tue Mar 13 03:33:09 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: 7253 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 206AB23E01 for ; Tue, 13 Mar 2012 03:33:13 +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 BC6DCA183C3 for ; Tue, 13 Mar 2012 03:33:12 +0000 (UTC) Received: by iage36 with SMTP id e36so243567iag.11 for ; Mon, 12 Mar 2012 20:33:12 -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=w4nE3yimeTYEcA7U+veaH5AF++BUJYrO0LSExtla6QM=; b=FpqqnT0e5IjxJQU2Qfeg9WbegUEPkUb50l3yBKi+RN/aJPqNwP21ZeRO+atXTeuhFk EWkd9c3IXFFluwU4G+FmB1irvqjqOsQRQaQMAjF5hh4RH6IOm2+CE97M954gB3kbQRDD sNKROtCFOCb+pSumm/+2HQ75canaj9Dx767PqhonILV8JRK6D98gUiO6YqnFtMVTZOkX duZJj2OTGhe8FiaNGUfPzHJU9Dm8JhDT/evkGRPxnnIX6uxx4IvHDkkJSQvfywpno+Yp hRyuwQw7qwyqs67QfDQMVyVswBFc4tL3jOXe1OQBqTB6dnR0LVKwYe/TZEGJ95QeoK67 HX5A== Received: by 10.50.184.228 with SMTP id ex4mr1884208igc.50.1331609592241; Mon, 12 Mar 2012 20:33:12 -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.231.53.18 with SMTP id k18csp56437ibg; Mon, 12 Mar 2012 20:33:11 -0700 (PDT) Received: by 10.180.14.73 with SMTP id n9mr3362876wic.16.1331609590379; Mon, 12 Mar 2012 20:33:10 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id t9si5422005wec.115.2012.03.12.20.33.09 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 12 Mar 2012 20:33:10 -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 1S7IU1-00085k-NB for ; Tue, 13 Mar 2012 03:33:09 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id A0867E0109 for ; Tue, 13 Mar 2012 03:33:09 +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: 148 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 148: remove generic tables code and use version that is now in lava-server Message-Id: <20120313033309.13101.85840.launchpad@ackee.canonical.com> Date: Tue, 13 Mar 2012 03:33:09 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14933"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 8da7d00f6908dc9fdbd0ffcf8f5f86e34bc5471b X-Gm-Message-State: ALoCoQkC60RyNzf/uL6PoQvyrMZHflQPYwbv6OEVEckXr51WjPwIYvMCx17ysVSbFkKB3W6DEjtR Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-scheduler/unify-table-code/+merge/96295 proposed by: Michael Hudson-Doyle (mwhudson) review: Approve - Zygmunt Krynicki (zkrynicki) ------------------------------------------------------------ revno: 148 [merge] committer: Michael Hudson-Doyle branch nick: trunk timestamp: Tue 2012-03-13 16:30:52 +1300 message: remove generic tables code and use version that is now in lava-server removed: lava_scheduler_app/tables.py modified: 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 === removed file 'lava_scheduler_app/tables.py' --- lava_scheduler_app/tables.py 2012-03-07 05:10:27 +0000 +++ lava_scheduler_app/tables.py 1970-01-01 00:00:00 +0000 @@ -1,116 +0,0 @@ -import simplejson - -from django.template import compile_string, RequestContext - -from django_tables2.columns import BoundColumn -from django_tables2.rows import BoundRow -from django_tables2.tables import Table, TableData -from django_tables2.utils import AttributeDict - -from lava.utils.data_tables.views import DataTableView -from lava.utils.data_tables.backends import QuerySetBackend - - -simple_nodelist = compile_string('{{ a }}', None) - - -class _ColWrapper(object): - - def __init__(self, name, table): - self.name = name - self.sort_expr = table.columns[name].accessor.replace('.', '__') - self.table = table - - def callback(self, record): - context = self.table.context - context.update({"a": BoundRow(self.table, record)[self.name]}) - try: - return simple_nodelist.render(context) - finally: - context.pop() - - -class _AjaxTableData(TableData): - def order_by(self, order_by): - if order_by: - raise AssertionError( - "AjaxTables do not support ordering by Table options") - return - - -class AjaxTable(Table): - TableDataClass = _AjaxTableData - - def __init__(self, id, source, params=(), _for_rendering=True, **kw): - if 'template' not in kw: - kw['template'] = 'lava_scheduler_app/ajax_table.html' - self.params = params - self.total_length = None - if _for_rendering: - qs = self.get_queryset() - self.total_length = qs.count() - - ordering = self.datatable_opts.get('aaSorting', [[0, 'asc']]) - # What follows is duplicated from backends.py which isn't ideal. - order_by = [] - for column_index, order in ordering: - name, col = self.base_columns.items()[column_index] - sort_expr = BoundColumn(self, col, name).accessor.replace('.', '__') - order_by.append( - "{asc_desc}{column}".format( - asc_desc="-" if order == 'desc' else '', - column=sort_expr)) - qs = qs.order_by(*order_by) - - display_length = self.datatable_opts.get('iDisplayLength', 10) - qs = qs[:display_length] - else: - qs = [] - super(AjaxTable, self).__init__(data=qs, **kw) - self.source = source - self.attrs = AttributeDict({ - 'id': id, - 'class': 'display', - }) - - @classmethod - def json(cls, request, params=()): - table = cls(None, None, params, _for_rendering=False) - table.context = RequestContext(request) - our_cols = [_ColWrapper(name, table) for name in table.columns.names()] - return DataTableView.as_view( - backend=QuerySetBackend( - queryset=table.get_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) - }) - if self.total_length is not None: - opts['iDeferLoading'] = self.total_length - aoColumnDefs = opts['aoColumnDefs'] = [] - for col in self.columns: - aoColumnDefs.append({ - 'bSortable': bool(col.sortable), - 'mDataProp': col.name, - 'aTargets': [col.name], - }) - return simplejson.dumps(opts) - - datatable_opts = {} - searchable_columns = [] - - def get_queryset(self): - raise NotImplementedError - === modified file 'lava_scheduler_app/views.py' --- lava_scheduler_app/views.py 2012-03-13 03:18:14 +0000 +++ lava_scheduler_app/views.py 2012-03-13 03:29:49 +0000 @@ -24,6 +24,8 @@ from django_tables2 import Attrs, Column +from lava.utils.data_tables.tables import DataTablesTable + from lava_server.views import index as lava_index from lava_server.bread_crumbs import ( BreadCrumb, @@ -40,9 +42,6 @@ DeviceStateTransition, TestJob, ) -from lava_scheduler_app.tables import ( - AjaxTable, - ) @@ -98,7 +97,7 @@ }).all() -class JobTable(AjaxTable): +class JobTable(DataTablesTable): def render_device(self, record): if record.actual_device: @@ -142,7 +141,7 @@ return IndexJobTable.json(request) -class DeviceTable(AjaxTable): +class DeviceTable(DataTablesTable): def get_queryset(self): return Device.objects.select_related("device_type") @@ -177,7 +176,7 @@ TestJob.objects.accessible_by_principal(user), pk=pk) -class DeviceHealthTable(AjaxTable): +class DeviceHealthTable(DataTablesTable): def get_queryset(self): return Device.objects.select_related( @@ -225,8 +224,7 @@ class HealthJobTable(JobTable): - def get_queryset(self): - device, = self.params + def get_queryset(self, device): return TestJob.objects.select_related( "submitter", ).filter( @@ -467,8 +465,7 @@ class RecentJobsTable(JobTable): - def get_queryset(self): - device, = self.params + def get_queryset(self, device): return device.recent_jobs() class Meta: @@ -480,10 +477,9 @@ return RecentJobsTable.json(request, params=(device,)) -class DeviceTransitionTable(AjaxTable): +class DeviceTransitionTable(DataTablesTable): - def get_queryset(self): - device, = self.params + def get_queryset(self, device): qs = device.transitions.select_related('created_by') qs = qs.extra(select={'prev': """ select t.created_on @@ -503,7 +499,8 @@ def render_transition(self, record): t = record - return '%s → %s' % (t.get_old_state_display(), t.get_new_state_display(),) + return mark_safe( + '%s → %s' % (t.get_old_state_display(), t.get_new_state_display(),)) def render_message(self, value): if value is None: === modified file 'setup.py' --- setup.py 2012-03-07 03:49:20 +0000 +++ setup.py 2012-03-13 01:19:49 +0000 @@ -35,7 +35,7 @@ install_requires=[ "django-restricted-resource", "django-tables2 >= 0.9.4", - "lava-server >= 0.10", + "lava-server >= 0.11.dev355", "simplejson", "south >= 0.7.3", "twisted",