~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/QueueStatusServer/handlers/statusbubble.py

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Google Inc. All rights reserved.
 
2
#
 
3
# Redistribution and use in source and binary forms, with or without
 
4
# modification, are permitted provided that the following conditions are
 
5
# met:
 
6
 
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
 
12
# distribution.
 
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.
 
16
 
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.
 
28
 
 
29
import operator
 
30
 
 
31
from google.appengine.ext import webapp
 
32
from google.appengine.ext.webapp import template
 
33
 
 
34
from model.attachment import Attachment
 
35
from model.workitems import WorkItems
 
36
from model.queues import Queue
 
37
 
 
38
 
 
39
class StatusBubble(webapp.RequestHandler):
 
40
    def _build_bubble(self, queue, attachment, queue_position):
 
41
        queue_status = attachment.status_for_queue(queue)
 
42
        bubble = {
 
43
            "name": queue.short_name().lower(),
 
44
            "attachment_id": attachment.id,
 
45
            "queue_position": queue_position,
 
46
            "state": attachment.state_from_queue_status(queue_status) if queue_status else "none",
 
47
            "status": queue_status,
 
48
        }
 
49
        return bubble
 
50
 
 
51
    def _have_status_for(self, attachment, queue):
 
52
        # Any pending queue is shown.
 
53
        if attachment.position_in_queue(queue):
 
54
            return True
 
55
        # Complete ewses are also shown.
 
56
        return bool(queue.is_ews() and attachment.status_for_queue(queue))
 
57
 
 
58
    def _build_bubbles_for_attachment(self, attachment):
 
59
        show_submit_to_ews = True
 
60
        bubbles = []
 
61
        for queue in Queue.all():
 
62
            if not self._have_status_for(attachment, queue):
 
63
                continue
 
64
            queue_position = attachment.position_in_queue(queue)
 
65
            if queue_position and queue_position >= 100:
 
66
                # This queue is so far behind it's not even worth showing.
 
67
                continue
 
68
            bubbles.append(self._build_bubble(queue, attachment, queue_position))
 
69
            # If even one ews has status, we don't show the submit-to-ews button.
 
70
            if queue.is_ews():
 
71
                show_submit_to_ews = False
 
72
 
 
73
        return (bubbles, show_submit_to_ews)
 
74
 
 
75
    def get(self, attachment_id_string):
 
76
        attachment_id = int(attachment_id_string)
 
77
        attachment = Attachment(attachment_id)
 
78
        bubbles, show_submit_to_ews = self._build_bubbles_for_attachment(attachment)
 
79
 
 
80
        template_values = {
 
81
            "bubbles": bubbles,
 
82
            "attachment_id": attachment_id,
 
83
            "show_submit_to_ews": show_submit_to_ews,
 
84
        }
 
85
        self.response.out.write(template.render("templates/statusbubble.html", template_values))