def action_submit(self, action, data): """ """ obj = IClassifiable(self.context) subjects = obj.categories for subject in data["suggestions"]: if subject not in subjects: subjects.append(subject) obj.categories = subjects url = getMultiAdapter((self.context, self.request), name="absolute_url")() IStatusMessage(self.request).addStatusMessage(_(u"Categories saved."), type="info") self.request.response.redirect(url) return ""
def action_submit(self, action, data): """ """ obj = IClassifiable(self.context) subjects = obj.categories for subject in data['suggestions']: if subject not in subjects: subjects.append(subject) obj.categories = subjects url = getMultiAdapter((self.context, self.request), name='absolute_url')() IStatusMessage(self.request).addStatusMessage( _(u"Categories saved."), type="info") self.request.response.redirect(url) return ''
def _wrapClassifiable(obj): """Looks whether the object is adaptable to IClassifiable, and returns the wrapper""" if not IClassifiable.providedBy(obj): wrapper = queryAdapter(obj, IClassifiable) if wrapper: obj = wrapper else: return None return obj
def test_adapters(self): """Creates an IATContentType and tests the adaptation to IClassifiable """ self.folder.invokeFactory('Document', 'test', text="This is a test", subject="A Subject") adapted = IClassifiable(self.folder['test']) self.failUnless(adapted.UID) self.failUnless(adapted.text== convertHtmlToWebIntelligentPlainText( self.folder['test'].SearchableText())) self.failUnless(adapted.categories==['A Subject']) self.failUnless(adapted.language=='en')
def getSuggestedSubjects(self): """ """ classifier = getUtility(IContentClassifier) uid = IClassifiable(self.context).UID return classifier.probabilityClassify(uid)