def test_multilanguage_indexer(self): portal_catalog = api.portal.get_tool('portal_catalog') utility = queryUtility(ITaxonomy, name='collective.taxonomy.test') taxonomy = utility.data taxonomy_test = schema.Set( title=u"taxonomy_test", description=u"taxonomy description schema", required=False, value_type=schema.Choice( vocabulary=u"collective.taxonomy.taxonomies"), ) portal_types = api.portal.get_tool('portal_types') fti = portal_types.get('Document') document_schema = fti.lookupSchema() schemaeditor = IEditableSchema(document_schema) schemaeditor.addField(taxonomy_test, name='taxonomy_test') notify(ObjectAddedEvent(taxonomy_test, document_schema)) notify(FieldAddedEvent(fti, taxonomy_test)) query = {} query['taxonomy_test'] = '5' simple_tax = [val for val in taxonomy['en'].values()] taxo_val = simple_tax[3] self.document.taxonomy_test = [taxo_val] self.document.reindexObject() self.assertEqual(len(portal_catalog(query)), 1)
def add(self, field): context = self.context schema = IEditableSchema(context.schema) # move it after the last field that is not in a fieldset # or at top if there is no field yet in "default" fieldset ordered_fields = [name for (name, f) in sortedFields(context.schema)] default_fields = non_fieldset_fields(context.schema) if len(default_fields) > 0: position = ordered_fields.index(default_fields[-1]) + 1 else: position = 0 try: schema.addField(field) except ValueError: raise WidgetActionExecutionError('__name__', Invalid( u'Please select a field name that is not already used.' )) schema.moveField(field.__name__, position) notify(ObjectAddedEvent(field, context.schema)) notify(FieldAddedEvent(context, field)) IStatusMessage(self.request).addStatusMessage( _(u"Field added successfully."), type='info')
def test_multilanguage_indexer(self): portal_catalog = api.portal.get_tool("portal_catalog") utility = queryUtility(ITaxonomy, name="collective.taxonomy.test") taxonomy = utility.data taxonomy_test = schema.Set( title=u"taxonomy_test", description=u"taxonomy description schema", required=False, value_type=schema.Choice( vocabulary=u"collective.taxonomy.taxonomies"), ) portal_types = api.portal.get_tool("portal_types") fti = portal_types.get("Document") document_schema = fti.lookupSchema() schemaeditor = IEditableSchema(document_schema) schemaeditor.addField(taxonomy_test, name="taxonomy_test") notify(ObjectAddedEvent(taxonomy_test, document_schema)) notify(FieldAddedEvent(fti, taxonomy_test)) query = {} query["taxonomy_test"] = "5" taxo_val = taxonomy["en"][u"\u241fInformation Science\u241fSport"] self.document.taxonomy_test = [taxo_val] self.document.reindexObject() self.assertEqual(len(portal_catalog(query)), 1) # clean up schemaeditor.removeField("taxonomy_test")
def test_multilanguage_indexer(self): portal_catalog = api.portal.get_tool("portal_catalog") utility = queryUtility(ITaxonomy, name="collective.taxonomy.test") taxonomy = utility.data taxonomy_test = schema.Set( title=u"taxonomy_test", description=u"taxonomy description schema", required=False, value_type=schema.Choice(vocabulary=u"collective.taxonomy.taxonomies"), ) portal_types = api.portal.get_tool("portal_types") fti = portal_types.get("Document") document_schema = fti.lookupSchema() schemaeditor = IEditableSchema(document_schema) schemaeditor.addField(taxonomy_test, name="taxonomy_test") notify(ObjectAddedEvent(taxonomy_test, document_schema)) notify(FieldAddedEvent(fti, taxonomy_test)) query = {} query["taxonomy_test"] = "5" simple_tax = [val for val in taxonomy["en"].values()] taxo_val = simple_tax[3] self.document.taxonomy_test = [taxo_val] self.document.reindexObject() self.assertEqual(len(portal_catalog(query)), 1)
def add(self, field): schema = IEditableSchema(self.context.schema) try: schema.addField(field) except ValueError: raise WidgetActionExecutionError('__name__', Invalid(_(u'Please select a field name that is not already used.'))) notify(ObjectAddedEvent(field, self.context.schema)) notify(SchemaModifiedEvent(self.context)) self.status = _(u"Field added successfully.")
def test_folderview_event_category(self): applyProfile(self.portal, 'collective.taxonomy:default') add_behavior('Collection', ICpskinIndexViewSettings.__identifier__) utility = queryUtility(ITaxonomy, name='collective.taxonomy.test') collection = api.content.create(container=self.folder, type='Collection', id='collection') collection.taxonomy_category = 'taxonomy_test' collection.reindexObject() taxonomy_test = schema.Set( title=u'taxonomy_test', description=u'taxonomy description schema', required=False, value_type=schema.Choice( vocabulary=u'collective.taxonomy.test'), ) portal_types = api.portal.get_tool('portal_types') fti = portal_types.get('Event') event_schema = fti.lookupSchema() schemaeditor = IEditableSchema(event_schema) schemaeditor.addField(taxonomy_test, name='taxonomy_test') notify(ObjectAddedEvent(taxonomy_test, event_schema)) notify(FieldAddedEvent(fti, taxonomy_test)) event = api.content.create( container=self.folder, type='Event', id='testevent') simple_tax = [val for val in utility.data['en'].values()] event.taxonomy_test = set(simple_tax[0]) view = getMultiAdapter( (self.portal, self.portal.REQUEST), name='folderview') see_categories = view.see_categories(collection) self.assertTrue(see_categories) collection.taxonomy_category = '' see_categories = view.see_categories(collection) self.assertFalse(see_categories) collection.taxonomy_category = 'taxonomy_test' categories = view.get_categories(collection, event) self.assertEqual(categories, 'Information Science') event.taxonomy_test = set(simple_tax[0:2]) categories = view.get_categories(collection, event) self.assertEqual( categories, 'Book Collecting, Information Science') event.taxonomy_test = set() categories = view.get_categories(collection, event) self.assertEqual(categories, '')
def test_folderview_event_category(self): applyProfile(self.portal, 'collective.taxonomy:default') add_behavior('Collection', ICpskinIndexViewSettings.__identifier__) utility = queryUtility(ITaxonomy, name='collective.taxonomy.test') collection = api.content.create(container=self.folder, type='Collection', id='collection') collection.taxonomy_category = 'taxonomy_test' collection.reindexObject() taxonomy_test = schema.Set( title=u'taxonomy_test', description=u'taxonomy description schema', required=False, value_type=schema.Choice(vocabulary=u'collective.taxonomy.test'), ) portal_types = api.portal.get_tool('portal_types') fti = portal_types.get('Event') event_schema = fti.lookupSchema() schemaeditor = IEditableSchema(event_schema) schemaeditor.addField(taxonomy_test, name='taxonomy_test') notify(ObjectAddedEvent(taxonomy_test, event_schema)) notify(FieldAddedEvent(fti, taxonomy_test)) event = api.content.create(container=self.folder, type='Event', id='testevent') simple_tax = [val for val in utility.data['en'].values()] event.taxonomy_test = set(simple_tax[0]) view = getMultiAdapter((self.portal, self.portal.REQUEST), name='folderview') see_categories = view.see_categories(collection) self.assertTrue(see_categories) collection.taxonomy_category = '' see_categories = view.see_categories(collection) self.assertFalse(see_categories) collection.taxonomy_category = 'taxonomy_test' categories = view.get_categories(collection, event) self.assertEqual(categories, 'Information Science') event.taxonomy_test = set(simple_tax[0:2]) categories = view.get_categories(collection, event) self.assertEqual(categories, 'Book Collecting, Information Science') event.taxonomy_test = set() categories = view.get_categories(collection, event) self.assertEqual(categories, '')
def test_indexer_with_field(self): portal_catalog = api.portal.get_tool('portal_catalog') utility = queryUtility(ITaxonomy, name='collective.taxonomy.test') taxonomy = utility.data taxonomy_test = schema.Set( title=u"taxonomy_test", description=u"taxonomy description schema", required=False, value_type=schema.Choice( vocabulary=u"collective.taxonomy.taxonomies"), ) portal_types = api.portal.get_tool('portal_types') fti = portal_types.get('Document') document_schema = fti.lookupSchema() schemaeditor = IEditableSchema(document_schema) schemaeditor.addField(taxonomy_test, name='taxonomy_test') notify(ObjectAddedEvent(taxonomy_test, document_schema)) notify(FieldAddedEvent(fti, taxonomy_test)) index = portal_catalog.Indexes['taxonomy_test'] self.assertEqual(index.numObjects(), 0) self.document.taxonomy_test = [] self.document.reindexObject() query = {} query['taxonomy_test'] = '1' self.assertEqual(len(portal_catalog(query)), 0) taxo_val = taxonomy['en'][u'\u241fInformation Science\u241fChronology'] self.document.taxonomy_test = [taxo_val] self.document.reindexObject() self.assertEqual(len(portal_catalog(query)), 1) index = portal_catalog.Indexes['taxonomy_test'] self.assertEqual(index.numObjects(), 1) self.document.taxonomy_test = set(taxo_val) self.document.reindexObject() index = portal_catalog.Indexes['taxonomy_test'] self.assertEqual(index.numObjects(), 1)
def add(self, new_field): schema = self.context.schema fieldset_id = int(self.request.form.get('fieldset_id', 0)) position = new_field_position(schema, fieldset_id) editable_schema = IEditableSchema(schema) try: editable_schema.addField(new_field) except ValueError: raise WidgetActionExecutionError( '__name__', Invalid( u'Please select a field name that is not already used.')) if fieldset_id: fieldset = get_fieldset_from_index(schema, fieldset_id) editable_schema.changeFieldFieldset(new_field.__name__, fieldset) editable_schema.moveField(new_field.__name__, position) notify(ObjectAddedEvent(new_field, schema)) notify(FieldAddedEvent(self.context, new_field)) IStatusMessage(self.request).addStatusMessage( _(u'Field added successfully.'), type='info')
def add(self, field): context = self.context schema = IEditableSchema(context.schema) # move it after the last field that is not in a fieldset # or at top if there is no field yet in "default" fieldset ordered_fields = [name for (name, f) in sortedFields(context.schema)] default_fields = non_fieldset_fields(context.schema) if len(default_fields) > 0: position = ordered_fields.index(default_fields[-1]) + 1 else: position = 0 try: schema.addField(field) except ValueError: raise WidgetActionExecutionError('__name__', Invalid(u'Please select a field name that is not already used.')) schema.moveField(field.__name__, position) notify(ObjectAddedEvent(field, context.schema)) notify(FieldAddedEvent(context, field)) self.status = _(u"Field added successfully.")
def test_taxonmies_field_visible(self): applyProfile(self.portal, 'collective.taxonomy:default') utility = queryUtility(ITaxonomy, name='collective.taxonomy.test') taxonomy_test = schema.Set( title=u'taxonomy_test', description=u'taxonomy description schema', required=False, value_type=schema.Choice( vocabulary=u'collective.taxonomy.test'), ) portal_types = api.portal.get_tool('portal_types') fti = portal_types.get('Event') event_schema = fti.lookupSchema() schemaeditor = IEditableSchema(event_schema) schemaeditor.addField(taxonomy_test, name='taxonomy_test') notify(ObjectAddedEvent(taxonomy_test, event_schema)) notify(FieldAddedEvent(fti, taxonomy_test)) event = api.content.create(self.portal, 'Event', 'testevent') simple_tax = [val for val in utility.data['en'].values()] event.taxonomy_test = set(simple_tax[0]) view = getMultiAdapter( (event, self.portal.REQUEST), name='event_summary') taxonomies = view.get_taxonomies() self.assertEqual(taxonomies[0]['value'], 'Information Science') event.taxonomy_test = set(simple_tax[0:2]) taxonomies = view.get_taxonomies() self.assertEqual( taxonomies[0]['value'], 'Information Science, Information Science/Book Collecting') event.taxonomy_test = set() taxonomies = view.get_taxonomies() self.assertEqual(len(taxonomies), 0)
def add(self, new_field): schema = self.context.schema fieldset_id = int(self.request.form.get('fieldset_id', 0)) position = new_field_position(schema, fieldset_id) editable_schema = IEditableSchema(schema) try: editable_schema.addField(new_field) except ValueError: raise WidgetActionExecutionError( '__name__', Invalid( u'Please select a field name that is not already used.' ) ) if fieldset_id: fieldset = get_fieldset_from_index(schema, fieldset_id) editable_schema.changeFieldFieldset(new_field.__name__, fieldset) editable_schema.moveField(new_field.__name__, position) notify(ObjectAddedEvent(new_field, schema)) notify(FieldAddedEvent(self.context, new_field)) IStatusMessage(self.request).addStatusMessage( _(u'Field added successfully.'), type='info')
def test_taxonmies_field_visible(self): applyProfile(self.portal, 'collective.taxonomy:default') utility = queryUtility(ITaxonomy, name='collective.taxonomy.test') taxonomy_test = schema.Set( title=u'taxonomy_test', description=u'taxonomy description schema', required=False, value_type=schema.Choice(vocabulary=u'collective.taxonomy.test'), ) portal_types = api.portal.get_tool('portal_types') fti = portal_types.get('Event') event_schema = fti.lookupSchema() schemaeditor = IEditableSchema(event_schema) schemaeditor.addField(taxonomy_test, name='taxonomy_test') notify(ObjectAddedEvent(taxonomy_test, event_schema)) notify(FieldAddedEvent(fti, taxonomy_test)) event = api.content.create(self.portal, 'Event', 'testevent') simple_tax = [val for val in utility.data['en'].values()] event.taxonomy_test = set(simple_tax[0]) view = getMultiAdapter((event, self.portal.REQUEST), name='event_summary') taxonomies = view.get_taxonomies() self.assertEqual(taxonomies[0]['value'], 'Information Science') event.taxonomy_test = set(simple_tax[0:2]) taxonomies = view.get_taxonomies() self.assertEqual( taxonomies[0]['value'], 'Information Science, Information Science/Book Collecting') event.taxonomy_test = set() taxonomies = view.get_taxonomies() self.assertEqual(len(taxonomies), 0)