Exemplo n.º 1
0
    def addfield(self, facet):
        "add index, collection field etc"

        id = facetId(facet.name)

        # new collections
        collections = self.getCollectionMap()
        field = collections.setdefault(id)
        field.title = u"%s" % facet.name
        field.description = u"" + facet.description
        field.group = u'Metadata'
        field.sortable = True
        field.enabled = True
        field.vocabulary = u'plone.app.vocabularies.Keywords'
        field.operations = ['plone.app.querystring.operation.selection.is']

        # old collections
        atct = getToolByName(self.context, 'portal_atct')
        atct.addIndex(id, facet.name, facet.description, enabled=True)
        atct.addMetadata(id, facet.name, facet.description, enabled=True)

        # catalog metadata
        if id not in self.catalog.schema():
            self.catalog.manage_addColumn(id)

        # catalog indexes
        if id not in self.catalog.indexes():
            self.catalog.addIndex(id, 'KeywordIndex')
            return [id]
        else:
            return []
Exemplo n.º 2
0
    def addField(self, facet):
        """add index, collection field etc"""

        id = facetId(facet.name)

        # new collections
        collections = self.getCollectionMap()
        if collections:
            field = collections.setdefault(id)
            field.title = u'%s' % facet.display_title
            field.description = u''
            if facet.description:
                field.description = u'' + facet.description
            field.group = u'Metadata'
            field.sortable = True
            field.enabled = True
            if facet.vocabularies in ['FieldType:StringField', 'free_text']:
                field.vocabulary = None
                field.operations = ['plone.app.querystring.operation.string.contains',
                                     'plone.app.querystring.operation.string.is']
            elif facet.vocabularies in ['FieldType:KeywordField', 'tags']:
                field.vocabulary = u'plone.app.vocabularies.Keywords'
                field.operations = ['plone.app.querystring.operation.selection.is']
            else:
                field.vocabulary = unicode(field.vocabulary)
                field.operations = ['plone.app.querystring.operation.selection.is']


        # old collections
        try:
            atct = getToolByName(self.context, 'portal_atct')
        except:
            atct = None
        if atct is not None:
            #criteria ??
            #from Products.ATContentTypes.criteria.selection import ATSelectionCriterion
            #from Products.ATContentTypes.criteria.simplestring import ATSimpleStringCriterion
            atct.addIndex(id, facet.display_title, facet.description, enabled=True)
            atct.addMetadata(id, facet.display_title, facet.description, enabled=True)

        # catalog metadata
        if id not in self.catalog.schema():
            self.catalog.manage_addColumn(id)

        # catalog indexes
        if id not in self.catalog.indexes():
            if facet.vocabularies in ['FieldType:StringField', 'free_text']:
                self.catalog.addIndex(id, 'FieldIndex')
            else:
                self.catalog.addIndex(id, 'KeywordIndex')
            return [id]
        else:
            return []
Exemplo n.º 3
0
    def removeField(self, facet):
        id = facetId(facet.name)

        collections = self.getCollectionMap()
        if id in collections:
            del collections[id]

        # old collections
        atct = getToolByName(self.context, 'portal_atct')
        atct.removeIndex(id)
        atct.removeMetadata(id)

        if id in self.catalog.indexes():
            self.catalog.delIndex(id)
        if id in self.catalog.schema():
            self.catalog.manage_delColumn(id)
Exemplo n.º 4
0
    def __init__(self, context):
        self.context = context

        try:
            proxy = getRegistryFacets()
        except ComponentLookupError:
            # not installed
            return

        self.fields = []
        for facet in proxy.facets:
            field_name = facetId(facet.name)
            vocabularies = facet.vocabularies

            if vocabularies in ['FieldType:StringField', 'free_text']:

                self.fields.append(
                    ExtensionStringField(field_name,
                                       schemata="categorization",
                                       searchable=True,
                                       widget=StringWidget(
                                           label=facet.display_title,
                                           description=facet.description
                                       )))
            elif vocabularies in ['FieldType:KeywordField', 'tags'] or not vocabularies:
                self.fields.append(
                    ExtensionKeywordField(field_name,
                                          schemata="categorization",
                                          multiValued=1,
                                          accessor=field_name,
                                          searchable=True,
                                          widget=KeywordWidget(
                                              label=facet.display_title,
                                              description=facet.description))
                )
            else:
                self.fields.append(
                    ExtensionKeywordField(field_name,
                                          schemata="categorization",
                                          multiValued=1,
                                          accessor=field_name,
                                          searchable=True,
                                          widget=InAndOutWidget(
                                              label=facet.display_title,
                                              description=facet.description),
                                          vocabulary=vocabularies)
                )
Exemplo n.º 5
0
    def __init__(self, context):
        self.context = context

        reg = getUtility(IRegistry)
        proxy = ComplexRecordsProxy(reg, IFacetSettings, prefix='collective.facets')

        self.fields = []
        for facet in proxy.facets:
            field_name = facetId(facet.name)
            self.fields.append(
                ExtensionKeywordField(field_name,
                    schemata="categorization",
                    multiValued=1,
                    accessor=field_name,
                    searchable=True,
                    widget=KeywordWidget(
                        label=field_name,
                        description=facet.description,
                        ),
                )
            )