Commit 165551f7 authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

port to cw 3.9

parent b4430eeb88a1
......@@ -44,7 +44,7 @@ for dname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'i18n'
# them to be included in the debian package
__depends_cubes__ = {'similarity': None, }
__depends__ = {'cubicweb': '>= 3.6.0'}
__depends__ = {'cubicweb': '>= 3.9.0'}
__use__ = ()
__recommend__ = ()
__recommends_cubes__ = {}
......
# -*- shell-script -*-
###############################################################################
#
# put here information about external resources used by your components,
# or to overides existing external resources configuration
#
###############################################################################
# CSS stylesheets to include in HTML headers
# uncomment the line below to use template specific stylesheet
# STYLESHEETS = DATADIR/cubes.classifiedad.css
BLUE_ARROW = DATADIR/blue_arrow.png
\ No newline at end of file
from cubes.similarity import reset_similarity
from cubicweb.server.hook import Hook
from cubicweb.selectors import implements
from cubicweb.selectors import is_instance
class ClassifiedAdAttributeHook(Hook):
__regid__ = 'classifiedad_attribute_hook'
events = ('after_add_entity', 'after_update_entity', 'after_delete_entity')
__select__ = Hook.__select__ & implements('ClassifiedAd')
__select__ = Hook.__select__ & is_instance('ClassifiedAd')
def __call__(self):
reset_similarity('ClassifiedAd')
......
BLUE_ARROW = data('blue_arrow.png')
\ No newline at end of file
......@@ -8,7 +8,7 @@
from logilab.mtconverter import xml_escape
from cubicweb.selectors import has_related_entities, implements
from cubicweb.selectors import has_related_entities, is_instance
from cubicweb.web import uicfg, component, box
from cubicweb.web.views import primary, baseviews
......@@ -27,7 +27,7 @@ uicfg.actionbox_appearsin_addmenu.tag_subject_of(('ClassifiedAd', 'has_image', '
class ExternalUriComponent(component.EntityVComponent):
"""component to display link to external uri"""
__regid__ = 'externaluricomp'
__select__ = (component.EntityVComponent.__select__ & has_related_entities('same_as') & ~implements('ExternalUri'))
__select__ = (component.EntityVComponent.__select__ & has_related_entities('same_as') & ~is_instance('ExternalUri'))
context = 'ctxtoolbar'
......@@ -37,7 +37,7 @@ class ExternalUriComponent(component.EntityVComponent):
def cell_call(self, row, col, view=None):
entity = self.cw_rset.get_entity(row, col)
self.w(u'<div class="toolbarButton" id="%s">' % self.div_id())
imgurl = self._cw.external_resource('BLUE_ARROW')
imgurl = self._cw.uiprops['BLUE_ARROW']
if hasattr(entity, 'url'):
url = entity.url
else:
......@@ -49,21 +49,21 @@ class ExternalUriComponent(component.EntityVComponent):
class ExternalUriGallery(baseviews.EntityView):
__regid__ = 'gallery'
title = _('gallery')
__select__ = implements('ExternalUri')
__select__ = is_instance('ExternalUri')
def call(self):
for entity in self.cw_rset.entities():
self.w(u'<img style="max-height: 100px; padding: 2px" src="%s" />' % entity.uri)
class ClassifiedAdPrimaryView(primary.PrimaryView):
__select__ = primary.PrimaryView.__select__ & implements('ClassifiedAd')
__select__ = primary.PrimaryView.__select__ & is_instance('ClassifiedAd')
def render_entity_relations(self, entity):
super(ClassifiedAdPrimaryView, self).render_entity_relations(entity)
self.wview('gallery', entity.related('has_image'), 'null')
class ClassifiedAdInContextView(baseviews.SameETypeListItemView):
__select__ = implements('ClassifiedAd')
__select__ = is_instance('ClassifiedAd')
def cell_call(self, row, col, contexteid=None):
entity = self.cw_rset.get_entity(row, col)
......@@ -89,18 +89,18 @@ class ClassifiedAdInContextView(baseviews.SameETypeListItemView):
# class ClassifiedPriceFacet(RangeFacet):
# __regid__ = 'classified-price-facet'
# __select__ = RangeFacet.__select__ & implements('ClassifiedAd')
# __select__ = RangeFacet.__select__ & is_instance('ClassifiedAd')
# rtype = 'price'
# class ClassifiedPubDateFacet(DateRangeFacet):
# __regid__ = 'classified-publication_date-facet'
# __select__ = DateRangeFacet.__select__ & implements('ClassifiedAd')
# __select__ = DateRangeFacet.__select__ & is_instance('ClassifiedAd')
# rtype = 'publication_date'
class ProximityOfAds(baseviews.EntityView):
__regid__ = 'proximity-of-ads'
title = _('proximity of ads')
__select__ = implements('ClassifiedAd')
__select__ = is_instance('ClassifiedAd')
def call(self):
self.w(u'<table><tr><th width="50%%">%s</th><th>%s</th></tr>' %
......@@ -117,7 +117,7 @@ class ProximityOfAds(baseviews.EntityView):
class ClosestAdsBox(box.EntityBoxTemplate):
__regid__ = 'closest_ads_box'
__select__ = box.EntityBoxTemplate.__select__ & implements('ClassifiedAd',)
__select__ = box.EntityBoxTemplate.__select__ & is_instance('ClassifiedAd',)
order = 25
def cell_call(self, row, col, **kwargs):
......@@ -134,22 +134,3 @@ class ClosestAdsBox(box.EntityBoxTemplate):
self.w(u'</div>')
self.w(u'</div>')
self.w(u'</div>')
class ClassifiedAdSimilarView(baseviews.EntityView):
__regid__ = 'similar-ads'
title = _('similar ads')
__select__ = implements('ClassifiedAd')
def call(self):
from cubes.classifiedad import entities
entities.update_proximity_cache(self._cw)
for row, ad in enumerate(self.cw_rset.entities()):
vector = entities.vspace.tfidf_by_id(ad.eid)
self.w(xml_escape(unicode(repr(sorted(vector, reverse=True, key=lambda x: x[1])))))
self.w(u'<hr />'+xml_escape(unicode(repr(sorted(entities.VSM.words)))))
self.w(u'<hr />'+xml_escape(unicode(repr(sorted(word for word in entities.VSM.words if len(word) < 3)))))
self.w(u'<ul>')
scores = ad.closest_ads()
for score, eid in scores:
self.w(u'<li>%s - %s</li>' % (score, self._cw.entity_from_eid(eid).view('outofcontext')))
self.w(u'</ul>')
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