web/views/iprogress.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 28 Apr 2010 12:15:52 +0200
brancholdstable
changeset 5424 8ecbcbff9777
parent 5421 8167de96c523
child 5426 0d4853a6e5ee
permissions -rw-r--r--
replace logilab-common by CubicWeb in disclaimer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5178
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
"""Specific views for entities implementing IProgress
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
__docformat__ = "restructuredtext en"
2058
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    22
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
4786
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
    24
from math import floor
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
    25
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    26
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
4786
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
    28
from cubicweb.utils import make_uid
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 984
diff changeset
    29
from cubicweb.selectors import implements
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
from cubicweb.interfaces import IProgress, IMileStone
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
from cubicweb.schema import display_name
984
536e421b082b import updates
sylvain.thenault@logilab.fr
parents: 728
diff changeset
    32
from cubicweb.view import EntityView
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
class ProgressTableView(EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
    """The progress table view is able to display progress information
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
    of any object implement IMileStone.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    The default layout is composoed of 7 columns : parent task,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
    milestone, state, estimated date, cost, progressbar, and todo_by
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    The view accepts an optional ``columns`` paramater that lets you
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
    remove or reorder some of those columns.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
    To add new columns, you should extend this class, define a new
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
    ``columns`` class attribute and implement corresponding
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
    build_COLNAME_cell methods
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
    header_for_COLNAME methods allow to customize header's label
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
    """
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
    51
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
    52
    __regid__ = 'progress_table_view'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
    title = _('task progression')
728
a95b284150d1 first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
    54
    __select__ = implements(IMileStone)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
    # default columns of the table
1375
5f412bed692c remove planned_delivery from ProgressTableView
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1346
diff changeset
    57
    columns = (_('project'), _('milestone'), _('state'), _('eta_date'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
               _('cost'), _('progress'), _('todo_by'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
    def call(self, columns=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        """displays all versions in a table"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    63
        self._cw.add_css('cubicweb.iprogress.css')
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    64
        _ = self._cw._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
        self.columns = columns or self.columns
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    66
        ecls = self._cw.vreg['etypes'].etype_class(self.cw_rset.description[0][0])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        self.w(u'<table class="progress">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
        self.table_header(ecls)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        self.w(u'<tbody>')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    70
        for row in xrange(self.cw_rset.rowcount):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
            self.cell_call(row=row, col=0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
        self.w(u'</tbody>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
        self.w(u'</table>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    76
        _ = self._cw._
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    77
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
        infos = {}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
        for col in self.columns:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
            meth = getattr(self, 'build_%s_cell' % col, None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
            # find the build method or try to find matching attribute
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
            if meth:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
                content = meth(entity)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
                content = entity.printable_value(col)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
            infos[col] = content
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
        if hasattr(entity, 'progress_class'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
            cssclass = entity.progress_class()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
            cssclass = u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
        self.w(u"""<tr class="%s" onmouseover="addElementClass(this, 'highlighted');"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
            onmouseout="removeElementClass(this, 'highlighted')">""" % cssclass)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        line = u''.join(u'<td>%%(%s)s</td>' % col for col in self.columns)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        self.w(line % infos)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
        self.w(u'</tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
    ## header management ######################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
    def header_for_project(self, ecls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
        """use entity's parent type as label"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   101
        return display_name(self._cw, ecls.parent_type)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
    def header_for_milestone(self, ecls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        """use entity's type as label"""
4262
83d245d33436 we should access to __regid__ instead of id since in that case bw compat fail: access to id throuhg a class returns the property object instead of calling the property's method
Stephanie Marcu
parents: 4252
diff changeset
   105
        return display_name(self._cw, ecls.__regid__)
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   106
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
    def table_header(self, ecls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        """builds the table's header"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
        self.w(u'<thead><tr>')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   110
        _ = self._cw._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        for column in self.columns:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
            meth = getattr(self, 'header_for_%s' % column, None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
            if meth:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
                colname = meth(ecls)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
                colname = _(column)
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   117
            self.w(u'<th>%s</th>' % xml_escape(colname))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
        self.w(u'</tr></thead>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   120
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
    ## cell management ########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
    def build_project_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        """``project`` column cell renderer"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
        project = entity.get_main_task()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
        if project:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
            return project.view('incontext')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   127
        return self._cw._('no related project')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
    def build_milestone_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        """``milestone`` column cell renderer"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
        return entity.view('incontext')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
    def build_state_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
        """``state`` column cell renderer"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   135
        return xml_escape(self._cw._(entity.state))
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   136
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
    def build_eta_date_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
        """``eta_date`` column cell renderer"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        if entity.finished():
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   140
            return self._cw.format_date(entity.completion_date())
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   141
        formated_date = self._cw.format_date(entity.initial_prevision_date())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
        if entity.in_progress():
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   143
            eta_date = self._cw.format_date(entity.eta_date())
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   144
            _ = self._cw._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
            if formated_date:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
                formated_date += u' (%s %s)' % (_('expected:'), eta_date)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
                formated_date = u'%s %s' % (_('expected:'), eta_date)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
        return formated_date
1346
38b2cf1b0bb8 add planned delivery column
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1124
diff changeset
   150
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
    def build_todo_by_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
        """``todo_by`` column cell renderer"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
        return u', '.join(p.view('outofcontext') for p in entity.contractors())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
    def build_cost_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        """``cost`` column cell renderer"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   157
        _ = self._cw._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
        pinfo = entity.progress_info()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
        totalcost = pinfo.get('estimatedcorrected', pinfo['estimated'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
        missing = pinfo.get('notestimatedcorrected', pinfo.get('notestimated', 0))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
        costdescr = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
        if missing:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
            # XXX: link to unestimated entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
            costdescr.append(_('%s not estimated') % missing)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
        estimated = pinfo['estimated']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
        if estimated and estimated != totalcost:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
            costdescr.append(_('initial estimation %s') % estimated)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        if costdescr:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
            return u'%s (%s)' % (totalcost, ', '.join(costdescr))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
        return unicode(totalcost)
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   171
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
    def build_progress_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
        """``progress`` column cell renderer"""
4211
eac4b23a42ff [views] backport progressbar template from shingouz
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3460
diff changeset
   174
        return entity.view('progressbar')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
class InContextProgressTableView(ProgressTableView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
    """this views redirects to ``progress_table_view`` but removes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
    the ``project`` column
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   181
    __regid__ = 'ic_progress_table_view'
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   182
2994
88c578819ac1 why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2670
diff changeset
   183
    def call(self, columns=None):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   184
        view = self._cw.vreg['views'].select('progress_table_view', self._cw,
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   185
                                         rset=self.cw_rset)
2994
88c578819ac1 why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2670
diff changeset
   186
        columns = list(columns or view.columns)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
            columns.remove('project')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
        except ValueError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
            self.info('[ic_progress_table_view] could not remove project from columns')
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   191
        view.render(w=self.w, columns=columns)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
class ProgressBarView(EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
    """displays a progress bar"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   196
    __regid__ = 'progressbar'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
    title = _('progress bar')
728
a95b284150d1 first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
   198
    __select__ = implements(IProgress)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
4786
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   200
    precision = 0.1
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   201
    red_threshold = 1.1
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   202
    orange_threshold = 1.05
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   203
    yellow_threshold = 1
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   204
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   205
    @classmethod
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   206
    def overrun(cls, entity):
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   207
        """overrun = done + todo - """
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   208
        if entity.done + entity.todo > entity.revised_cost:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   209
            overrun = entity.done + entity.todo - entity.revised_cost
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   210
        else:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   211
            overrun = 0
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   212
        if overrun < cls.precision:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   213
            overrun = 0
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   214
        return overrun
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   215
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   216
    @classmethod
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   217
    def overrun_percentage(cls, entity):
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   218
        """pourcentage overrun = overrun / budget"""
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   219
        if entity.revised_cost == 0:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   220
            return 0
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   221
        else:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   222
            return cls.overrun(entity) * 100. / entity.revised_cost
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   223
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
    def cell_call(self, row, col):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   225
        self._cw.add_css('cubicweb.iprogress.css')
4232
d9d031d68be2 more 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4211
diff changeset
   226
        self._cw.add_js('cubicweb.iprogress.js')
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   227
        entity = self.cw_rset.get_entity(row, col)
4786
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   228
        done = entity.done
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   229
        todo = entity.todo
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   230
        budget = entity.revised_cost
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   231
        if budget == 0:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   232
            pourcent = 100
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   233
        else:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   234
            pourcent = done*100./budget
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   235
        if pourcent > 100.1:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   236
            color = 'red'
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   237
        elif todo+done > self.red_threshold*budget:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   238
            color = 'red'
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   239
        elif todo+done > self.orange_threshold*budget:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   240
            color = 'orange'
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   241
        elif todo+done > self.yellow_threshold*budget:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   242
            color = 'yellow'
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   243
        else:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   244
            color = 'green'
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   245
        if pourcent < 0:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   246
            pourcent = 0
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   247
4786
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   248
        if floor(done) == done or done>100:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   249
            done_str = '%i' % done
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   250
        else:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   251
            done_str = '%.1f' % done
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   252
        if floor(budget) == budget or budget>100:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   253
            budget_str = '%i' % budget
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   254
        else:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   255
            budget_str = '%.1f' % budget
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   256
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   257
        title = u'%s/%s = %i%%' % (done_str, budget_str, pourcent)
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   258
        short_title = title
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   259
        if self.overrun_percentage(entity):
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   260
            title += u' overrun +%sj (+%i%%)' % (self.overrun(entity),
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   261
                                                 self.overrun_percentage(entity))
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   262
            overrun = self.overrun(entity)
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   263
            if floor(overrun) == overrun or overrun>100:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   264
                overrun_str = '%i' % overrun
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   265
            else:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   266
                overrun_str = '%.1f' % overrun
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   267
            short_title += u' +%s' % overrun_str
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   268
        # write bars
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   269
        maxi = max(done+todo, budget)
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   270
        if maxi == 0:
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   271
            maxi = 1
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   272
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   273
        cid = make_uid('progress_bar')
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   274
        self._cw.html_headers.add_onload('draw_progressbar("canvas%s", %i, %i, %i, "%s");' %
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   275
                                         (cid,
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   276
                                          int(100.*done/maxi), int(100.*(done+todo)/maxi),
5041
ebdab53b0c45 [cleanup] remove 3.7 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4786
diff changeset
   277
                                          int(100.*budget/maxi), color))
4786
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   278
        self.w(u'%s<br/>'
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   279
               u'<canvas class="progressbar" id="canvas%s" width="100" height="10"></canvas>'
5178
42285e33b01c [iprogress] use xml_escape instead of buggy replace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5041
diff changeset
   280
               % (xml_escape(short_title), cid))