def Vocabulary(context):
    # get site to store the municipality list as a volatile attribute
    site = getToolByName(context, 'portal_url').getPortalObject()

    try:
        return site._v_municipality_vocabulary
    except AttributeError:
        client = portal.get_client()

        if client is not None:
            logging.info("Requesting municipality list...")
            data = client.service.GetMunicipalityList()
            logging.debug("Received %d items." % len(data))
            municipalities = data[0]
            logging.debug("Received %d municipalities." % len(municipalities))
            terms = [
                SimpleVocabulary.createTerm(
                    m.MunicipalityCode,
                    str(m.MunicipalityCode),
                    unicode(m.MunicipalityName).rsplit('Kommune', 1)[0].strip(),
                    ) for m in municipalities
                ]
        else:
            terms = []

        vocabulary = site._v_municipality_vocabulary = SimpleVocabulary(terms)

    return vocabulary
Exemplo n.º 2
0
    def __call__(self, token):
        registry = getUtility(IRegistry)
        settings = registry.forInterface(IBorgerPortalSettings)

        if token != settings.synchronization_token:
            raise Unauthorized("Token mismatch or missing token.")

        client = get_client()

        # get all synchronized documents
        brains = self.context.portal_catalog(
            portal_type="Document",
            review_state="synchronized"
            )

        for brain in brains:
            document = brain.getObject()
            metadata = get_article_metadata(document)

            # retrieve article
            try:
                article = client.service.GetArticleByID(
                    metadata.id,
                    metadata.municipality
                    )
            except suds.WebFault, exc:
                logging.warn(exc)
                title = document.Title().decode('utf-8')
                IStatusMessage(self.request).addStatusMessage(
                    _(u"Fejl ved opdatering af artikel: ${title}.",
                      mapping={'title': title}),
                    type="warning"
                    )

                continue

            # as unrestricted user ...
            old = security.loginAsUnrestrictedUser()
            try:
                # update document content
                update_content(document, article)
            finally:
                security.loginAsUser(old)
Exemplo n.º 3
0
 def _client(self):
     return portal.get_client()