Exemple #1
0
def SearchableText_contact(obj):
    topics = []
    for topic in getattr(obj.aq_base, "topics", []) or []:
        topics.append(
            translate_vocabulary_term("imio.smartweb.vocabulary.Topics",
                                      topic))

    sm = getSiteManager()
    utility = sm.queryUtility(ITaxonomy,
                              name="collective.taxonomy.contact_category")
    current_lang = api.portal.get_current_language()[:2]
    categories = []
    for category in getattr(obj.aq_base, "taxonomy_contact_category",
                            []) or []:
        categories.append(
            utility.translate(category,
                              context=obj,
                              target_language=current_lang))

    result = " ".join((
        safe_unicode(obj.title) or "",
        safe_unicode(obj.subtitle) or "",
        safe_unicode(obj.description) or "",
        *topics,
        *categories,
    ))
    return _unicode_save_string_concat(result)
Exemple #2
0
    def __call__(self):
        rich_text_ids = ["activity", "informations_complementaires"]
        text_items = []
        for rich_text_id in rich_text_ids:
            rich_text = getattr(self.context, rich_text_id, None)
            if rich_text is None:
                continue
            transforms = getToolByName(self.context, "portal_transforms")
            raw = safe_unicode(rich_text.raw)
            if six.PY2:
                raw = raw.encode("utf-8", "replace")
            text_items.append(
                safe_unicode(
                    transforms.convertTo(
                        "text/plain", raw,
                        mimetype=rich_text.mimeType).getData().strip()))
        text = u" ".join(text_items)

        taxonomy_ids = api.portal.get_registry_record(
            'cpskin.core.interfaces.ICPSkinSettings.indexed_taxonomies'
        )  # noqa
        taxonomy_ids = taxonomy_ids.split("\n")
        taxo_items = []
        lang = self.context.language
        for taxonomy_id in taxonomy_ids:
            field_name = taxonomy_id.replace("_", "")
            keys = getattr(self.context, "taxonomy_{0}".format(field_name),
                           None)
            if not keys:
                continue
            try:
                taxonomy = getUtility(
                    ITaxonomy,
                    name="collective.taxonomy.{0}".format(taxonomy_id))
            except ComponentLookupError:
                taxonomy = getUtility(
                    ITaxonomy,
                    name="collective.taxonomy.{0}".format(field_name))
            for key in keys:
                try:
                    taxo_items.append(
                        safe_unicode(
                            taxonomy.translate(key,
                                               context=self.context,
                                               target_language=lang)))
                except KeyError:
                    pass
        taxo_text = u" ".join(taxo_items)

        return _unicode_save_string_concat(u" ".join((
            safe_unicode(self.context.id),
            safe_unicode(self.context.title) or u"",
            safe_unicode(self.context.description) or u"",
            text,
            taxo_text,
        )))
Exemple #3
0
def SearchableText_etherpad(context):
    view = etherpad_view.EtherpadView(context, getRequest())
    view.update()
    if view.etherpad is None:
        return indexers.SearchableText(context)
    text = indexers.SearchableText(context)
    transforms = getToolByName(context, 'portal_transforms')
    h = HTMLParser()
    value = h.unescape(str(view.content()))
    content = transforms.convertTo('text/plain', value, mimetype='text/html')
    return indexers._unicode_save_string_concat(text, content.getData())
Exemple #4
0
 def __call__(self):
     """ Extend the searchable text with a custom string """
     primary_field = IPrimaryFieldInfo(self.context)
     if primary_field.value is None:
         return self.searchable_text()
     mimetype = primary_field.value.contentType
     transforms = getToolByName(self.context, 'portal_transforms')
     value = str(primary_field.value.data)
     filename = primary_field.value.filename
     try:
         transformed_value = transforms.convertTo('text/plain', value,
                                                  mimetype=mimetype,
                                                  filename=filename)
         if not transformed_value:
             return self.searchable_text()
         ret = _unicode_save_string_concat(self.searchable_text(),
                                           transformed_value.getData())
         if ret.startswith(' '):
             ret = ret[1:]
         return ret
     except:
         return self.searchable_text()
Exemple #5
0
 def __call__(self):
     """ Extend the searchable text with a custom string """
     primary_field = IPrimaryFieldInfo(self.context)
     if primary_field.value is None:
         return self.searchable_text()
     mimetype = primary_field.value.contentType
     transforms = getToolByName(self.context, 'portal_transforms')
     value = str(primary_field.value.data)
     filename = primary_field.value.filename
     try:
         transformed_value = transforms.convertTo('text/plain',
                                                  value,
                                                  mimetype=mimetype,
                                                  filename=filename)
         if not transformed_value:
             return self.searchable_text()
         ret = _unicode_save_string_concat(self.searchable_text(),
                                           transformed_value.getData())
         if ret.startswith(' '):
             ret = ret[1:]
         return ret
     except:  # noqa
         return self.searchable_text()
def proposta_SearchableText(obj):
    return _unicode_save_string_concat(SearchableText_(obj))
def consulta_publica_SearchableText(obj):
    return _unicode_save_string_concat(SearchableText_(obj))
def SearchableText_scheda(obj):
    """
    re-defined SearchableText for scheda.
    Add also tiles text and title
    """
    return _unicode_save_string_concat(SearchableText(obj))
Exemple #9
0
def SearchableText_projectcontent(obj):
    if obj.text is None or obj.text.output is None:
        return SearchableText(obj)
    return _unicode_save_string_concat(SearchableText(obj), obj.text.output)
Exemple #10
0
def SearchableText_section(context):
    return _unicode_save_string_concat(SearchableText(context))
Exemple #11
0
def consulta_publica_SearchableText(obj):
    return _unicode_save_string_concat(SearchableText_(obj))
def publication_searchable_text(obj, **kw):
    return _unicode_save_string_concat(SearchableText(obj))
Exemple #13
0
def SearchableText_banhua(obj):
    return _unicode_save_string_concat(SearchableText(obj))
Exemple #14
0
def SearchableText_projectcontent(obj):
    if obj.text is None or obj.text.output is None:
        return SearchableText(obj)
    return _unicode_save_string_concat(SearchableText(obj), obj.text.output)
Exemple #15
0
def SearchableText_polyester(obj):
    return _unicode_save_string_concat(SearchableText(obj))
Exemple #16
0
def minuta_SearchableText(obj):
    return _unicode_save_string_concat(SearchableText_(obj))
Exemple #17
0
def SearchableText_tumour(obj):
    return _unicode_save_string_concat(SearchableText(obj))
Exemple #18
0
def proposta_SearchableText(obj):
    return u' '.join([_unicode_save_string_concat(SearchableText_(obj)),
                      obj.justificativa,
                      obj.bairro or ''])
Exemple #19
0
def SearchableText_subsite(context):
    return _unicode_save_string_concat(SearchableText(context))