From patchwork Tue Feb 14 22:55:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Larson X-Patchwork-Id: 6778 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 EC5D423E01 for ; Tue, 14 Feb 2012 22:55:20 +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 90662A18925 for ; Tue, 14 Feb 2012 22:55:20 +0000 (UTC) Received: by iabz7 with SMTP id z7so796486iab.11 for ; Tue, 14 Feb 2012 14:55:20 -0800 (PST) Received: by 10.50.87.136 with SMTP id ay8mr20791461igb.25.1329260119995; Tue, 14 Feb 2012 14:55:19 -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.66.135 with SMTP id n7cs102575ibi; Tue, 14 Feb 2012 14:55:19 -0800 (PST) Received: by 10.216.136.138 with SMTP id w10mr1718810wei.33.1329260118731; Tue, 14 Feb 2012 14:55:18 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id dy1si12230168wib.24.2012.02.14.14.55.18 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 14 Feb 2012 14:55:18 -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 1RxRHK-0000im-4w for ; Tue, 14 Feb 2012 22:55:18 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 05A4FE143A for ; Tue, 14 Feb 2012 22:55:18 +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: 130 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 130: Make alljobs paginated so that it will load very quickly Message-Id: <20120214225518.7987.20826.launchpad@ackee.canonical.com> Date: Tue, 14 Feb 2012 22:55:18 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14781"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: ca4a94636aa007b30c792da81fc86a3c01d13822 X-Gm-Message-State: ALoCoQk9LxnNZDnSjqDLKxtSnbbNXJqP6D7OyWIV0A2uUvVfOPeKdqxakV7rnZEnOSm+PzsZ5wKU Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-scheduler/server-side-tables/+merge/92565 proposed by: Michael Hudson-Doyle (mwhudson) review: Approve - Zygmunt Krynicki (zkrynicki) ------------------------------------------------------------ revno: 130 [merge] committer: Paul Larson branch nick: lava-scheduler timestamp: Tue 2012-02-14 14:53:27 -0800 message: Make alljobs paginated so that it will load very quickly modified: lava_scheduler_app/templates/lava_scheduler_app/alljobs.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 'lava_scheduler_app/templates/lava_scheduler_app/alljobs.html' --- lava_scheduler_app/templates/lava_scheduler_app/alljobs.html 2011-12-06 23:02:25 +0000 +++ lava_scheduler_app/templates/lava_scheduler_app/alljobs.html 2012-02-10 19:44:59 +0000 @@ -8,32 +8,14 @@ ID - Status - Device - Description - Submitter - Submit Time + Status + Device + Description + Submitter + Submit Time - {% for job in jobs %} - - {{ job.id }} - {{ job.get_status_display }} - {% if job.actual_device %} - {{ job.actual_device }} - {% else %}{% if job.requested_device %} - {{ job.requested_device }} - {% else %} - {{ job.requested_device_type|default:'' }} - {% endif %}{% endif %} - {{ job.description|default:'' }} - {{ job.submitter }} - {{ job.submit_time }} - - {% endfor %} @@ -41,12 +23,37 @@ $(document).ready( function() { $("table.data").dataTable({ - "bJQueryUI": true, - "aoColumnDefs": [ - { "sType": "num-html", "aTargets": [ "id" ] } - ], - "aaSorting": [[0, "desc"]], - "iDisplayLength": 25 + bJQueryUI: true, + bServerSide: true, + bProcessing: true, + bFilter: true, + sAjaxSource: "{% url lava_scheduler_app.views.alljobs_json %}", + aaSorting: [[0, "desc"]], + iDisplayLength: 25, + aoColumnDefs: [ + { + aTargets: ["id"], + fnRender: function (o) { return '' + o.aData.id.id + ''; } + }, + {aTargets: ["status"], mDataProp: 'status'}, + {aTargets: ["description"], mDataProp: 'description'}, + {aTargets: ["submitter"], mDataProp: 'submitter'}, + {aTargets: ["submit_time"], mDataProp: 'submit_time'}, + { + aTargets: ["device"], + fnRender: function (o) { + o = o.aData.device; + r = o.name; + if (o.requested) { + r = '' + r + ''; + } + if (o.link) { + return '' + r + ''; + } + return r; + } + } + ] }); } ); === modified file 'lava_scheduler_app/urls.py' --- lava_scheduler_app/urls.py 2011-12-13 03:58:12 +0000 +++ lava_scheduler_app/urls.py 2012-02-10 01:24:02 +0000 @@ -1,5 +1,6 @@ from django.conf.urls.defaults import url, patterns + urlpatterns = patterns( 'lava_scheduler_app.views', url(r'^$', @@ -8,6 +9,9 @@ url(r'^alljobs$', 'job_list', name='lava.scheduler.job.list'), + url(r'^alljobs_json$', + 'alljobs_json', + name='lava.scheduler.job.list_json'), url(r'^device/(?P[-_a-zA-Z0-9]+)$', 'device_detail', name='lava.scheduler.device.detail'), === modified file 'lava_scheduler_app/views.py' --- lava_scheduler_app/views.py 2012-02-09 20:44:59 +0000 +++ lava_scheduler_app/views.py 2012-02-10 19:50:40 +0000 @@ -4,19 +4,24 @@ import simplejson import StringIO - +from django.conf import settings +from django.core.urlresolvers import reverse from django.http import ( HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed, ) -from django.template import RequestContext from django.shortcuts import ( get_object_or_404, redirect, render_to_response, ) +from django.template import RequestContext +from django.template import defaultfilters as filters + +from lava.utils.data_tables.views import DataTableView +from lava.utils.data_tables.backends import QuerySetBackend, Column from lava_server.views import index as lava_index from lava_server.bread_crumbs import ( @@ -29,7 +34,12 @@ getDispatcherErrors, getDispatcherLogMessages ) -from lava_scheduler_app.models import Device, DeviceStateTransition, TestJob +from lava_scheduler_app.models import ( + Device, + DeviceStateTransition, + TestJob, + ) + def post_only(func): @@ -60,14 +70,58 @@ return render_to_response( "lava_scheduler_app/alljobs.html", { - 'jobs': TestJob.objects.select_related( - "actual_device", "requested_device", "requested_device_type", - "submitter").all(), 'bread_crumb_trail': BreadCrumbTrail.leading_to(job_list), }, RequestContext(request)) +def device_callback(job): + if job.actual_device: + return dict( + name=job.actual_device.pk, requested=False, + link=reverse(device_detail, kwargs=dict(pk=job.actual_device.pk))) + elif job.requested_device: + return dict( + name=job.requested_device.pk, requested=True, + link=reverse(device_detail, kwargs=dict(pk=job.requested_device.pk))) + else: + return dict(name=job.requested_device_type.pk, requested=True) + + +def id_callback(job): + if job is None: + return job + else: + return dict(id=job.id, link=reverse(job_detail, kwargs=dict(pk=job.id))) + + +alljobs_json = DataTableView.as_view( + backend=QuerySetBackend( + queryset=TestJob.objects.select_related( + "actual_device", "requested_device", "requested_device_type", + "submitter").extra( + select={ + 'device_sort': 'coalesce(actual_device_id, requested_device_id, requested_device_type_id)' + }).all(), + columns=[ + Column( + 'id', 'id', id_callback), + Column( + 'status', 'status', lambda job: job.get_status_display()), + Column( + 'device', 'device_sort', device_callback), + Column( + 'description', 'description', lambda job: job.description), + Column( + 'submitter', 'submitter', lambda job: job.submitter.username), + Column( + 'submit_time', 'submit_time', + lambda job: filters.date( + job.submit_time, settings.DATETIME_FORMAT)), + ], + searching_columns=['description'])) + + @BreadCrumb("Job #{pk}", parent=index, needs=['pk']) def job_detail(request, pk): job = get_object_or_404(TestJob, pk=pk) === modified file 'setup.py' --- setup.py 2011-12-05 21:46:59 +0000 +++ setup.py 2012-02-14 22:53:27 +0000 @@ -33,7 +33,7 @@ scheduler = lava_scheduler_app.extension:SchedulerExtension """, install_requires=[ - "lava-server >= 0.8", + "lava-server >= 0.10", "simplejson", "south >= 0.7.3", "twisted",