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)))
Exemplo n.º 2
0
 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)))
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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