Ejemplo n.º 1
0
def SearchableText(obj):
    text = u''
    richtext = IRichText(obj, None)
    if richtext:
        textvalue = richtext.text
        if IRichTextValue.providedBy(textvalue):
            transforms = getToolByName(obj, 'portal_transforms')
            # Before you think about switching raw/output
            # or mimeType/outputMimeType, first read
            # https://github.com/plone/Products.CMFPlone/issues/2066
            raw = safe_unicode(textvalue.raw)
            if six.PY2:
                raw = raw.encode('utf-8', 'replace')
            text = transforms.convertTo(
                'text/plain',
                raw,
                mimetype=textvalue.mimeType,
            ).getData().strip()

    subject = u' '.join(
        [safe_unicode(s) for s in obj.Subject()]
    )

    return u' '.join((
        safe_unicode(obj.id),
        safe_unicode(obj.title) or u'',
        safe_unicode(obj.description) or u'',
        safe_unicode(text),
        safe_unicode(subject),
    ))
Ejemplo n.º 2
0
def searchabletext_testimony(object, **kw):
    result = []

    fields = ['title',
              'description',
              'video_transcript',
              'textual_testimony',
              'displayed_function',
              'first_name',
              'theme',
              'domain']
    for field_name in fields:
        value = getattr(object, field_name, None)
        if type(value) is unicode:
            text = safe_unicode(value).encode('utf-8')
            result.append(text)
        elif IRichTextValue.providedBy(value):
            transforms = getToolByName(object, 'portal_transforms')
            text = transforms.convertTo(
                'text/plain',
                safe_unicode(value.raw).encode('utf-8'),
                mimetype=value.mimeType,
            ).getData().strip()
            result.append(text)

    return ' '.join(result)
Ejemplo n.º 3
0
def get_text_from_richtext(field):
    if IRichTextValue.providedBy(field):
        transforms = api.portal.get_tool("portal_transforms")
        raw = safe_unicode(field.raw)
        text = (transforms.convertTo(
            "text/plain", raw, mimetype=field.mimeType).getData().strip())
        return safe_unicode(text)
Ejemplo n.º 4
0
def searchable_text_address(object, **kw):
    result = [
        safe_unicode(object.Title()).encode("utf-8"),
        safe_unicode(object.Description()).encode("utf-8"),
    ]
    other_names = getattr(object, "other_names", None)
    if other_names:
        result.append(safe_unicode(other_names).encode("utf-8"))
    address = getattr(object, "address", None)
    if address:
        fields = [
            "number", "street", "zip_code", "commune", "longitude", "latitude"
        ]
        for field_name in fields:
            value = getattr(address, field_name, None)
            if type(value) is unicode:  # noqa
                text = safe_unicode(value).encode("utf-8")
                result.append(text)
            elif IRichTextValue.providedBy(value):
                transforms = getToolByName(object, "portal_transforms")
                text = (transforms.convertTo(
                    "text/plain",
                    safe_unicode(value.raw).encode("utf-8"),
                    mimetype=value.mimeType,
                ).getData().strip())
                result.append(text)

    return " ".join(result)
Ejemplo n.º 5
0
def run(context):
    catalog = api.portal.get_tool('portal_catalog')
    brains = catalog(portal_type="eea.meeting.email")

    for brain in brains:
        email = brain.getObject()
        url = email.absolute_url(1)
        updated = False
        if IRichTextValue.providedBy(email.body):
            email.body = email.body.raw
            updated = True
            LOGGER.info('Updated "body" for %s.', url)

        if email.receiver is not None and not isinstance(email.receiver, set):
            email.receiver = set(email.receiver.split())
            updated = True
            LOGGER.info('Updated "receiver" for %s.', url)

        if email.cc is not None and not isinstance(email.cc, list):
            email.cc = email.cc.split()
            updated = True
            LOGGER.info('Updated "cc" for %s.', url)

        if updated:
            email.reindexObject()
Ejemplo n.º 6
0
def searchabletext_patrimoine(object, **kw):
    """
    Indexes the following field types in Patrimoine objects,
    making them available in Full Text Search:
    - text
    - rich text
    - keywords
    - taxonomies
    """
    result = []
    subjects = getattr(object, "subject", None)
    if type(subjects) is tuple:
        text = " ".join([s for s in subjects if isinstance(s, six.text_type)])
        result.append(text)

    for schemata in iterSchemata(object):
        if "collective.taxonomy.generated" in str(schemata):
            value = getattr(object, "taxonomy_{0}".format(schemata.__name__),
                            None)
            if value:
                value = [value] if isinstance(value, six.text_type) else value
                translator = queryUtility(
                    ITaxonomy,
                    name="collective.taxonomy.{0}".format(schemata.__name__))
                for taxonomy_id in value:
                    translation = translator.translate(taxonomy_id,
                                                       target_language="fr")
                    text = translation
                    result.append(text)
            continue

        for field_name, field_type in getFields(schemata).items():
            value = getattr(object, field_name, None)
            if isinstance(value, six.text_type):
                text = value
                result.append(text)
            elif IRichTextValue.providedBy(value):
                transforms = getToolByName(object, "portal_transforms")
                text = (transforms.convertTo(
                    "text/plain", value.raw,
                    mimetype=value.mimeType).getData().strip())
                result.append(text)

    return " ".join(result)
Ejemplo n.º 7
0
def SearchableText(obj):
    text = u""
    richtext = IRichText(obj, None)
    if richtext:
        textvalue = richtext.text
        if IRichTextValue.providedBy(textvalue):
            transforms = getToolByName(obj, 'portal_transforms')
            text = transforms.convertTo(
                'text/plain',
                safe_unicode(textvalue.output).encode('utf8'),
                mimetype=textvalue.mimeType,
            ).getData().strip()

    return u" ".join((
        safe_unicode(obj.id),
        safe_unicode(obj.title) or u"",
        safe_unicode(obj.description) or u"",
        safe_unicode(text)
    ))
Ejemplo n.º 8
0
def searchabletext_project(object, **kw):
    result = []

    fields = ["title", "description", "body", "original_author"]
    for field_name in fields:
        value = getattr(object, field_name, None)
        if type(value) is unicode:
            text = safe_unicode(value).encode("utf-8")
            result.append(text)
        elif IRichTextValue.providedBy(value):
            transforms = getToolByName(object, "portal_transforms")
            text = (transforms.convertTo(
                "text/plain",
                safe_unicode(value.raw).encode("utf-8"),
                mimetype=value.mimeType,
            ).getData().strip())
            result.append(text.encode("utf8"))

    return " ".join(result)
Ejemplo n.º 9
0
def SearchableText(obj):
    text = u""
    richtext = obj.body_text
    if richtext:
        if IRichTextValue.providedBy(richtext):
            transforms = api.portal.get_tool('portal_transforms')
            text = transforms.convertTo(
                'text/plain',
                safe_unicode(richtext.output).encode('utf8'),
                mimetype=richtext.mimeType,
            ).getData().strip()
    subject = u' '.join([safe_unicode(s) for s in obj.Subject()])

    return u" ".join((
        safe_unicode(obj.id),
        safe_unicode(obj.title) or u"",
        safe_unicode(obj.description) or u"",
        safe_unicode(text),
        safe_unicode(subject),
    ))
Ejemplo n.º 10
0
def SearchableText(obj):
    text = u''
    if obj.abstract:
        textvalue = obj.abstract
        if IRichTextValue.providedBy(textvalue):
            transforms = getToolByName(obj, 'portal_transforms')
            text = (transforms.convertTo(
                'text/plain',
                safe_unicode(textvalue.raw).encode('utf-8'),
                mimetype=textvalue.mimeType,
            ).getData().strip())

    subject = u' '.join([safe_unicode(s) for s in obj.Subject()])

    return u' '.join((
        safe_unicode(obj.id),
        safe_unicode(obj.title) or u'',
        safe_unicode(obj.description) or u'',
        safe_unicode(text),
        safe_unicode(subject),
    ))
Ejemplo n.º 11
0
def SearchableText(obj):
    text = u""
    richtext = IRichText(obj, None)
    if richtext:
        textvalue = richtext.text
        if IRichTextValue.providedBy(textvalue):
            transforms = getToolByName(obj, 'portal_transforms')
            text = transforms.convertTo(
                'text/plain',
                safe_unicode(textvalue.output).encode('utf8'),
                mimetype=textvalue.mimeType,
            ).getData().strip()

    subject = u' '.join([safe_unicode(s) for s in obj.Subject()])

    return u" ".join((
        safe_unicode(obj.id),
        safe_unicode(obj.title) or u"",
        safe_unicode(obj.description) or u"",
        safe_unicode(text),
        safe_unicode(subject),
    ))
Ejemplo n.º 12
0
def searchabletext_project(object, **kw):
    result = []

    fields = ["title", "description", "body", "original_author"]
    for field_name in fields:
        value = getattr(object, field_name, None)
        if type(value) is unicode:
            text = safe_unicode(value).encode("utf-8")
            result.append(text)
        elif IRichTextValue.providedBy(value):
            transforms = getToolByName(object, "portal_transforms")
            text = (
                transforms.convertTo(
                    "text/plain",
                    safe_unicode(value.raw).encode("utf-8"),
                    mimetype=value.mimeType,
                )
                .getData()
                .strip()
            )
            result.append(text.encode("utf8"))

    return " ".join(result)