From patchwork Wed Aug 24 23:55:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael-Doyle Hudson X-Patchwork-Id: 3667 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 0F11F23F4D for ; Wed, 24 Aug 2011 23:55:15 +0000 (UTC) Received: from mail-bw0-f52.google.com (mail-bw0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id E64D9A181B2 for ; Wed, 24 Aug 2011 23:55:14 +0000 (UTC) Received: by bkbzs2 with SMTP id zs2so2040214bkb.11 for ; Wed, 24 Aug 2011 16:55:14 -0700 (PDT) Received: by 10.204.13.81 with SMTP id b17mr682836bka.278.1314230114478; Wed, 24 Aug 2011 16:55:14 -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.204.41.75 with SMTP id n11cs33250bke; Wed, 24 Aug 2011 16:55:14 -0700 (PDT) Received: by 10.227.157.81 with SMTP id a17mr1964208wbx.75.1314230113902; Wed, 24 Aug 2011 16:55:13 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com [91.189.90.7]) by mx.google.com with ESMTPS id fz18si2518wbb.111.2011.08.24.16.55.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 16:55:13 -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 1QwNHt-0001bl-DA for ; Wed, 24 Aug 2011 23:55:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 57DB7E0419 for ; Wed, 24 Aug 2011 23:55:13 +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: 76 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 76: add a jsonp-compatible view of a job Message-Id: <20110824235513.22704.21387.launchpad@ackee.canonical.com> Date: Wed, 24 Aug 2011 23:55: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="13779"; Instance="initZopeless config overlay" X-Launchpad-Hash: 8d96666f3a33c66caf2efd54ed560c17dc19a4b0 Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-scheduler/ajax-job-info/+merge/72660 proposed by: Michael Hudson-Doyle (mwhudson) review: Approve - Zygmunt Krynicki (zkrynicki) ------------------------------------------------------------ revno: 76 [merge] committer: Michael-Doyle Hudson branch nick: trunk timestamp: Thu 2011-08-25 11:52:28 +1200 message: add a jsonp-compatible view of a job modified: lava_scheduler_app/urls.py lava_scheduler_app/views.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/urls.py' --- lava_scheduler_app/urls.py 2011-08-22 03:08:56 +0000 +++ lava_scheduler_app/urls.py 2011-08-23 04:04:17 +0000 @@ -8,6 +8,7 @@ url(r'^device/(?P[-_a-zA-Z0-9]+)/maintenance$', 'device_maintenance_mode'), url(r'^device/(?P[-_a-zA-Z0-9]+)/online$', 'device_online'), url(r'^job/(?P[0-9]+)$', 'job'), + url(r'^job/(?P[0-9]+)/cancel$', 'job_cancel'), + url(r'^job/(?P[0-9]+)/json$', 'job_json'), url(r'^job/(?P[0-9]+)/output$', 'job_output'), - url(r'^job/(?P[0-9]+)/cancel$', 'job_cancel'), ) === modified file 'lava_scheduler_app/views.py' --- lava_scheduler_app/views.py 2011-08-22 05:21:44 +0000 +++ lava_scheduler_app/views.py 2011-08-24 10:58:25 +0000 @@ -1,3 +1,4 @@ +import json import os from django.http import ( @@ -6,7 +7,11 @@ HttpResponseNotAllowed, ) from django.template import RequestContext -from django.shortcuts import redirect, render_to_response +from django.shortcuts import ( + get_object_or_404, + redirect, + render_to_response, + ) from lava_scheduler_app.models import Device, TestJob @@ -96,6 +101,19 @@ "you cannot cancel this job", content_type="text/plain") +def job_json(request, pk): + job = get_object_or_404(TestJob, pk=pk) + json_text = json.dumps({ + 'status': job.get_status_display(), + 'results_link': job.results_link, + }) + content_type = 'application/json' + if 'callback' in request.GET: + json_text = '%s(%s)'%(request.GET['callback'], json_text) + content_type = 'text/javascript' + return HttpResponse(json_text, content_type=content_type) + + def device(request, pk): device = Device.objects.get(pk=pk) recent_jobs = TestJob.objects.all().filter(