Exemplo n.º 1
0
 def test_get_updated_sds_english(self):
     since = datetime.datetime(2011, 1, 1)
     updated = sd_client.getUpdatedServiceDescriptions(since, lang='en')
     self.assertTrue(len(updated) > 0)
     updated_ids = [
         x['tjenestebeskrivelseID']['tjenesteID'] for x in updated
     ]
     self.assertEqual(len(updated_ids), len(set(updated_ids)))
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
 def test_get_updated_sds_english(self):
     since = datetime.datetime(2011, 1, 1)
     updated = sd_client.getUpdatedServiceDescriptions(since, lang='en')
     self.assertTrue(len(updated) > 0)
     updated_ids = [x['tjenestebeskrivelseID']['tjenesteID'] for x in updated]
     self.assertEqual(len(updated_ids), len(set(updated_ids)))