author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 07 Oct 2009 13:52:36 +0200 | |
branch | stable |
changeset 3592 | 4c08780e54ed |
parent 2994 | 88c578819ac1 |
child 3023 | 7864fee8b4ec |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
"""Specific views for entities implementing IProgress |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1723
diff
changeset
|
4 |
:copyright: 2001-2009 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 |
|
0 | 37 |
id = 'progress_table_view' |
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""" |
|
48 |
self.req.add_css('cubicweb.iprogress.css') |
|
49 |
_ = self.req._ |
|
50 |
self.columns = columns or self.columns |
|
2670
4747145ff69c
[vreg] api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
51 |
ecls = self.vreg['etypes'].etype_class(self.rset.description[0][0]) |
0 | 52 |
self.w(u'<table class="progress">') |
53 |
self.table_header(ecls) |
|
54 |
self.w(u'<tbody>') |
|
55 |
for row in xrange(self.rset.rowcount): |
|
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): |
|
61 |
_ = self.req._ |
|
62 |
entity = self.entity(row, col) |
|
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""" |
|
86 |
return display_name(self.req, ecls.parent_type) |
|
87 |
||
88 |
def header_for_milestone(self, ecls): |
|
89 |
"""use entity's type as label""" |
|
90 |
return display_name(self.req, ecls.id) |
|
1723 | 91 |
|
0 | 92 |
def table_header(self, ecls): |
93 |
"""builds the table's header""" |
|
94 |
self.w(u'<thead><tr>') |
|
95 |
_ = self.req._ |
|
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') |
|
112 |
return self.req._('no related project') |
|
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""" |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
120 |
return xml_escape(self.req._(entity.state)) |
1723 | 121 |
|
0 | 122 |
def build_eta_date_cell(self, entity): |
123 |
"""``eta_date`` column cell renderer""" |
|
124 |
if entity.finished(): |
|
125 |
return self.format_date(entity.completion_date()) |
|
126 |
formated_date = self.format_date(entity.initial_prevision_date()) |
|
127 |
if entity.in_progress(): |
|
128 |
eta_date = self.format_date(entity.eta_date()) |
|
129 |
_ = self.req._ |
|
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""" |
|
142 |
_ = self.req._ |
|
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""" |
|
159 |
progress = u'<div class="progress_data">%s (%.2f%%)</div>' % ( |
|
160 |
entity.done, entity.progress()) |
|
161 |
return progress + entity.view('progressbar') |
|
162 |
||
163 |
||
164 |
class InContextProgressTableView(ProgressTableView): |
|
165 |
"""this views redirects to ``progress_table_view`` but removes |
|
166 |
the ``project`` column |
|
167 |
""" |
|
168 |
id = '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): |
2670
4747145ff69c
[vreg] api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
171 |
view = self.vreg['views'].select('progress_table_view', self.req, |
4747145ff69c
[vreg] api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
172 |
rset=self.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""" |
|
183 |
id = 'progressbar' |
|
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 |
|
187 |
def cell_call(self, row, col): |
|
188 |
self.req.add_css('cubicweb.iprogress.css') |
|
189 |
entity = self.entity(row, col) |
|
190 |
widget = ProgressBarWidget(entity.done, entity.todo, |
|
191 |
entity.revised_cost) |
|
192 |
self.w(widget.render()) |
|
193 |