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

similar entities box moved to cube similarity

parent e60a4b7efaf7
......@@ -10,12 +10,12 @@ from logilab.mtconverter import xml_escape
from cubicweb.selectors import has_related_entities, is_instance
from cubicweb.web import uicfg, component, box
from cubicweb.web import uicfg, component
from cubicweb.web.views import primary, baseviews
from cubicweb.web.facet import RelationFacet, AttributeFacet, RangeFacet, DateRangeFacet
from cubes.similarity import get_vspace
from cubes.similarity.views import SimilarAction
from cubes.similarity.views import SimilarAction, SimilarEntitiesBox
uicfg.primaryview_section.tag_subject_of(('ClassifiedAd', 'same_as', '*'), 'hidden')
uicfg.primaryview_section.tag_subject_of(('ClassifiedAd', 'url', '*'), 'hidden')
......@@ -82,25 +82,9 @@ 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__ & is_instance('ClassifiedAd',)
order = 25
def cell_call(self, row, col, **kwargs):
entity = self.cw_rset.get_entity(row, col)
vspace = get_vspace('ClassifiedAd', self._cw)
scores = vspace.similarity_by_id(entity.eid)
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, eids in scores[:5]:
for eid in eids:
self.w(u'<span>%.2f - %s</span><br />' % (score, self._cw.entity_from_eid(eid).view('outofcontext')))
self.w(u'</div>')
self.w(u'</div>')
self.w(u'</div>')
class ClosestAdsBox(SimilarEntitiesBox):
__select__ = SimilarEntitiesBox.__select__ & is_instance('ClassifiedAd',)
etype = 'ClassifiedAd'
class ClassifiedAdSimilarAction(SimilarAction):
__select__ = is_instance('ClassifiedAd')
Markdown is supported
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