diff mbox

[Branch,~linaro-validation/lava-scheduler/trunk] Rev 236: add a re-submit button to jobs in UI

Message ID 20130115205412.9956.19497.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Andy Doan Jan. 15, 2013, 8:54 p.m. UTC
Merge authors:
  Andy Doan (doanac)
Related merge proposals:
  https://code.launchpad.net/~doanac/lava-scheduler/resubmit-button/+merge/143372
  proposed by: Andy Doan (doanac)
------------------------------------------------------------
revno: 236 [merge]
committer: Andy Doan <andy.doan@linaro.org>
branch nick: lava-scheduler
timestamp: Tue 2013-01-15 14:53:29 -0600
message:
  add a re-submit button to jobs in UI
modified:
  lava_scheduler_app/models.py
  lava_scheduler_app/templates/lava_scheduler_app/job_sidebar.html
  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/models.py'
--- lava_scheduler_app/models.py	2013-01-14 21:01:59 +0000
+++ lava_scheduler_app/models.py	2013-01-15 20:53:29 +0000
@@ -463,10 +463,15 @@ 
         """
         Permission required for user to add failure information to a job
         """
-        return self._can_admin(user)
+        states = [TestJob.COMPLETE, TestJob.INCOMPLETE, TestJob.CANCELED]
+        return self._can_admin(user) and self.status in states
 
     def can_cancel(self, user):
-        return self._can_admin(user)
+        return self._can_admin(user) and self.status <= TestJob.RUNNING
+
+    def can_resubmit(self, user):
+        states = [TestJob.COMPLETE, TestJob.INCOMPLETE, TestJob.CANCELED]
+        return self._can_admin(user) and self.status in states
 
     def cancel(self):
         if self.status == TestJob.RUNNING:

=== modified file 'lava_scheduler_app/templates/lava_scheduler_app/job_sidebar.html'
--- lava_scheduler_app/templates/lava_scheduler_app/job_sidebar.html	2013-01-02 19:27:56 +0000
+++ lava_scheduler_app/templates/lava_scheduler_app/job_sidebar.html	2013-01-15 17:44:36 +0000
@@ -84,18 +84,26 @@ 
 
 </ul>
 {% if show_cancel or show_failure %}
-<h2>Actions</h2>
+<h2>Job Actions</h2>
 {% if show_cancel %}
 <form method="POST"
       action="{% url lava.scheduler.job.cancel job.pk %}">
   {% csrf_token %}
-  <button id="cancel-button">Cancel Job</button>
+  <button id="cancel-button">Cancel</button>
+</form>
+{% endif %}
+{% if show_resubmit %}
+<form method="POST"
+      action="{% url lava.scheduler.job.resubmit job.pk %}">
+  {% csrf_token %}
+  <button>Re-submit</button>
 </form>
 {% endif %}
 {% if show_failure %}
-<ul>
- <li><a href="{% url lava.scheduler.job.annotate_failure job.pk %}">Annotate Failure</a></li>
-</ul>
+<form method="GET"
+      action="{% url lava.scheduler.job.annotate_failure job.pk %}">
+  <button>Annotate</button>
+</form>
 {% endif %}
 {% endif %}
 

=== modified file 'lava_scheduler_app/urls.py'
--- lava_scheduler_app/urls.py	2013-01-02 22:07:30 +0000
+++ lava_scheduler_app/urls.py	2013-01-15 17:44:36 +0000
@@ -87,6 +87,9 @@ 
     url(r'^job/(?P<pk>[0-9]+)/cancel$',
         'job_cancel',
         name='lava.scheduler.job.cancel'),
+    url(r'^job/(?P<pk>[0-9]+)/resubmit$',
+        'job_resubmit',
+        name='lava.scheduler.job.resubmit'),
     url(r'^job/(?P<pk>[0-9]+)/annotate_failure$',
         'job_annotate_failure',
         name='lava.scheduler.job.annotate_failure'),

=== modified file 'lava_scheduler_app/views.py'
--- lava_scheduler_app/views.py	2013-01-03 16:15:48 +0000
+++ lava_scheduler_app/views.py	2013-01-15 17:44:36 +0000
@@ -560,8 +560,9 @@ 
 
     data = {
         'job': job,
-        'show_cancel': job.status <= TestJob.RUNNING and job.can_cancel(request.user),
-        'show_failure': job.status > TestJob.COMPLETE and job.can_annotate(request.user),
+        'show_cancel': job.can_cancel(request.user),
+        'show_failure': job.can_annotate(request.user),
+        'show_resubmit': job.can_resubmit(request.user),
         'bread_crumb_trail': BreadCrumbTrail.leading_to(job_detail, pk=pk),
         'show_reload_page': job.status <= TestJob.RUNNING,
     }
@@ -728,6 +729,18 @@ 
             "you cannot cancel this job", content_type="text/plain")
 
 
+@post_only
+def job_resubmit(request, pk):
+    job = get_restricted_job(request.user, pk)
+    if job.can_resubmit(request.user):
+        definition = job.definition
+        job = TestJob.from_json_and_user(definition, request.user)
+        return redirect(job)
+    else:
+        return HttpResponseForbidden(
+            "you cannot re-submit this job", content_type="text/plain")
+
+
 class FailureForm(forms.ModelForm):
     class Meta:
         model = TestJob