web/views/iprogress.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 01 Jun 2010 08:34:35 +0200
changeset 5611 55366f5b7a9f
parent 5556 9ab2b4c74baf
child 5722 61d6a4caa963
permissions -rw-r--r--
cleanups
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/>.
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
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    25
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
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
    27
from cubicweb.utils import make_uid
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    28
from cubicweb.selectors import implements, adaptable
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
from cubicweb.interfaces import IProgress, IMileStone
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
from cubicweb.schema import display_name
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    31
from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat
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
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    35
class IProgressAdapter(EntityAdapter):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    36
    """something that has a cost, a state and a progression.
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    37
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    38
    You should at least override progress_info an in_progress methods on concret
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    39
    implementations.
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    40
    """
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    41
    __regid__ = 'IProgress'
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    42
    __select__ = implements(IProgress) # XXX for bw compat, should be abstract
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    43
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    44
    @property
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    45
    @implements_adapter_compat('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    46
    def cost(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    47
        """the total cost"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    48
        return self.progress_info()['estimated']
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    49
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    50
    @property
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    51
    @implements_adapter_compat('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    52
    def revised_cost(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    53
        return self.progress_info().get('estimatedcorrected', self.cost)
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    54
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    55
    @property
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    56
    @implements_adapter_compat('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    57
    def done(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    58
        """what is already done"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    59
        return self.progress_info()['done']
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    60
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    61
    @property
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    62
    @implements_adapter_compat('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    63
    def todo(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    64
        """what remains to be done"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    65
        return self.progress_info()['todo']
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    66
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    67
    @implements_adapter_compat('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    68
    def progress_info(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    69
        """returns a dictionary describing progress/estimated cost of the
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    70
        version.
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    71
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    72
        - mandatory keys are (''estimated', 'done', 'todo')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    73
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    74
        - optional keys are ('notestimated', 'notestimatedcorrected',
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    75
          'estimatedcorrected')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    76
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    77
        'noestimated' and 'notestimatedcorrected' should default to 0
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    78
        'estimatedcorrected' should default to 'estimated'
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    79
        """
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    80
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    81
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    82
    @implements_adapter_compat('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    83
    def finished(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    84
        """returns True if status is finished"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    85
        return not self.in_progress()
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    86
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    87
    @implements_adapter_compat('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    88
    def in_progress(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    89
        """returns True if status is not finished"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    90
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    91
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    92
    @implements_adapter_compat('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    93
    def progress(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    94
        """returns the % progress of the task item"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    95
        try:
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    96
            return 100. * self.done / self.revised_cost
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    97
        except ZeroDivisionError:
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    98
            # total cost is 0 : if everything was estimated, task is completed
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    99
            if self.progress_info().get('notestimated'):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   100
                return 0.
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   101
            return 100
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   102
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   103
    @implements_adapter_compat('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   104
    def progress_class(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   105
        return ''
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   106
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   107
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   108
class IMileStoneAdapter(IProgressAdapter):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   109
    __regid__ = 'IMileStone'
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   110
    __select__ = implements(IMileStone) # XXX for bw compat, should be abstract
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   111
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   112
    parent_type = None # specify main task's type
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   113
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   114
    @implements_adapter_compat('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   115
    def get_main_task(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   116
        """returns the main ITask entity"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   117
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   118
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   119
    @implements_adapter_compat('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   120
    def initial_prevision_date(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   121
        """returns the initial expected end of the milestone"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   122
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   123
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   124
    @implements_adapter_compat('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   125
    def eta_date(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   126
        """returns expected date of completion based on what remains
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   127
        to be done
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   128
        """
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   129
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   130
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   131
    @implements_adapter_compat('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   132
    def completion_date(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   133
        """returns date on which the subtask has been completed"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   134
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   135
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   136
    @implements_adapter_compat('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   137
    def contractors(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   138
        """returns the list of persons supposed to work on this task"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   139
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   140
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   141
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5178
diff changeset
   142
class ProgressTableView(EntityAttributesTableView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
    """The progress table view is able to display progress information
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
    of any object implement IMileStone.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
    The default layout is composoed of 7 columns : parent task,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
    milestone, state, estimated date, cost, progressbar, and todo_by
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
    The view accepts an optional ``columns`` paramater that lets you
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
    remove or reorder some of those columns.
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
    To add new columns, you should extend this class, define a new
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
    ``columns`` class attribute and implement corresponding
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
    build_COLNAME_cell methods
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
    header_for_COLNAME methods allow to customize header's label
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
    """
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   158
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   159
    __regid__ = 'progress_table_view'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   160
    __select__ = adaptable('IMileStone')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
    title = _('task progression')
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5178
diff changeset
   162
    table_css = "progress"
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5178
diff changeset
   163
    css_files = ('cubicweb.iprogress.css',)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
    # default columns of the table
1375
5f412bed692c remove planned_delivery from ProgressTableView
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1346
diff changeset
   166
    columns = (_('project'), _('milestone'), _('state'), _('eta_date'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
               _('cost'), _('progress'), _('todo_by'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
    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
   170
        _ = self._cw._
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   171
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
        infos = {}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
        for col in self.columns:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
            meth = getattr(self, 'build_%s_cell' % col, None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
            # find the build method or try to find matching attribute
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
            if meth:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
                content = meth(entity)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
                content = entity.printable_value(col)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
            infos[col] = content
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   181
        cssclass = entity.cw_adapt_to('IMileStone').progress_class()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
        self.w(u"""<tr class="%s" onmouseover="addElementClass(this, 'highlighted');"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
            onmouseout="removeElementClass(this, 'highlighted')">""" % cssclass)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
        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
   185
        self.w(line % infos)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
        self.w(u'</tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
    ## header management ######################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   190
    def header_for_project(self, sample):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
        """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
   192
        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
   193
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   194
    def header_for_milestone(self, sample):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
        """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
   196
        return display_name(self._cw, sample.__regid__)
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   197
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
    ## cell management ########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
    def build_project_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
        """``project`` column cell renderer"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   201
        project = entity.cw_adapt_to('IMileStone').get_main_task()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
        if project:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
            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
   204
        return self._cw._('no related project')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
    def build_milestone_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
        """``milestone`` column cell renderer"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
        return entity.view('incontext')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
    def build_state_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
        """``state`` column cell renderer"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   212
        return xml_escape(entity.cw_adapt_to('IWorkflowable').printable_state)
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   213
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
    def build_eta_date_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
        """``eta_date`` column cell renderer"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   216
        imilestone = entity.cw_adapt_to('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   217
        if imilestone.finished():
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   218
            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
   219
        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
   220
        if imilestone.in_progress():
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   221
            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
   222
            _ = self._cw._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
            if formated_date:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
                formated_date += u' (%s %s)' % (_('expected:'), eta_date)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
                formated_date = u'%s %s' % (_('expected:'), eta_date)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
        return formated_date
1346
38b2cf1b0bb8 add planned delivery column
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1124
diff changeset
   228
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
    def build_todo_by_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
        """``todo_by`` column cell renderer"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   231
        imilestone = entity.cw_adapt_to('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   232
        return u', '.join(p.view('outofcontext') for p in imilestone.contractors())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
    def build_cost_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
        """``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
   236
        _ = self._cw._
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   237
        imilestone = entity.cw_adapt_to('IMileStone')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   238
        pinfo = imilestone.progress_info()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
        totalcost = pinfo.get('estimatedcorrected', pinfo['estimated'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
        missing = pinfo.get('notestimatedcorrected', pinfo.get('notestimated', 0))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
        costdescr = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
        if missing:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
            # XXX: link to unestimated entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
            costdescr.append(_('%s not estimated') % missing)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
        estimated = pinfo['estimated']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
        if estimated and estimated != totalcost:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   247
            costdescr.append(_('initial estimation %s') % estimated)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
        if costdescr:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   249
            return u'%s (%s)' % (totalcost, ', '.join(costdescr))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   250
        return unicode(totalcost)
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   251
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
    def build_progress_cell(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
        """``progress`` column cell renderer"""
4211
eac4b23a42ff [views] backport progressbar template from shingouz
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3460
diff changeset
   254
        return entity.view('progressbar')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
class InContextProgressTableView(ProgressTableView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   258
    """this views redirects to ``progress_table_view`` but removes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
    the ``project`` column
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3023
diff changeset
   261
    __regid__ = 'ic_progress_table_view'
1723
30c3a713ab61 View.dispatch -> View.render
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   262
2994
88c578819ac1 why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2670
diff changeset
   263
    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
   264
        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
   265
                                         rset=self.cw_rset)
2994
88c578819ac1 why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2670
diff changeset
   266
        columns = list(columns or view.columns)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
            columns.remove('project')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
        except ValueError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   270
            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
   271
        view.render(w=self.w, columns=columns)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
class ProgressBarView(EntityView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
    """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
   276
    __regid__ = 'progressbar'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   277
    __select__ = adaptable('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   278
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   279
    title = _('progress bar')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   280
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
   281
    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
   282
    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
   283
    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
   284
    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
   285
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   286
    @classmethod
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   287
    def overrun(cls, iprogress):
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
   288
        """overrun = done + todo - """
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   289
        if iprogress.done + iprogress.todo > iprogress.revised_cost:
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   290
            overrun = iprogress.done + iprogress.todo - iprogress.revised_cost
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
   291
        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
   292
            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
   293
        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
   294
            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
   295
        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
   296
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   297
    @classmethod
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   298
    def overrun_percentage(cls, iprogress):
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
   299
        """pourcentage overrun = overrun / budget"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   300
        if iprogress.revised_cost == 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
   301
            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
   302
        else:
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   303
            return cls.overrun(iprogress) * 100. / iprogress.revised_cost
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
   304
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
    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
   306
        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
   307
        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
   308
        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
   309
        iprogress = entity.cw_adapt_to('IProgress')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   310
        done = iprogress.done
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   311
        todo = iprogress.todo
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   312
        budget = iprogress.revised_cost
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
   313
        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
   314
            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
   315
        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
   316
            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
   317
        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
   318
            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
   319
        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
   320
            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
   321
        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
   322
            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
   323
        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
   324
            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
   325
        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
   326
            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
   327
        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
   328
            pourcent = 0
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
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
   330
        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
   331
            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
   332
        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
   333
            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
   334
        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
   335
            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
   336
        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
   337
            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
   338
df2a12bfbab6 [fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4262
diff changeset
   339
        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
   340
        short_title = title
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   341
        overrunpercent = self.overrun_percentage(iprogress)
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   342
        if overrunpercent:
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   343
            overrun = self.overrun(iprogress)
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   344
            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
   345
            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
   346
                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
   347
            else:
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   348
                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
   349
        # 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
   350
        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
   351
        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
   352
            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
   353
        cid = make_uid('progress_bar')
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   354
        self._cw.html_headers.add_onload(
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   355
            '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
   356
            (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
   357
             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
   358
        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
   359
               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
   360
               % (xml_escape(short_title), cid))