173 rdefs.append( (rschema, matchtschemas, role, dispctrl) ) |
173 rdefs.append( (rschema, matchtschemas, role, dispctrl) ) |
174 return sorted(rdefs, key=lambda x: x[-1]['order']) |
174 return sorted(rdefs, key=lambda x: x[-1]['order']) |
175 |
175 |
176 def _relation_rset(self, entity, rschema, role, dispctrl): |
176 def _relation_rset(self, entity, rschema, role, dispctrl): |
177 try: |
177 try: |
178 if dispctrl.get('limit'): |
178 dispctrl.setdefault('limit', self.maxrelated) |
179 rset = entity.related(rschema.type, role, |
179 rset = entity.related(rschema.type, role, limit=dispctrl['limit']+1) |
180 limit=self.maxrelated+1) |
|
181 else: |
|
182 rset = entity.related(rschema.type, role) |
|
183 except Unauthorized: |
180 except Unauthorized: |
184 return |
181 return |
185 if 'filter' in dispctrl: |
182 if 'filter' in dispctrl: |
186 rset = dispctrl['filter'](rset) |
183 rset = dispctrl['filter'](rset) |
187 return rset |
184 return rset |
188 |
185 |
189 def _render_relation(self, rset, dispctrl, defaultvid, showlabel): |
186 def _render_relation(self, rset, dispctrl, defaultvid, showlabel): |
190 self.w(u'<div class="section">') |
187 self.w(u'<div class="section">') |
191 if showlabel: |
188 if showlabel: |
192 self.w(u'<h4>%s</h4>' % self.req._(dispctrl['label'])) |
189 self.w(u'<h4>%s</h4>' % self.req._(dispctrl['label'])) |
193 self.wview(dispctrl.get('vid', defaultvid), rset) |
190 self.wview(dispctrl.get('vid', defaultvid), rset, dispctrl=dispctrl) |
194 self.w(u'</div>') |
191 self.w(u'</div>') |
195 |
192 |
196 def _render_attribute(self, rschema, value, role='subject'): |
193 def _render_attribute(self, rschema, value, role='subject'): |
197 if rschema.is_final(): |
194 if rschema.is_final(): |
198 show_label = self.show_attr_label |
195 show_label = self.show_attr_label |
202 self.field(label, value, show_label=show_label, tr=False) |
199 self.field(label, value, show_label=show_label, tr=False) |
203 |
200 |
204 |
201 |
205 class RelatedView(EntityView): |
202 class RelatedView(EntityView): |
206 id = 'autolimited' |
203 id = 'autolimited' |
207 def call(self, title=None, **kwargs): |
204 |
|
205 def call(self, dispctrl=None, **kwargs): |
|
206 # nb: rset retreived using entity.related with limit + 1 if any |
|
207 # because of that, we known that rset.printable_rql() will return |
|
208 # rql with no limit set anyway (since it's handled manually) |
|
209 if dispctrl is not None: |
|
210 limit = dispctrl.get('limit') |
208 # if not too many entities, show them all in a list |
211 # if not too many entities, show them all in a list |
209 maxrelated = self.req.property_value('navigation.related-limit') |
212 if limit is None or self.rset.rowcount <= limit: |
210 if title: |
|
211 self.w(u'<div class="title"><span>%s</span></div>' % title) |
|
212 if self.rset.rowcount <= maxrelated: |
|
213 if self.rset.rowcount == 1: |
213 if self.rset.rowcount == 1: |
214 self.wview('incontext', self.rset, row=0) |
214 self.wview('incontext', self.rset, row=0) |
215 elif 1 < self.rset.rowcount <= 5: |
215 elif 1 < self.rset.rowcount <= 5: |
216 self.wview('csv', self.rset) |
216 self.wview('csv', self.rset) |
217 else: |
217 else: |
218 self.w(u'<div>') |
218 self.w(u'<div>') |
219 self.wview('simplelist', self.rset) |
219 self.wview('simplelist', self.rset) |
220 self.w(u'</div>') |
220 self.w(u'</div>') |
221 # else show links to display related entities |
221 # else show links to display related entities |
222 else: |
222 else: |
223 rql = self.rset.printable_rql() |
223 rql = rset.printable_rql() |
224 self.rset.limit(maxrelated) |
224 self.rset.limit(limit) # remove extra entity |
225 self.w(u'<div>') |
225 self.w(u'<div>') |
226 self.wview('simplelist', self.rset) |
226 self.wview('simplelist', self.rset) |
227 self.w(u'[<a href="%s">%s</a>]' % (self.build_url(rql=rql), |
227 self.w(u'[<a href="%s">%s</a>]' % (self.build_url(rql=rql), |
228 self.req._('see them all'))) |
228 self.req._('see them all'))) |
229 self.w(u'</div>') |
229 self.w(u'</div>') |