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 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 test_get_active_sd_english(self): active = sd_client.getActiveServiceDescriptionsOverview(lang='en') active_ids = [x['tjenestebeskrivelseID']['tjenesteID'] for x in active] self.assertEqual(len(active_ids), len(set(active_ids)))