author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 15 Feb 2010 18:44:47 +0100 | |
changeset 4587 | 70d47389630c |
parent 4262 | 83d245d33436 |
child 4786 | df2a12bfbab6 |
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 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
11 |
from logilab.mtconverter import xml_escape |
0 | 12 |
|
1132 | 13 |
from cubicweb.selectors import implements |
0 | 14 |
from cubicweb.interfaces import IProgress, IMileStone |
15 |
from cubicweb.schema import display_name |
|
984 | 16 |
from cubicweb.view import EntityView |
0 | 17 |
from cubicweb.web.htmlwidgets import ProgressBarWidget |
18 |
||
19 |
||
20 |
class ProgressTableView(EntityView): |
|
21 |
"""The progress table view is able to display progress information |
|
22 |
of any object implement IMileStone. |
|
23 |
||
24 |
The default layout is composoed of 7 columns : parent task, |
|
25 |
milestone, state, estimated date, cost, progressbar, and todo_by |
|
26 |
||
27 |
The view accepts an optional ``columns`` paramater that lets you |
|
28 |
remove or reorder some of those columns. |
|
29 |
||
30 |
To add new columns, you should extend this class, define a new |
|
31 |
``columns`` class attribute and implement corresponding |
|
32 |
build_COLNAME_cell methods |
|
33 |
||
34 |
header_for_COLNAME methods allow to customize header's label |
|
35 |
""" |
|
1723 | 36 |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
37 |
__regid__ = 'progress_table_view' |
0 | 38 |
title = _('task progression') |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
39 |
__select__ = implements(IMileStone) |
0 | 40 |
|
41 |
# default columns of the table |
|
1375
5f412bed692c
remove planned_delivery from ProgressTableView
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1346
diff
changeset
|
42 |
columns = (_('project'), _('milestone'), _('state'), _('eta_date'), |
0 | 43 |
_('cost'), _('progress'), _('todo_by')) |
44 |
||
45 |
||
46 |
def call(self, columns=None): |
|
47 |
"""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
|
48 |
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
|
49 |
_ = self._cw._ |
0 | 50 |
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
|
51 |
ecls = self._cw.vreg['etypes'].etype_class(self.cw_rset.description[0][0]) |
0 | 52 |
self.w(u'<table class="progress">') |
53 |
self.table_header(ecls) |
|
54 |
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
|
55 |
for row in xrange(self.cw_rset.rowcount): |
0 | 56 |
self.cell_call(row=row, col=0) |
57 |
self.w(u'</tbody>') |
|
58 |
self.w(u'</table>') |
|
59 |
||
60 |
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
|
61 |
_ = self._cw._ |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
62 |
entity = self.cw_rset.get_entity(row, col) |
0 | 63 |
infos = {} |
64 |
for col in self.columns: |
|
65 |
meth = getattr(self, 'build_%s_cell' % col, None) |
|
66 |
# find the build method or try to find matching attribute |
|
67 |
if meth: |
|
68 |
content = meth(entity) |
|
69 |
else: |
|
70 |
content = entity.printable_value(col) |
|
71 |
infos[col] = content |
|
72 |
if hasattr(entity, 'progress_class'): |
|
73 |
cssclass = entity.progress_class() |
|
74 |
else: |
|
75 |
cssclass = u'' |
|
76 |
self.w(u"""<tr class="%s" onmouseover="addElementClass(this, 'highlighted');" |
|
77 |
onmouseout="removeElementClass(this, 'highlighted')">""" % cssclass) |
|
78 |
line = u''.join(u'<td>%%(%s)s</td>' % col for col in self.columns) |
|
79 |
self.w(line % infos) |
|
80 |
self.w(u'</tr>\n') |
|
81 |
||
82 |
## header management ###################################################### |
|
83 |
||
84 |
def header_for_project(self, ecls): |
|
85 |
"""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
|
86 |
return display_name(self._cw, ecls.parent_type) |
0 | 87 |
|
88 |
def header_for_milestone(self, ecls): |
|
89 |
"""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
|
90 |
return display_name(self._cw, ecls.__regid__) |
1723 | 91 |
|
0 | 92 |
def table_header(self, ecls): |
93 |
"""builds the table's header""" |
|
94 |
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
|
95 |
_ = self._cw._ |
0 | 96 |
for column in self.columns: |
97 |
meth = getattr(self, 'header_for_%s' % column, None) |
|
98 |
if meth: |
|
99 |
colname = meth(ecls) |
|
100 |
else: |
|
101 |
colname = _(column) |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
102 |
self.w(u'<th>%s</th>' % xml_escape(colname)) |
0 | 103 |
self.w(u'</tr></thead>\n') |
104 |
||
1723 | 105 |
|
0 | 106 |
## cell management ######################################################## |
107 |
def build_project_cell(self, entity): |
|
108 |
"""``project`` column cell renderer""" |
|
109 |
project = entity.get_main_task() |
|
110 |
if project: |
|
111 |
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
|
112 |
return self._cw._('no related project') |
0 | 113 |
|
114 |
def build_milestone_cell(self, entity): |
|
115 |
"""``milestone`` column cell renderer""" |
|
116 |
return entity.view('incontext') |
|
117 |
||
118 |
def build_state_cell(self, entity): |
|
119 |
"""``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
|
120 |
return xml_escape(self._cw._(entity.state)) |
1723 | 121 |
|
0 | 122 |
def build_eta_date_cell(self, entity): |
123 |
"""``eta_date`` column cell renderer""" |
|
124 |
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
|
125 |
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
|
126 |
formated_date = self._cw.format_date(entity.initial_prevision_date()) |
0 | 127 |
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
|
128 |
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
|
129 |
_ = self._cw._ |
0 | 130 |
if formated_date: |
131 |
formated_date += u' (%s %s)' % (_('expected:'), eta_date) |
|
132 |
else: |
|
133 |
formated_date = u'%s %s' % (_('expected:'), eta_date) |
|
134 |
return formated_date |
|
1346
38b2cf1b0bb8
add planned delivery column
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1124
diff
changeset
|
135 |
|
0 | 136 |
def build_todo_by_cell(self, entity): |
137 |
"""``todo_by`` column cell renderer""" |
|
138 |
return u', '.join(p.view('outofcontext') for p in entity.contractors()) |
|
139 |
||
140 |
def build_cost_cell(self, entity): |
|
141 |
"""``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
|
142 |
_ = self._cw._ |
0 | 143 |
pinfo = entity.progress_info() |
144 |
totalcost = pinfo.get('estimatedcorrected', pinfo['estimated']) |
|
145 |
missing = pinfo.get('notestimatedcorrected', pinfo.get('notestimated', 0)) |
|
146 |
costdescr = [] |
|
147 |
if missing: |
|
148 |
# XXX: link to unestimated entities |
|
149 |
costdescr.append(_('%s not estimated') % missing) |
|
150 |
estimated = pinfo['estimated'] |
|
151 |
if estimated and estimated != totalcost: |
|
152 |
costdescr.append(_('initial estimation %s') % estimated) |
|
153 |
if costdescr: |
|
154 |
return u'%s (%s)' % (totalcost, ', '.join(costdescr)) |
|
155 |
return unicode(totalcost) |
|
1723 | 156 |
|
0 | 157 |
def build_progress_cell(self, entity): |
158 |
"""``progress`` column cell renderer""" |
|
4211
eac4b23a42ff
[views] backport progressbar template from shingouz
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3460
diff
changeset
|
159 |
return entity.view('progressbar') |
0 | 160 |
|
161 |
||
162 |
class InContextProgressTableView(ProgressTableView): |
|
163 |
"""this views redirects to ``progress_table_view`` but removes |
|
164 |
the ``project`` column |
|
165 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
166 |
__regid__ = 'ic_progress_table_view' |
1723 | 167 |
|
2994
88c578819ac1
why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2670
diff
changeset
|
168 |
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
|
169 |
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
|
170 |
rset=self.cw_rset) |
2994
88c578819ac1
why not columns, too ?
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2670
diff
changeset
|
171 |
columns = list(columns or view.columns) |
0 | 172 |
try: |
173 |
columns.remove('project') |
|
174 |
except ValueError: |
|
175 |
self.info('[ic_progress_table_view] could not remove project from columns') |
|
1723 | 176 |
view.render(w=self.w, columns=columns) |
0 | 177 |
|
178 |
||
179 |
class ProgressBarView(EntityView): |
|
180 |
"""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
|
181 |
__regid__ = 'progressbar' |
0 | 182 |
title = _('progress bar') |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
183 |
__select__ = implements(IProgress) |
0 | 184 |
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
entity = self.cw_rset.get_entity(row, col) |
0 | 189 |
widget = ProgressBarWidget(entity.done, entity.todo, |
190 |
entity.revised_cost) |
|
191 |
self.w(widget.render()) |
|
192 |