diff mbox

[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
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Aug. 24, 2011, 11:55 p.m. UTC
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 <michael.hudson@linaro.org>
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
diff mbox

Patch

=== 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<pk>[-_a-zA-Z0-9]+)/maintenance$', 'device_maintenance_mode'),
     url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)/online$', 'device_online'),
     url(r'^job/(?P<pk>[0-9]+)$', 'job'),
+    url(r'^job/(?P<pk>[0-9]+)/cancel$', 'job_cancel'),
+    url(r'^job/(?P<pk>[0-9]+)/json$', 'job_json'),
     url(r'^job/(?P<pk>[0-9]+)/output$', 'job_output'),
-    url(r'^job/(?P<pk>[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(