def test_process_unicode(self): lsts = [ (u"日本", [u"日本", u"本"]), (u"日", [u"日"]), (u"日本語", [u"日本", u"本語", u"語"]), (u"日本語python", [u"日本", u"本語", u"語", u"python"]), (u"日本語12345", [u"日本", u"本語", u"語", u"12345"]), ] for lst, rst in lsts: self.assertEqual(rst, list(process_unicode(lst)))
def test_process_unicode(self): lsts = [ (u"日本", [u"日本", u"本"]), (u"日", [u"日"]), (u"日本語", [u"日本", u"本語", u"語"]), (u"日本語python", [u"日本", u"本語", u"語", u"python"]), (u"日本語12345", [u"日本", u"本語", u"語", u"12345"]), ] for lst, rst in lsts: self.assertEqual(rst, list(process_unicode(lst)))
def __call__(self, value, *args, **kwargs): words = process_unicode(unicode(value, 'utf-8')) cat = getToolByName(kwargs['instance'], 'portal_catalog') query = {'portal_type': 'PolicyDocumentReference', 'Title': list(words)} oid = kwargs['instance'].UID() brains = [b for b in cat(**query) if b.Title == value and b.getObject().UID() != oid] if brains: return ("Validation failed, there is already an Policy " "Document with this title.") return True
def has_value(self, **kwargs): """ Returns true if text field has at least 2 words in it """ convert = getToolByName(self.context, 'portal_transforms').convert accessor = self.field.getAccessor(self.context) if not accessor: logger.warning("Field %s for %s has no accessor", self.field, self.context) return False value = accessor() text = convert('html_to_text', value).getData().strip() if not isinstance(text, unicode): text = unicode(text, 'utf-8', 'ignore') words = process_unicode(text) return len(list(words)) > 1 #there should be at least 2 words, or
def has_value(self, **kwargs): """ Returns true if text field has at least 2 words in it """ convert = getToolByName(self.context, 'portal_transforms').convert accessor = self.field.getAccessor(self.context) if not accessor: logger.warning("Field %s for %s has no accessor" % (self.field, self.context)) return False value = accessor() text = convert('html_to_text', value).getData().strip() if not isinstance(text, unicode): text = unicode(text, 'utf-8', 'ignore') words = process_unicode(text) return len(list(words)) > 1 #there should be at least 2 words, or