web/views/iprogress.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 28 Oct 2011 11:33:26 +0200
changeset 8037 a36bd56f33bb
parent 7475 a70456bbb4bd
child 8038 678d22a56ab6
permissions -rw-r--r--
[diet] move iprogress to its own cube. Closes #1916016
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8037
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
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
     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/>.
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    18
"""Specific views for entities implementing IProgress/IMileStone"""
0
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
__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
    21
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
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
    23
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
    24
8037
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
    25
from logilab.common.deprecation import class_deprecated
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
5722
61d6a4caa963 [iprogress] move adapter to entities.adapters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5611
diff changeset
    29
from cubicweb.selectors import adaptable
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
from cubicweb.schema import display_name
5722
61d6a4caa963 [iprogress] move adapter to entities.adapters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5611
diff changeset
    31
from cubicweb.view import EntityView
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5178
diff changeset
    32
from cubicweb.web.views.tableview import EntityAttributesTableView
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    34
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5178
diff changeset
    35
class ProgressTableView(EntityAttributesTableView):
0
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
    """
8037
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
    51
    __metaclass__ = class_deprecated
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
    52
    __deprecation_warning__ = '[3.14] %(cls)s is deprecated'
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
    53
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
    54
    __regid__ = 'progress_table_view'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    55
    __select__ = adaptable('IMileStone')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
    title = _('task progression')
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5178
diff changeset
    57
    table_css = "progress"
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5178
diff changeset
    58
    css_files = ('cubicweb.iprogress.css',)
0
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
    # default columns of the table
1375
5f412bed692c remove planned_delivery from ProgressTableView
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1346
diff changeset
    61
    columns = (_('project'), _('milestone'), _('state'), _('eta_date'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
               _('cost'), _('progress'), _('todo_by'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
    def cell_call(self, row, col):
8037
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
    65
        x
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    66
        _ = self._cw._
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    67
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
        infos = {}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        for col in self.columns:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
            meth = getattr(self, 'build_%s_cell' % col, None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
            # find the build method or try to find matching attribute
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
            if meth:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
                content = meth(entity)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
                content = entity.printable_value(col)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
            infos[col] = content
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    77
        cssclass = entity.cw_adapt_to('IMileStone').progress_class()
5727
29afb9e715bb [3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5722
diff changeset
    78
        self.w(u"""<tr class="%s" onmouseover="$(this).addClass('highlighted');"
29afb9e715bb [3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5722
diff changeset
    79
            onmouseout="$(this).removeClass('highlighted')">""" % cssclass)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
        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
    81
        self.w(line % infos)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
        self.w(u'</tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    ## header management ######################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    86
    def header_for_project(self, sample):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
        """use entity's parent type as label"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    88
        return display_name(self._cw, sample.cw_adapt_to('IMileStone').parent_type)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    90
    def header_for_milestone(self, sample):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
        """use entity's type as label"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    92
        return display_name(self._cw, sample.__regid__)
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
    93
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
    ## cell management ########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
    def build_project_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
        """``project`` column cell renderer"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    97
        project = entity.cw_adapt_to('IMileStone').get_main_task()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
        if project:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
            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
   100
        return self._cw._('no related project')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    def build_milestone_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        """``milestone`` column cell renderer"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        return entity.view('incontext')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    def build_state_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
        """``state`` column cell renderer"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   108
        return xml_escape(entity.cw_adapt_to('IWorkflowable').printable_state)
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   109
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
    def build_eta_date_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        """``eta_date`` column cell renderer"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   112
        imilestone = entity.cw_adapt_to('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   113
        if imilestone.finished():
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   114
            return self._cw.format_date(imilestone.completion_date())
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   115
        formated_date = self._cw.format_date(imilestone.initial_prevision_date())
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   116
        if imilestone.in_progress():
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   117
            eta_date = self._cw.format_date(imilestone.eta_date())
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   118
            _ = self._cw._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
            if formated_date:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
                formated_date += u' (%s %s)' % (_('expected:'), eta_date)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
                formated_date = u'%s %s' % (_('expected:'), eta_date)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        return formated_date
1346
38b2cf1b0bb8 add planned delivery column
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1124
diff changeset
   124
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
    def build_todo_by_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        """``todo_by`` column cell renderer"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   127
        imilestone = entity.cw_adapt_to('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   128
        return u', '.join(p.view('outofcontext') for p in imilestone.contractors())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
    def build_cost_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
        """``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
   132
        _ = self._cw._
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   133
        imilestone = entity.cw_adapt_to('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   134
        pinfo = imilestone.progress_info()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        totalcost = pinfo.get('estimatedcorrected', pinfo['estimated'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
        missing = pinfo.get('notestimatedcorrected', pinfo.get('notestimated', 0))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
        costdescr = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
        if missing:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
            # XXX: link to unestimated entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
            costdescr.append(_('%s not estimated') % missing)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
        estimated = pinfo['estimated']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
        if estimated and estimated != totalcost:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
            costdescr.append(_('initial estimation %s') % estimated)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
        if costdescr:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
            return u'%s (%s)' % (totalcost, ', '.join(costdescr))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
        return unicode(totalcost)
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   147
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
    def build_progress_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
        """``progress`` column cell renderer"""
4211
eac4b23a42ff [views] backport progressbar template from shingouz
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3460
diff changeset
   150
        return entity.view('progressbar')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
class InContextProgressTableView(ProgressTableView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
    """this views redirects to ``progress_table_view`` but removes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
    the ``project`` column
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
    """
8037
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
   157
    __metaclass__ = class_deprecated
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
   158
    __deprecation_warning__ = '[3.14] %(cls)s is deprecated'
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   159
    __regid__ = 'ic_progress_table_view'
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   160
2994
88c578819ac1 why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2670
diff changeset
   161
    def call(self, columns=None):
8037
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
   162
        x
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   163
        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
   164
                                         rset=self.cw_rset)
2994
88c578819ac1 why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2670
diff changeset
   165
        columns = list(columns or view.columns)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
            columns.remove('project')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        except ValueError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
            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
   170
        view.render(w=self.w, columns=columns)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
class ProgressBarView(EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
    """displays a progress bar"""
8037
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
   175
    __metaclass__ = class_deprecated
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
   176
    __deprecation_warning__ = '[3.14] %(cls)s is deprecated'
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   177
    __regid__ = 'progressbar'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   178
    __select__ = adaptable('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   179
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
    title = _('progress bar')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
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
   182
    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
   183
    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
   184
    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
   185
    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
   186
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   187
    @classmethod
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   188
    def overrun(cls, iprogress):
6496
21bbb561809b [iprogress] None resilience
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5727
diff changeset
   189
        done = iprogress.done or 0
21bbb561809b [iprogress] None resilience
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5727
diff changeset
   190
        todo = iprogress.todo or 0
7475
a70456bbb4bd [views/iprogress] rename to make things easier to read and understand
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6496
diff changeset
   191
        budget = iprogress.revised_cost or 0
a70456bbb4bd [views/iprogress] rename to make things easier to read and understand
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6496
diff changeset
   192
        if done + todo > budget:
a70456bbb4bd [views/iprogress] rename to make things easier to read and understand
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6496
diff changeset
   193
            overrun = done + todo - budget
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
   194
        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
   195
            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
   196
        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
   197
            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
   198
        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
   199
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
    @classmethod
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   201
    def overrun_percentage(cls, iprogress):
7475
a70456bbb4bd [views/iprogress] rename to make things easier to read and understand
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6496
diff changeset
   202
        budget = iprogress.revised_cost or 0
a70456bbb4bd [views/iprogress] rename to make things easier to read and understand
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6496
diff changeset
   203
        if budget == 0:
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
   204
            return 0
7475
a70456bbb4bd [views/iprogress] rename to make things easier to read and understand
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6496
diff changeset
   205
        return cls.overrun(iprogress) * 100. / budget
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
   206
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
    def cell_call(self, row, col):
8037
a36bd56f33bb [diet] move iprogress to its own cube. Closes #1916016
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7475
diff changeset
   208
        x
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   209
        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
   210
        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
   211
        entity = self.cw_rset.get_entity(row, col)
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   212
        iprogress = entity.cw_adapt_to('IProgress')
6496
21bbb561809b [iprogress] None resilience
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5727
diff changeset
   213
        done = iprogress.done or 0
21bbb561809b [iprogress] None resilience
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5727
diff changeset
   214
        todo = iprogress.todo or 0
21bbb561809b [iprogress] None resilience
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5727
diff changeset
   215
        budget = iprogress.revised_cost or 0
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
   216
        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
   217
            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
   218
        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
   219
            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
   220
        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
   221
            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
   222
        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
   223
            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
   224
        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
   225
            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
   226
        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
   227
            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
   228
        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
   229
            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
   230
        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
   231
            pourcent = 0
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
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
   233
        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
   234
            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
   235
        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
   236
            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
   237
        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
   238
            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
   239
        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
   240
            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
   241
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
        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
   243
        short_title = title
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   244
        overrunpercent = self.overrun_percentage(iprogress)
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   245
        if overrunpercent:
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   246
            overrun = self.overrun(iprogress)
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   247
            title += u' overrun +%sj (+%i%%)' % (overrun, overrunpercent)
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   248
            if floor(overrun) == overrun or overrun > 100:
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   249
                short_title += u' +%i' % overrun
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
   250
            else:
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   251
                short_title += u' +%.1f' % overrun
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
   252
        # 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
   253
        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
   254
        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
   255
            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
   256
        cid = make_uid('progress_bar')
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   257
        self._cw.html_headers.add_onload(
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   258
            'draw_progressbar("canvas%s", %i, %i, %i, "%s");' %
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   259
            (cid, int(100.*done/maxi), int(100.*(done+todo)/maxi),
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   260
             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
   261
        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
   262
               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
   263
               % (xml_escape(short_title), cid))