author | Adrien Chauve <adrien.chauve@logilab.fr> |
Thu, 04 Mar 2010 09:43:16 +0100 | |
branch | stable |
changeset 4786 | df2a12bfbab6 |
parent 4262 | 83d245d33436 |
child 5041 | ebdab53b0c45 |
permissions | -rw-r--r-- |
0 | 1 |
"""Specific views for entities implementing IProgress |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2994
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1723
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__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
|
9 |
_ = unicode |
0 | 10 |
|
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
|
11 |
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
|
12 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
0 | 14 |
|
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
|
15 |
from cubicweb.utils import make_uid |
1132 | 16 |
from cubicweb.selectors import implements |
0 | 17 |
from cubicweb.interfaces import IProgress, IMileStone |
18 |
from cubicweb.schema import display_name |
|
984 | 19 |
from cubicweb.view import EntityView |
0 | 20 |
|
21 |
||
22 |
class ProgressTableView(EntityView): |
|
23 |
"""The progress table view is able to display progress information |
|
24 |
of any object implement IMileStone. |
|
25 |
||
26 |
The default layout is composoed of 7 columns : parent task, |
|
27 |
milestone, state, estimated date, cost, progressbar, and todo_by |
|
28 |
||
29 |
The view accepts an optional ``columns`` paramater that lets you |
|
30 |
remove or reorder some of those columns. |
|
31 |
||
32 |
To add new columns, you should extend this class, define a new |
|
33 |
``columns`` class attribute and implement corresponding |
|
34 |
build_COLNAME_cell methods |
|
35 |
||
36 |
header_for_COLNAME methods allow to customize header's label |
|
37 |
""" |
|
1723 | 38 |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
39 |
__regid__ = 'progress_table_view' |
0 | 40 |
title = _('task progression') |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
41 |
__select__ = implements(IMileStone) |
0 | 42 |
|
43 |
# default columns of the table |
|
1375
5f412bed692c
remove planned_delivery from ProgressTableView
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1346
diff
changeset
|
44 |
columns = (_('project'), _('milestone'), _('state'), _('eta_date'), |
0 | 45 |
_('cost'), _('progress'), _('todo_by')) |
46 |
||
47 |
||
48 |
def call(self, columns=None): |
|
49 |
"""displays all versions in a table""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
50 |
self._cw.add_css('cubicweb.iprogress.css') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
51 |
_ = self._cw._ |
0 | 52 |
self.columns = columns or self.columns |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
53 |
ecls = self._cw.vreg['etypes'].etype_class(self.cw_rset.description[0][0]) |
0 | 54 |
self.w(u'<table class="progress">') |
55 |
self.table_header(ecls) |
|
56 |
self.w(u'<tbody>') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
57 |
for row in xrange(self.cw_rset.rowcount): |
0 | 58 |
self.cell_call(row=row, col=0) |
59 |
self.w(u'</tbody>') |
|
60 |
self.w(u'</table>') |
|
61 |
||
62 |
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
|
63 |
_ = self._cw._ |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
64 |
entity = self.cw_rset.get_entity(row, col) |
0 | 65 |
infos = {} |
66 |
for col in self.columns: |
|
67 |
meth = getattr(self, 'build_%s_cell' % col, None) |
|
68 |
# find the build method or try to find matching attribute |
|
69 |
if meth: |
|
70 |
content = meth(entity) |
|
71 |
else: |
|
72 |
content = entity.printable_value(col) |
|
73 |
infos[col] = content |
|
74 |
if hasattr(entity, 'progress_class'): |
|
75 |
cssclass = entity.progress_class() |
|
76 |
else: |
|
77 |
cssclass = u'' |
|
78 |
self.w(u"""<tr class="%s" onmouseover="addElementClass(this, 'highlighted');" |
|
79 |
onmouseout="removeElementClass(this, 'highlighted')">""" % cssclass) |
|
80 |
line = u''.join(u'<td>%%(%s)s</td>' % col for col in self.columns) |
|
81 |
self.w(line % infos) |
|
82 |
self.w(u'</tr>\n') |
|
83 |
||
84 |
## header management ###################################################### |
|
85 |
||
86 |
def header_for_project(self, ecls): |
|
87 |
"""use entity's parent type as label""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
88 |
return display_name(self._cw, ecls.parent_type) |
0 | 89 |
|
90 |
def header_for_milestone(self, ecls): |
|
91 |
"""use entity's type as label""" |
|
4262
83d245d33436
we should access to __regid__ instead of id since in that case bw compat fail: access to id throuhg a class returns the property object instead of calling the property's method
Stephanie Marcu
parents:
4252
diff
changeset
|
92 |
return display_name(self._cw, ecls.__regid__) |
1723 | 93 |
|
0 | 94 |
def table_header(self, ecls): |
95 |
"""builds the table's header""" |
|
96 |
self.w(u'<thead><tr>') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
97 |
_ = self._cw._ |
0 | 98 |
for column in self.columns: |
99 |
meth = getattr(self, 'header_for_%s' % column, None) |
|
100 |
if meth: |
|
101 |
colname = meth(ecls) |
|
102 |
else: |
|
103 |
colname = _(column) |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
104 |
self.w(u'<th>%s</th>' % xml_escape(colname)) |
0 | 105 |
self.w(u'</tr></thead>\n') |
106 |
||
1723 | 107 |
|
0 | 108 |
## cell management ######################################################## |
109 |
def build_project_cell(self, entity): |
|
110 |
"""``project`` column cell renderer""" |
|
111 |
project = entity.get_main_task() |
|
112 |
if project: |
|
113 |
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
|
114 |
return self._cw._('no related project') |
0 | 115 |
|
116 |
def build_milestone_cell(self, entity): |
|
117 |
"""``milestone`` column cell renderer""" |
|
118 |
return entity.view('incontext') |
|
119 |
||
120 |
def build_state_cell(self, entity): |
|
121 |
"""``state`` column cell renderer""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
122 |
return xml_escape(self._cw._(entity.state)) |
1723 | 123 |
|
0 | 124 |
def build_eta_date_cell(self, entity): |
125 |
"""``eta_date`` column cell renderer""" |
|
126 |
if entity.finished(): |
|
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
127 |
return self._cw.format_date(entity.completion_date()) |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
128 |
formated_date = self._cw.format_date(entity.initial_prevision_date()) |
0 | 129 |
if entity.in_progress(): |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
130 |
eta_date = self._cw.format_date(entity.eta_date()) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
131 |
_ = self._cw._ |
0 | 132 |
if formated_date: |
133 |
formated_date += u' (%s %s)' % (_('expected:'), eta_date) |
|
134 |
else: |
|
135 |
formated_date = u'%s %s' % (_('expected:'), eta_date) |
|
136 |
return formated_date |
|
1346
38b2cf1b0bb8
add planned delivery column
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1124
diff
changeset
|
137 |
|
0 | 138 |
def build_todo_by_cell(self, entity): |
139 |
"""``todo_by`` column cell renderer""" |
|
140 |
return u', '.join(p.view('outofcontext') for p in entity.contractors()) |
|
141 |
||
142 |
def build_cost_cell(self, entity): |
|
143 |
"""``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
|
144 |
_ = self._cw._ |
0 | 145 |
pinfo = entity.progress_info() |
146 |
totalcost = pinfo.get('estimatedcorrected', pinfo['estimated']) |
|
147 |
missing = pinfo.get('notestimatedcorrected', pinfo.get('notestimated', 0)) |
|
148 |
costdescr = [] |
|
149 |
if missing: |
|
150 |
# XXX: link to unestimated entities |
|
151 |
costdescr.append(_('%s not estimated') % missing) |
|
152 |
estimated = pinfo['estimated'] |
|
153 |
if estimated and estimated != totalcost: |
|
154 |
costdescr.append(_('initial estimation %s') % estimated) |
|
155 |
if costdescr: |
|
156 |
return u'%s (%s)' % (totalcost, ', '.join(costdescr)) |
|
157 |
return unicode(totalcost) |
|
1723 | 158 |
|
0 | 159 |
def build_progress_cell(self, entity): |
160 |
"""``progress`` column cell renderer""" |
|
4211
eac4b23a42ff
[views] backport progressbar template from shingouz
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3460
diff
changeset
|
161 |
return entity.view('progressbar') |
0 | 162 |
|
163 |
||
164 |
class InContextProgressTableView(ProgressTableView): |
|
165 |
"""this views redirects to ``progress_table_view`` but removes |
|
166 |
the ``project`` column |
|
167 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
168 |
__regid__ = 'ic_progress_table_view' |
1723 | 169 |
|
2994
88c578819ac1
why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2670
diff
changeset
|
170 |
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
|
171 |
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
|
172 |
rset=self.cw_rset) |
2994
88c578819ac1
why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2670
diff
changeset
|
173 |
columns = list(columns or view.columns) |
0 | 174 |
try: |
175 |
columns.remove('project') |
|
176 |
except ValueError: |
|
177 |
self.info('[ic_progress_table_view] could not remove project from columns') |
|
1723 | 178 |
view.render(w=self.w, columns=columns) |
0 | 179 |
|
180 |
||
181 |
class ProgressBarView(EntityView): |
|
182 |
"""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
|
183 |
__regid__ = 'progressbar' |
0 | 184 |
title = _('progress bar') |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
185 |
__select__ = implements(IProgress) |
0 | 186 |
|
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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
|
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
192 |
@classmethod |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
193 |
def overrun(cls, entity): |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
194 |
"""overrun = done + todo - """ |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
195 |
if entity.done + entity.todo > entity.revised_cost: |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
196 |
overrun = entity.done + entity.todo - entity.revised_cost |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
197 |
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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
|
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
203 |
@classmethod |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
204 |
def overrun_percentage(cls, entity): |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
205 |
"""pourcentage overrun = overrun / budget""" |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
206 |
if entity.revised_cost == 0: |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
207 |
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
|
208 |
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
|
209 |
return cls.overrun(entity) * 100. / entity.revised_cost |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
210 |
|
0 | 211 |
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
|
212 |
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
|
213 |
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
|
214 |
entity = self.cw_rset.get_entity(row, col) |
4786
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
215 |
done = entity.done |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
216 |
todo = entity.todo |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
217 |
budget = entity.revised_cost |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
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
|
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.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
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
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
|
232 |
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
|
233 |
pourcent = 0 |
0 | 234 |
|
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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
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
|
243 |
|
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
244 |
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
|
245 |
short_title = title |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
246 |
if self.overrun_percentage(entity): |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
247 |
title += u' overrun +%sj (+%i%%)' % (self.overrun(entity), |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
248 |
self.overrun_percentage(entity)) |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
249 |
overrun = self.overrun(entity) |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
250 |
if floor(overrun) == overrun or overrun>100: |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
251 |
overrun_str = '%i' % overrun |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
252 |
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
|
253 |
overrun_str = '%.1f' % overrun |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
254 |
short_title += u' +%s' % overrun_str |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
255 |
# 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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
|
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
260 |
cid = make_uid('progress_bar') |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
261 |
self._cw.html_headers.add_onload('draw_progressbar("canvas%s", %i, %i, %i, "%s");' % |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
262 |
(cid, |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
263 |
int(100.*done/maxi), int(100.*(done+todo)/maxi), |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
264 |
int(100.*budget/maxi), color), |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
265 |
jsoncall=self._cw.json_request) |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
266 |
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
|
267 |
u'<canvas class="progressbar" id="canvas%s" width="100" height="10"></canvas>' |
df2a12bfbab6
[fix] #731915 use add_onload instead of plain <script> tag for progress bar.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4262
diff
changeset
|
268 |
% (short_title.replace(' ',' '), cid)) |