263 |
263 |
264 class RelatedView(EntityView): |
264 class RelatedView(EntityView): |
265 __regid__ = 'autolimited' |
265 __regid__ = 'autolimited' |
266 |
266 |
267 def call(self, **kwargs): |
267 def call(self, **kwargs): |
268 # nb: rset retreived using entity.related with limit + 1 if any |
268 # nb: rset is retreived using entity.related with limit + 1 if any. |
269 # because of that, we known that rset.printable_rql() will return |
269 # Because of that, we know that rset.printable_rql() will return rql |
270 # rql with no limit set anyway (since it's handled manually) |
270 # with no limit set anyway (since it's handled manually) |
271 if 'dispctrl' in self.cw_extra_kwargs: |
271 if 'dispctrl' in self.cw_extra_kwargs: |
272 limit = self.cw_extra_kwargs['dispctrl'].get('limit') |
272 limit = self.cw_extra_kwargs['dispctrl'].get('limit') |
|
273 subvid = self.cw_extra_kwargs['dispctrl'].get('subvid', 'incontext') |
273 else: |
274 else: |
274 limit = None |
275 limit = None |
|
276 subvid = 'incontext' |
275 if limit is None or self.cw_rset.rowcount <= limit: |
277 if limit is None or self.cw_rset.rowcount <= limit: |
276 if self.cw_rset.rowcount == 1: |
278 if self.cw_rset.rowcount == 1: |
277 self.wview('incontext', self.cw_rset, row=0) |
279 self.wview(subvid, self.cw_rset, row=0) |
278 elif 1 < self.cw_rset.rowcount <= 5: |
280 elif 1 < self.cw_rset.rowcount <= 5: |
279 self.wview('csv', self.cw_rset) |
281 self.wview('csv', self.cw_rset, subvid=subvid) |
280 else: |
282 else: |
281 self.w(u'<div>') |
283 self.w(u'<div>') |
282 self.wview('simplelist', self.cw_rset) |
284 self.wview('simplelist', self.cw_rset, subvid=subvid) |
283 self.w(u'</div>') |
285 self.w(u'</div>') |
284 # else show links to display related entities |
286 # else show links to display related entities |
285 else: |
287 else: |
286 rql = self.cw_rset.printable_rql() |
288 rql = self.cw_rset.printable_rql() |
287 self.cw_rset.limit(limit) # remove extra entity |
289 self.cw_rset.limit(limit) # remove extra entity |
288 self.w(u'<div>') |
290 self.w(u'<div>') |
289 self.wview('simplelist', self.cw_rset) |
291 self.wview('simplelist', self.cw_rset, subvid=subvid) |
290 self.w(u'[<a href="%s">%s</a>]' % (self._cw.build_url(rql=rql), |
292 self.w(u'[<a href="%s">%s</a>]' % ( |
291 self._cw._('see them all'))) |
293 xml_escape(self._cw.build_url(rql=rql, vid=subvid)), |
|
294 self._cw._('see them all'))) |
292 self.w(u'</div>') |
295 self.w(u'</div>') |
293 |
296 |
294 |
297 |
295 class URLAttributeView(EntityView): |
298 class URLAttributeView(EntityView): |
296 """use this view for attributes whose value is an url and that you want |
299 """use this view for attributes whose value is an url and that you want |