258 rdefs.append( (rschema, matchtschemas, role, dispctrl) ) |
257 rdefs.append( (rschema, matchtschemas, role, dispctrl) ) |
259 return sorted(rdefs, key=lambda x: x[-1]['order']) |
258 return sorted(rdefs, key=lambda x: x[-1]['order']) |
260 |
259 |
261 def _relation_rset(self, entity, rschema, role, dispctrl): |
260 def _relation_rset(self, entity, rschema, role, dispctrl): |
262 try: |
261 try: |
263 dispctrl.setdefault('limit', self.maxrelated) |
262 rset = entity.related(rschema.type, role) |
264 rset = entity.related(rschema.type, role, limit=dispctrl['limit']+1) |
|
265 except Unauthorized: |
263 except Unauthorized: |
266 return |
264 return |
267 if 'filter' in dispctrl: |
265 if 'filter' in dispctrl: |
268 rset = dispctrl['filter'](rset) |
266 rset = dispctrl['filter'](rset) |
269 return rset |
267 return rset |
293 return label |
291 return label |
294 return u'' |
292 return u'' |
295 |
293 |
296 |
294 |
297 class RelatedView(EntityView): |
295 class RelatedView(EntityView): |
|
296 """Display a rset, usually containing entities linked to another entity |
|
297 being displayed. |
|
298 |
|
299 It will try to display nicely according to the number of items in the result |
|
300 set. |
|
301 """ |
298 __regid__ = 'autolimited' |
302 __regid__ = 'autolimited' |
299 |
303 |
300 def call(self, **kwargs): |
304 def call(self, **kwargs): |
301 # nb: rset is retreived using entity.related with limit + 1 if any. |
|
302 # Because of that, we know that rset.printable_rql() will return rql |
|
303 # with no limit set anyway (since it's handled manually) |
|
304 if 'dispctrl' in self.cw_extra_kwargs: |
305 if 'dispctrl' in self.cw_extra_kwargs: |
305 limit = self.cw_extra_kwargs['dispctrl'].get('limit') |
306 if 'limit' in self.cw_extra_kwargs['dispctrl']: |
|
307 limit = self.cw_extra_kwargs['dispctrl']['limit'] |
|
308 else: |
|
309 limit = self._cw.property_value('navigation.related-limit') |
|
310 list_limit = self.cw_extra_kwargs['dispctrl'].get('use_list_limit', 5) |
306 subvid = self.cw_extra_kwargs['dispctrl'].get('subvid', 'incontext') |
311 subvid = self.cw_extra_kwargs['dispctrl'].get('subvid', 'incontext') |
307 else: |
312 else: |
308 limit = None |
313 limit = list_limit = None |
309 subvid = 'incontext' |
314 subvid = 'incontext' |
310 if limit is None or self.cw_rset.rowcount <= limit: |
315 if limit is None or self.cw_rset.rowcount <= limit: |
311 if self.cw_rset.rowcount == 1: |
316 if self.cw_rset.rowcount == 1: |
312 self.wview(subvid, self.cw_rset, row=0) |
317 self.wview(subvid, self.cw_rset, row=0) |
313 elif 1 < self.cw_rset.rowcount <= 5: |
318 elif list_limit is None or 1 < self.cw_rset.rowcount <= list_limit: |
314 self.wview('csv', self.cw_rset, subvid=subvid) |
319 self.wview('csv', self.cw_rset, subvid=subvid) |
315 else: |
320 else: |
316 self.w(u'<div>') |
321 self.w(u'<div>') |
317 self.wview('simplelist', self.cw_rset, subvid=subvid) |
322 self.wview('simplelist', self.cw_rset, subvid=subvid) |
318 self.w(u'</div>') |
323 self.w(u'</div>') |
319 # else show links to display related entities |
324 # else show links to display related entities |
320 else: |
325 else: |
321 rql = self.cw_rset.printable_rql() |
326 rql = self.cw_rset.printable_rql() |
322 self.cw_rset.limit(limit) # remove extra entity |
327 self.cw_rset.limit(limit) # remove extra entity |
323 self.w(u'<div>') |
328 if list_limit is None: |
324 self.wview('simplelist', self.cw_rset, subvid=subvid) |
329 self.wview('csv', self.cw_rset, subvid=subvid) |
325 self.w(u'[<a href="%s">%s</a>]' % ( |
330 self.w(u'[<a href="%s">%s</a>]' % ( |
326 xml_escape(self._cw.build_url(rql=rql, vid=subvid)), |
331 xml_escape(self._cw.build_url(rql=rql, vid=subvid)), |
327 self._cw._('see them all'))) |
332 self._cw._('see them all'))) |
328 self.w(u'</div>') |
333 else: |
|
334 self.w(u'<div>') |
|
335 self.wview('simplelist', self.cw_rset, subvid=subvid) |
|
336 self.w(u'[<a href="%s">%s</a>]' % ( |
|
337 xml_escape(self._cw.build_url(rql=rql, vid=subvid)), |
|
338 self._cw._('see them all'))) |
|
339 self.w(u'</div>') |
329 |
340 |
330 |
341 |
331 class URLAttributeView(EntityView): |
342 class URLAttributeView(EntityView): |
332 """use this view for attributes whose value is an url and that you want |
343 """use this view for attributes whose value is an url and that you want |
333 to display as clickable link |
344 to display as clickable link |