1209 else: |
1209 else: |
1210 self.wview(cellvid or 'outofcontext', self.cw_rset, row=row, col=col) |
1210 self.wview(cellvid or 'outofcontext', self.cw_rset, row=row, col=col) |
1211 else: |
1211 else: |
1212 # XXX why do we need a fallback view here? |
1212 # XXX why do we need a fallback view here? |
1213 self.wview(cellvid or 'final', self.cw_rset, 'null', row=row, col=col) |
1213 self.wview(cellvid or 'final', self.cw_rset, 'null', row=row, col=col) |
1214 |
|
1215 |
|
1216 class InitialTableView(TableView): |
|
1217 """same display as table view but consider two rql queries : |
|
1218 |
|
1219 * the default query (ie `rql` form parameter), which is only used to select |
|
1220 this view and to build the filter form. This query should have the same |
|
1221 structure as the actual without actual restriction (but link to |
|
1222 restriction variables) and usually with a limit for efficiency (limit set |
|
1223 to 2 is advised) |
|
1224 |
|
1225 * the actual query (`actualrql` form parameter) whose results will be |
|
1226 displayed with default restrictions set |
|
1227 """ |
|
1228 __regid__ = 'initialtable' |
|
1229 __select__ = nonempty_rset() |
|
1230 # should not be displayed in possible view since it expects some specific |
|
1231 # parameters |
|
1232 title = None |
|
1233 |
|
1234 def call(self, title=None, subvid=None, headers=None, divid=None, |
|
1235 paginate=False, displaycols=None, displayactions=None, |
|
1236 mainindex=None): |
|
1237 """Dumps a table displaying a composite query""" |
|
1238 try: |
|
1239 actrql = self._cw.form['actualrql'] |
|
1240 except KeyError: |
|
1241 actrql = self.cw_rset.printable_rql() |
|
1242 else: |
|
1243 self._cw.ensure_ro_rql(actrql) |
|
1244 displaycols = self.displaycols(displaycols, headers) |
|
1245 if displayactions is None and 'displayactions' in self._cw.form: |
|
1246 displayactions = True |
|
1247 if divid is None and 'divid' in self._cw.form: |
|
1248 divid = self._cw.form['divid'] |
|
1249 self.w(u'<div class="section">') |
|
1250 if not title and 'title' in self._cw.form: |
|
1251 # pop title so it's not displayed by the table view as well |
|
1252 title = self._cw.form.pop('title') |
|
1253 if title: |
|
1254 self.w(u'<h2>%s</h2>\n' % title) |
|
1255 if mainindex is None: |
|
1256 mainindex = self.main_var_index() |
|
1257 if mainindex is not None: |
|
1258 actions = self.form_filter(divid, displaycols, displayactions, |
|
1259 displayfilter=True, paginate=paginate, |
|
1260 hidden=True) |
|
1261 else: |
|
1262 actions = () |
|
1263 if not subvid and 'subvid' in self._cw.form: |
|
1264 subvid = self._cw.form.pop('subvid') |
|
1265 self._cw.view('table', self._cw.execute(actrql), |
|
1266 'noresult', w=self.w, displayfilter=False, subvid=subvid, |
|
1267 displayactions=displayactions, displaycols=displaycols, |
|
1268 actions=actions, headers=headers, divid=divid) |
|
1269 self.w(u'</div>\n') |
|
1270 |
|
1271 |
|
1272 class EditableInitialTableTableView(InitialTableView): |
|
1273 __regid__ = 'editable-initialtable' |
|
1274 finalview = 'editable-final' |
|
1275 |
|
1276 |
|
1277 @add_metaclass(class_deprecated) |
|
1278 class EntityAttributesTableView(EntityView): |
|
1279 """This table displays entity attributes in a table and allow to set a |
|
1280 specific method to help building cell content for each attribute as well as |
|
1281 column header. |
|
1282 |
|
1283 Table will render entity cell by using the appropriate build_COLNAME_cell |
|
1284 methods if defined otherwise cell content will be entity.COLNAME. |
|
1285 |
|
1286 Table will render column header using the method header_for_COLNAME if |
|
1287 defined otherwise COLNAME will be used. |
|
1288 """ |
|
1289 __deprecation_warning__ = '[3.14] %(cls)s is deprecated' |
|
1290 __abstract__ = True |
|
1291 columns = () |
|
1292 table_css = "listing" |
|
1293 css_files = () |
|
1294 |
|
1295 def call(self, columns=None): |
|
1296 if self.css_files: |
|
1297 self._cw.add_css(self.css_files) |
|
1298 _ = self._cw._ |
|
1299 self.columns = columns or self.columns |
|
1300 sample = self.cw_rset.get_entity(0, 0) |
|
1301 self.w(u'<table class="%s">' % self.table_css) |
|
1302 self.table_header(sample) |
|
1303 self.w(u'<tbody>') |
|
1304 for row in range(self.cw_rset.rowcount): |
|
1305 self.cell_call(row=row, col=0) |
|
1306 self.w(u'</tbody>') |
|
1307 self.w(u'</table>') |
|
1308 |
|
1309 def cell_call(self, row, col): |
|
1310 _ = self._cw._ |
|
1311 entity = self.cw_rset.get_entity(row, col) |
|
1312 entity.complete() |
|
1313 infos = {} |
|
1314 for col in self.columns: |
|
1315 meth = getattr(self, 'build_%s_cell' % col, None) |
|
1316 # find the build method or try to find matching attribute |
|
1317 if meth: |
|
1318 content = meth(entity) |
|
1319 else: |
|
1320 content = entity.printable_value(col) |
|
1321 infos[col] = content |
|
1322 self.w(u"""<tr onmouseover="$(this).addClass('highlighted');" |
|
1323 onmouseout="$(this).removeClass('highlighted')">""") |
|
1324 line = u''.join(u'<td>%%(%s)s</td>' % col for col in self.columns) |
|
1325 self.w(line % infos) |
|
1326 self.w(u'</tr>\n') |
|
1327 |
|
1328 def table_header(self, sample): |
|
1329 """builds the table's header""" |
|
1330 self.w(u'<thead><tr>') |
|
1331 for column in self.columns: |
|
1332 meth = getattr(self, 'header_for_%s' % column, None) |
|
1333 if meth: |
|
1334 colname = meth(sample) |
|
1335 else: |
|
1336 colname = self._cw._(column) |
|
1337 self.w(u'<th>%s</th>' % xml_escape(colname)) |
|
1338 self.w(u'</tr></thead>\n') |
|