1d0825bca7fe65beaee391d30da42e937db621564Steve Block# Copyright (C) 2009 Google Inc. All rights reserved.
2231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#
3231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# Redistribution and use in source and binary forms, with or without
4231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# modification, are permitted provided that the following conditions are
5231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# met:
6231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#
7231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#     * Redistributions of source code must retain the above copyright
8231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# notice, this list of conditions and the following disclaimer.
9231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#     * Redistributions in binary form must reproduce the above
10231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# copyright notice, this list of conditions and the following disclaimer
11231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# in the documentation and/or other materials provided with the
12231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# distribution.
13231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#     * Neither the name of Google Inc. nor the names of its
14231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# contributors may be used to endorse or promote products derived from
15231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# this software without specific prior written permission.
16231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#
17231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
296c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsenimport operator
306c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
31d0825bca7fe65beaee391d30da42e937db621564Steve Blockfrom google.appengine.ext import webapp
32d0825bca7fe65beaee391d30da42e937db621564Steve Blockfrom google.appengine.ext.webapp import template
33231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
34d0825bca7fe65beaee391d30da42e937db621564Steve Blockfrom model.attachment import Attachment
35a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochfrom model.queues import Queue
366c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
37231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
38d0825bca7fe65beaee391d30da42e937db621564Steve Blockclass Dashboard(webapp.RequestHandler):
39a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    # We may want to sort these?
40a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    _ordered_queues = Queue.all()
41a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    _header_names = [queue.short_name() for queue in _ordered_queues]
42d0825bca7fe65beaee391d30da42e937db621564Steve Block
43a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    def _build_bubble(self, attachment, queue):
44a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        queue_status = attachment.status_for_queue(queue)
456c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        bubble = {
466c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen            "status_class": attachment.state_from_queue_status(queue_status) if queue_status else "none",
476c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen            "status_date": queue_status.date if queue_status else None,
486c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        }
496c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        return bubble
506c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
516c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    def _build_row(self, attachment):
526c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        row = {
536c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen            "bug_id": attachment.bug_id(),
546c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen            "attachment_id": attachment.id,
55a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch            "bubbles": [self._build_bubble(attachment, queue) for queue in self._ordered_queues],
566c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        }
576c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        return row
586c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
596c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    def get(self):
60d0825bca7fe65beaee391d30da42e937db621564Steve Block        template_values = {
616c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen            "headers": self._header_names,
626c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen            "rows": [self._build_row(attachment) for attachment in Attachment.recent(limit=25)],
63d0825bca7fe65beaee391d30da42e937db621564Steve Block        }
64d0825bca7fe65beaee391d30da42e937db621564Steve Block        self.response.out.write(template.render("templates/dashboard.html", template_values))
65