def __setattr__(self, attr, value): if attr in ['taxonomy']: return if attr == 'purge': self.__dict__['purge'] = value return if attr == 'field_prefix': self.__dict__['behavior'].removeIndex() setattr(self.__dict__['behavior'], attr, value or "") self.__dict__['behavior'].addIndex() return if attr == 'import_file' and value is not None: import_file = value.data adapter = TaxonomyImportExportAdapter(self.__dict__['context']) purge = self.__dict__.get('purge', False) logger.info("Importing document into '%s' (purge: %s)" % ( self.__dict__['taxonomy'], str(purge).lower() )) adapter.importDocument(self.utility, import_file, purge) else: if attr == 'field_title': self.__dict__['utility'].title = value if attr == 'field_description': self.__dict__['utility'].description = value if attr == 'default_language': self.__dict__['utility'].default_language = value setattr(self.__dict__['behavior'], attr, value)
def add(self, data): if 'import_file' not in data: raise ValueError("Import file is not in form") taxonomy = registerTaxonomy(self.context, name=data['taxonomy'], title=data['field_title'], description=data['field_description'], default_language=data['default_language']) # Import adapter = TaxonomyImportExportAdapter(self.context) if 'import_file' in data: if data['import_file']: import_file = data['import_file'].data adapter.importDocument(taxonomy, import_file) del data['import_file'] del data['taxonomy'] taxonomy.registerBehavior(**data) api.portal.show_message(_(u"Taxonomy imported."), request=self.request) return self.request.RESPONSE.redirect(self.context.portal_url() + '/@@taxonomy-settings')
def add(self, data): if 'import_file' not in data: raise ValueError("Import file is not in form") taxonomy = registerTaxonomy( self.context, name=data['taxonomy'], title=data['field_title'], description=data['field_description'], default_language=data['default_language'] ) # Import adapter = TaxonomyImportExportAdapter(self.context) if 'import_file' in data: if data['import_file']: import_file = data['import_file'].data adapter.importDocument(taxonomy, import_file) del data['import_file'] del data['taxonomy'] taxonomy.registerBehavior(**data) api.portal.show_message(_(u"Taxonomy imported."), request=self.request) return self.request.RESPONSE.redirect( self.context.portal_url() + '/@@taxonomy-settings' )
def add_default_taxonomies(): taxonomies = [{ 'filename': '@@taxonomy-settings-categories-evenements', 'name': 'categoriesevenements', 'title': u'Catégories événements', 'field_description': '', 'default_language': 'fr' }, { 'filename': '@@taxonomy-settings-thematiques', 'name': 'thematiques', 'title': u'Thématiques', 'field_description': '', 'default_language': 'fr' }, { 'filename': '@@taxonomy-settings-types-activites', 'name': 'types_activites', 'title': u"Types d'activités", 'field_description': '', 'default_language': 'fr' }, { 'filename': '@@taxonomy-settings-types-organisations', 'name': 'types_organisations', 'title': u"Types d'organisations", 'field_description': '', 'default_language': 'fr' }] for tax in taxonomies: # TODO check if no taxonomy exist with same id portal = api.portal.get() taxonomy = registerTaxonomy( portal, name=tax['name'], title=tax['title'], description=tax['field_description'], default_language=tax['default_language'] ) # Import adapter = TaxonomyImportExportAdapter(portal) data_path = os.path.join(os.path.dirname(__file__), 'data') file_path = os.path.join(data_path, tax['filename']) data = open(file_path, 'r').read(), import_file = data[0] adapter.importDocument(taxonomy, import_file) del tax['filename'] # {'field_description': None, 'title': u'Cat\xe9gorie', 'field_title': u'Cat\xe9gorie', 'description': None, 'is_required': False, 'default_language': u'fr', 'write_permission': None, 'is_single_select': False, 'name': 'collective.taxonomy.generated.categorievent'} # {'field_description': '', 'title': 'Cat\xc3\xa9gories \xc3\xa9v\xc3\xa9nements','description': '', 'is_required': False, 'default_language': 'fr', 'write_permission': None, 'is_single_select': False, 'name': 'collective.taxonomy.generated.categoriesevenements'} # {'field_description': None, # 'title': u'Cat\xe9gorie', tax['field_title'] = tax['title'] # 'description': None, tax['is_required'] = False tax['write_permission'] = None tax['is_single_select'] = False # 'name': 'collective.taxonomy.generated.categorievent'} taxonomy.registerBehavior(**tax) logger.info('Taxonomy {0} imported'.format(tax['name']))
def add_default_taxonomies(): taxonomies = [{ 'filename': '@@taxonomy-settings-categories-evenements', 'name': 'categoriesevenements', 'title': u'Catégories événements', 'field_description': '', 'default_language': 'fr' }, { 'filename': '@@taxonomy-settings-thematiques', 'name': 'thematiques', 'title': u'Thématiques', 'field_description': '', 'default_language': 'fr' }, { 'filename': '@@taxonomy-settings-types-activites', 'name': 'types_activites', 'title': u"Types d'activités", 'field_description': '', 'default_language': 'fr' }, { 'filename': '@@taxonomy-settings-types-organisations', 'name': 'types_organisations', 'title': u"Types d'organisations", 'field_description': '', 'default_language': 'fr' }] for tax in taxonomies: # TODO check if no taxonomy exist with same id portal = api.portal.get() taxonomy = registerTaxonomy(portal, name=tax['name'], title=tax['title'], description=tax['field_description'], default_language=tax['default_language']) # Import adapter = TaxonomyImportExportAdapter(portal) data_path = os.path.join(os.path.dirname(__file__), 'data') file_path = os.path.join(data_path, tax['filename']) data = open(file_path, 'r').read(), import_file = data[0] adapter.importDocument(taxonomy, import_file) del tax['filename'] # {'field_description': None, 'title': u'Cat\xe9gorie', 'field_title': u'Cat\xe9gorie', 'description': None, 'is_required': False, 'default_language': u'fr', 'write_permission': None, 'is_single_select': False, 'name': 'collective.taxonomy.generated.categorievent'} # {'field_description': '', 'title': 'Cat\xc3\xa9gories \xc3\xa9v\xc3\xa9nements','description': '', 'is_required': False, 'default_language': 'fr', 'write_permission': None, 'is_single_select': False, 'name': 'collective.taxonomy.generated.categoriesevenements'} # {'field_description': None, # 'title': u'Cat\xe9gorie', tax['field_title'] = tax['title'] # 'description': None, tax['is_required'] = False tax['write_permission'] = None tax['is_single_select'] = False # 'name': 'collective.taxonomy.generated.categorievent'} taxonomy.registerBehavior(**tax) logger.info('Taxonomy {0} imported'.format(tax['name']))
def __setattr__(self, attr, value): if attr in ['taxonomy']: return if 'import_file' is attr and value is not None: import_file = value.data adapter = TaxonomyImportExportAdapter(self.__dict__['context']) adapter.importDocument(self.utility, import_file) else: if attr == 'field_title': self.__dict__['utility'].title = value if attr == 'field_description': self.__dict__['utility'].description = value if attr == 'default_language': self.__dict__['utility'].default_language = value setattr(self.__dict__['behavior'], attr, value)
def create_taxonomy_object(data_tax, portal): taxonomy = registerTaxonomy( api.portal.get(), name=data_tax["taxonomy"], title=data_tax["field_title"], description=data_tax["field_description"], default_language=data_tax["default_language"], ) adapter = TaxonomyImportExportAdapter(portal) data_path = os.path.join(os.path.dirname(__file__), "data") file_path = os.path.join(data_path, data_tax["filename"]) data = (open(file_path, "r").read(), ) import_file = data[0] adapter.importDocument(taxonomy, import_file) del data_tax["taxonomy"] del data_tax["filename"] taxonomy.registerBehavior(**data_tax)
def create_taxonomy_object(data_tax, portal): taxonomy = registerTaxonomy( api.portal.get(), name=data_tax["taxonomy"], title=data_tax["field_title"], description=data_tax["field_description"], default_language=data_tax["default_language"], ) adapter = TaxonomyImportExportAdapter(portal) data_path = os.path.join(os.path.dirname(__file__), "data") file_path = os.path.join(data_path, data_tax["filename"]) data = (open(file_path, "r").read(),) import_file = data[0] adapter.importDocument(taxonomy, import_file) del data_tax["taxonomy"] del data_tax["filename"] taxonomy.registerBehavior(**data_tax)
def post_install(context): """ Post install script """ site = context.aq_parent language = 'en' if IS_PLONE_4: directory = '/profiles/plone4imports/' else: directory = '/profiles/plone5imports/' for name, title in TAXONOMIES.items(): taxonomy = registerTaxonomy(site, name, title, language, 'Created at install') path = os.path.dirname(os.path.realpath(__file__)) path += directory + name + '.xml' with open(path) as xmlfile: data = xmlfile.read().encode() import_adapter = TaxonomyImportExportAdapter(site) import_adapter.importDocument(taxonomy, data)