def importActiveServiceDescriptions(context): lang = context.Language() or 'no' ct = getToolByName(context, 'portal_catalog') existing = ct.unrestrictedSearchResults(portal_type='ServiceDescription', Language=lang) for brain in list(existing): obj = brain.getObject() parent = aq_parent(obj) del parent[obj.getId()] active_sd_ids = [sd['tjenestebeskrivelseID'] for sd in sd_client.getActiveServiceDescriptionsOverview(lang=lang)] pu = getToolByName(context, 'plone_utils') for sd_id in active_sd_ids: internal_id = sd_id['tjenesteID'] data = getServiceDescriptionData(context, sd_id) text = context.restrictedTraverse('@@sd-template')(data=data) los_categories = [brain.getObject() for brain in data['topic_refs']] logger.info("Creating service description '%s'" % data['title']) new_id = context.invokeFactory('ServiceDescription', id_from_title(data['title'], locale=lang), serviceId=internal_id, title=data['title'], description=data['description'], nationalText=text, text=text, los_categories=los_categories, subject=data['keywords'], language=lang) context[new_id].unmarkCreationFlag() if lang != 'no': linkTranslation(context[new_id], internal_id) pu.changeOwnershipOf(context[new_id], 'updater') context[new_id].reindexObject() registry = getUtility(IRegistry) # XXX: Should store time per language if lang == 'no': registry['jarn.kommuner.lastUpdate'] = datetime.now() logger.info('done')
def updateActiveServiceDescriptions(context): lang = context.Language() or 'no' ct = getToolByName(context, 'portal_catalog') registry = getUtility(IRegistry) last_update = registry['jarn.kommuner.lastUpdate'] # XXX: Should store time per language if lang == 'no': registry['jarn.kommuner.lastUpdate'] = datetime.now() updated_ids = [ sd['tjenestebeskrivelseID'] for sd in sd_client.getUpdatedServiceDescriptions(last_update, lang=lang) ] pu = getToolByName(context, 'plone_utils') for sd_id in updated_ids: data = getServiceDescriptionData(context, sd_id) text = context.restrictedTraverse('@@sd-template')(data=data) los_categories = [brain.getObject() for brain in data['topic_refs']] sd = ct.unrestrictedSearchResults(serviceId=sd_id['tjenesteID'], Language=lang) if not sd: internal_id = sd_id['tjenesteID'] logger.info("Creating service description '%s'" % data['title']) new_id = context.invokeFactory('ServiceDescription', id_from_title(data['title'], locale=lang), serviceId=internal_id, title=data['title'], description=data['description'], nationalText=text, text=text, los_categories=los_categories, subject=data['keywords'], language=lang) context[new_id].unmarkCreationFlag() if lang != 'no': linkTranslation(context[new_id], internal_id) pu.changeOwnershipOf(context[new_id], 'updater') context[new_id].reindexObject() ev = ServiceDescriptionCreated(context[new_id]) notify(ev) else: sd = sd[0].getObject() logger.info("Updating service description '%s'" % data['title']) ev = ServiceDescriptionUpdated(sd, text, data) notify(ev)
def importActiveServiceDescriptions(context): lang = context.Language() or 'no' ct = getToolByName(context, 'portal_catalog') existing = ct.unrestrictedSearchResults(portal_type='ServiceDescription', Language=lang) for brain in list(existing): obj = brain.getObject() parent = aq_parent(obj) del parent[obj.getId()] active_sd_ids = [ sd['tjenestebeskrivelseID'] for sd in sd_client.getActiveServiceDescriptionsOverview(lang=lang) ] pu = getToolByName(context, 'plone_utils') for sd_id in active_sd_ids: internal_id = sd_id['tjenesteID'] data = getServiceDescriptionData(context, sd_id) text = context.restrictedTraverse('@@sd-template')(data=data) los_categories = [brain.getObject() for brain in data['topic_refs']] logger.info("Creating service description '%s'" % data['title']) new_id = context.invokeFactory('ServiceDescription', id_from_title(data['title'], locale=lang), serviceId=internal_id, title=data['title'], description=data['description'], nationalText=text, text=text, los_categories=los_categories, subject=data['keywords'], language=lang) context[new_id].unmarkCreationFlag() if lang != 'no': linkTranslation(context[new_id], internal_id) pu.changeOwnershipOf(context[new_id], 'updater') context[new_id].reindexObject() registry = getUtility(IRegistry) # XXX: Should store time per language if lang == 'no': registry['jarn.kommuner.lastUpdate'] = datetime.now() logger.info('done')
def updateActiveServiceDescriptions(context): lang = context.Language() or 'no' ct = getToolByName(context, 'portal_catalog') registry = getUtility(IRegistry) last_update = registry['jarn.kommuner.lastUpdate'] # XXX: Should store time per language if lang == 'no': registry['jarn.kommuner.lastUpdate'] = datetime.now() updated_ids = [sd['tjenestebeskrivelseID'] for sd in sd_client.getUpdatedServiceDescriptions(last_update, lang=lang)] pu = getToolByName(context, 'plone_utils') for sd_id in updated_ids: data = getServiceDescriptionData(context, sd_id) text = context.restrictedTraverse('@@sd-template')(data=data) los_categories = [brain.getObject() for brain in data['topic_refs']] sd = ct.unrestrictedSearchResults(serviceId=sd_id['tjenesteID'], Language=lang) if not sd: internal_id = sd_id['tjenesteID'] logger.info("Creating service description '%s'" % data['title']) new_id = context.invokeFactory('ServiceDescription', id_from_title(data['title'], locale=lang), serviceId=internal_id, title=data['title'], description=data['description'], nationalText=text, text=text, los_categories=los_categories, subject=data['keywords'], language=lang) context[new_id].unmarkCreationFlag() if lang != 'no': linkTranslation(context[new_id], internal_id) pu.changeOwnershipOf(context[new_id], 'updater') context[new_id].reindexObject() ev = ServiceDescriptionCreated(context[context_id]) notify(ev) else: sd = sd[0].getObject() logger.info("Updating service description '%s'" % data['title']) ev = ServiceDescriptionUpdated(sd, text, data) notify(ev)
def setupLOSContent(context): if context.readDataFile('kommuner-content.txt') is None: return parents = dict() synonyms = dict() synonym_ids = dict() portal = context.getSite() wftool = getToolByName(portal, "portal_workflow") xml_file = os.path.join(os.path.dirname(__file__), 'data', 'los-alt.xml') tree = ET.parse(xml_file) groups = tree.findall('//emne-gruppe') associations = tree.findall('//assosiasjon-gruppe') hierarchy_associations = associations[0] synonym_associations = associations[1] topic_group = groups[0] topic_elements = [ elem for elem in topic_group if elem.find('identifikator').text != "http://psi.norge.no/los/tema/temastruktur" ] synonym_group = groups[1] synonym_elements = [elem for elem in synonym_group] for association in hierarchy_associations: elems = association.findall('.//medlem') parent_id = [ elem.attrib['referanse'] for elem in elems if elem.attrib['type'] == 'http://www.techquila.com/psi/thesaurus/#broader' ][0] child_id = [ elem.attrib['referanse'] for elem in elems if elem.attrib['type'] == 'http://www.techquila.com/psi/thesaurus/#narrower' ][0] if parent_id == "http://psi.norge.no/los/tema/temastruktur": parent_id = None parents[child_id] = parent_id for association in synonym_associations: elems = association.findall('.//medlem') topic_id = [ elem.attrib['referanse'] for elem in elems if elem.attrib['type'] == 'http://www.techquila.com/psi/thesaurus/#broader' ][0] word_id = [ elem.attrib['referanse'] for elem in elems if elem.attrib['type'] == 'http://www.techquila.com/psi/thesaurus/#narrower' ][0] if topic_id not in synonyms: synonyms[topic_id] = set() synonym_ids[topic_id] = set() for elem in synonym_elements: if elem.find('identifikator').text == word_id: synonyms[topic_id].add(unicode(elem.find('namn').text)) synonym_ids[topic_id].add(word_id) break main_topics = [] sub_topics = [] for elem in topic_elements: topic_id = elem.find('identifikator').text if parents[topic_id] is None: main_topics.append(elem) else: sub_topics.append(elem) if 'tema' not in portal.objectIds(): portal.invokeFactory('Folder', 'tema', title='Tema') tema_folder = portal['tema'] tema_folder.unmarkCreationFlag() tema_folder.setExcludeFromNav(True) tema_folder.setLayout('tema_view') wftool.doActionFor(tema_folder, 'publish') tema_folder.reindexObject() tema_folder = portal['tema'] existing = tema_folder.objectIds(['LOSCategory']) for topic_id in existing: del tema_folder[topic_id] for elem in main_topics: title = unicode(elem.find('namn').text) topic_id = elem.find('identifikator').text folder_id = tema_folder.invokeFactory('LOSCategory', id_from_title(title), title=title, losId=topic_id) folder = tema_folder[folder_id] folder.unmarkCreationFlag() wftool.doActionFor(folder, 'publish') folder.reindexObject() for subtopic in sub_topics: subtopic_id = subtopic.find('identifikator').text if parents[subtopic_id] == topic_id: title = unicode(subtopic.find('namn').text) subtopic_synonyms = [] subtopic_synonym_ids = [] if subtopic_id in synonyms: subtopic_synonyms = synonyms[subtopic_id] if subtopic_id in synonym_ids: subtopic_synonym_ids = synonym_ids[subtopic_id] subfolder_id = folder.invokeFactory( 'LOSCategory', id_from_title(title), title=title, losId=subtopic_id, synonyms=subtopic_synonyms, synonymIds=subtopic_synonym_ids) subfolder = folder[subfolder_id] subfolder.unmarkCreationFlag() wftool.doActionFor(subfolder, 'publish') subfolder.reindexObject()
def test_norwegian_id_from_title_utf8(self): self.assertEqual(id_from_title('Jeg kjører til Ålesund for været'), 'jeg-kjorer-til-alesund-for-vaeret')
def setupLOSContent(context): if context.readDataFile('kommuner-content.txt') is None: return parents = dict() synonyms = dict() synonym_ids = dict() portal = context.getSite() wftool = getToolByName(portal, "portal_workflow") xml_file = os.path.join(os.path.dirname(__file__), 'data', 'los-alt.xml') tree = ET.parse(xml_file) groups = tree.findall('//emne-gruppe') associations = tree.findall('//assosiasjon-gruppe') hierarchy_associations = associations[0] synonym_associations = associations[1] topic_group = groups[0] topic_elements = [elem for elem in topic_group if elem.find('identifikator').text != "http://psi.norge.no/los/tema/temastruktur"] synonym_group = groups[1] synonym_elements = [elem for elem in synonym_group] for association in hierarchy_associations: elems = association.findall('.//medlem') parent_id = [elem.attrib['referanse'] for elem in elems if elem.attrib['type'] == 'http://www.techquila.com/psi/thesaurus/#broader'][0] child_id = [elem.attrib['referanse'] for elem in elems if elem.attrib['type'] == 'http://www.techquila.com/psi/thesaurus/#narrower'][0] if parent_id == "http://psi.norge.no/los/tema/temastruktur": parent_id = None parents[child_id] = parent_id for association in synonym_associations: elems = association.findall('.//medlem') topic_id = [elem.attrib['referanse'] for elem in elems if elem.attrib['type'] == 'http://www.techquila.com/psi/thesaurus/#broader'][0] word_id = [elem.attrib['referanse'] for elem in elems if elem.attrib['type'] == 'http://www.techquila.com/psi/thesaurus/#narrower'][0] if topic_id not in synonyms: synonyms[topic_id] = set() synonym_ids[topic_id] = set() for elem in synonym_elements: if elem.find('identifikator').text == word_id: synonyms[topic_id].add(unicode(elem.find('namn').text)) synonym_ids[topic_id].add(word_id) break main_topics = [] sub_topics = [] for elem in topic_elements: topic_id = elem.find('identifikator').text if parents[topic_id] is None: main_topics.append(elem) else: sub_topics.append(elem) if 'tema' not in portal.objectIds(): portal.invokeFactory('Folder', 'tema', title='Tema') tema_folder = portal['tema'] tema_folder.unmarkCreationFlag() tema_folder.setExcludeFromNav(True) tema_folder.setLayout('tema_view') wftool.doActionFor(tema_folder, 'publish') tema_folder.reindexObject() tema_folder = portal['tema'] existing = tema_folder.objectIds(['LOSCategory']) for topic_id in existing: del tema_folder[topic_id] for elem in main_topics: title = unicode(elem.find('namn').text) topic_id = elem.find('identifikator').text folder_id = tema_folder.invokeFactory('LOSCategory', id_from_title(title), title=title, losId=topic_id) folder = tema_folder[folder_id] folder.unmarkCreationFlag() wftool.doActionFor(folder, 'publish') folder.reindexObject() for subtopic in sub_topics: subtopic_id = subtopic.find('identifikator').text if parents[subtopic_id] == topic_id: title = unicode(subtopic.find('namn').text) subtopic_synonyms = [] subtopic_synonym_ids = [] if subtopic_id in synonyms: subtopic_synonyms = synonyms[subtopic_id] if subtopic_id in synonym_ids: subtopic_synonym_ids = synonym_ids[subtopic_id] subfolder_id = folder.invokeFactory('LOSCategory', id_from_title(title), title=title, losId=subtopic_id, synonyms=subtopic_synonyms, synonymIds=subtopic_synonym_ids) subfolder = folder[subfolder_id] subfolder.unmarkCreationFlag() wftool.doActionFor(subfolder, 'publish') subfolder.reindexObject()