1 # Copyright (C) 2011 Google Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 from urllib import unquote_plus
31 from google.appengine.ext import webapp
32 from google.appengine.ext.webapp import template
33 from django.utils import simplejson
35 from model.queueentry import QueueEntry
38 class QueueHandler(webapp.RequestHandler):
39 def get(self, builder_name):
40 self._get(unquote_plus(builder_name))
42 def post(self, builder_name):
43 self._post(unquote_plus(builder_name))
45 def _queued_test_names(self, builder_name):
46 return [entry.test for entry in QueueEntry.entries_for_builder(builder_name)]
48 def _queue_list_url(self, builder_name):
49 return '/builder/%s/queue' % builder_name
52 class QueueEdit(QueueHandler):
53 def _get(self, builder_name):
54 test_names = self._queued_test_names(builder_name)
55 self.response.out.write(
56 template.render("templates/builder-queue-edit.html", {
57 'builder_name': builder_name,
58 'queued_test_names': simplejson.dumps(test_names),
62 class QueueAdd(QueueHandler):
63 def _post(self, builder_name):
64 current_tests = set(self._queued_test_names(builder_name))
65 tests = set(self.request.get_all('test')).difference(current_tests)
68 QueueEntry.add(builder_name, test)
70 self.redirect(self._queue_list_url(builder_name))
73 class QueueRemove(QueueHandler):
74 def _post(self, builder_name):
75 tests = self.request.get_all('test')
78 QueueEntry.remove(builder_name, test)
80 self.redirect(self._queue_list_url(builder_name))
83 class QueueHtml(QueueHandler):
84 def _get(self, builder_name):
85 self.response.out.write(
86 template.render("templates/builder-queue-list.html", {
87 'builder_name': builder_name,
88 'entries': QueueEntry.entries_for_builder(builder_name),
92 class QueueJson(QueueHandler):
93 def _get(self, builder_name):
94 queue_json = {'tests': self._queued_test_names(builder_name)}
95 self.response.out.write(simplejson.dumps(queue_json))