Commit b3d4bb23 authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

[views] add sidebox with most similar ads

parent a7b640b37d4f
......@@ -10,7 +10,7 @@ from logilab.mtconverter import xml_escape
from cubicweb.selectors import has_related_entities, implements
from cubicweb.web import uicfg, component
from cubicweb.web import uicfg, component, box
from cubicweb.web.views import primary, baseviews
from cubicweb.web.facet import RelationFacet, AttributeFacet, RangeFacet, DateRangeFacet
......@@ -105,3 +105,20 @@ class ProximityOfAds(baseviews.EntityView):
self.w(u'</ul></td></tr>')
self.w(u'</table>')
class ClosestAdsBox(box.EntityBoxTemplate):
__regid__ = 'closest_ads_box'
__select__ = box.EntityBoxTemplate.__select__ & implements('ClassifiedAd',)
order = 25
def cell_call(self, row, col, **kwargs):
entity = self.cw_rset.get_entity(row, col)
scores = entity.closest_ads()
if scores:
self.w(u'<div class="sideBox">')
self.w(u'<div class="sideBoxTitle"><span>%s</span></div>' % 'Similar ads')
self.w(u'<div class="%s"><div class="sideBoxBody">' % 'sideBox')
for score, eid in scores[:5]:
self.w(u'<span>%s - %s</span><br />' % (score, self._cw.entity_from_eid(eid).view('outofcontext')))
self.w(u'</div>')
self.w(u'</div>')
self.w(u'</div>')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment