Exemplo n.º 1
0
    def _add_article(self, article, municipality, enable_toc):
        title = article.ArticleTitle
        name = queryUtility(IURLNormalizer).normalize(title)
        container = self.context.restrictedTraverse('@@plone').getCurrentFolder()

        if name in container.objectIds():
            raise AlreadyExists(name)

        # create document
        name = container.invokeFactory(id=name, type_name='Document')
        document = container[name]

        # set initial content
        update_content(document, article)

        # annotate article metadata
        metadata = get_article_metadata(document)
        metadata.id = article.ArticleID
        metadata.url = article.ArticleUrl
        metadata.municipality = municipality

        # Enable TOC if setting is enabled
        document.setTableContents(enable_toc)

        # set review state directly (no transition is available for this)
        wftool = getToolByName(self.context, 'portal_workflow')
        status = wftool.getStatusOf('synchronizable_document_workflow', document)
        status['review_state'] = 'synchronized'
        document.reindexObject()

        return name
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 get_url(self):
     metadata = get_article_metadata(self.context)
     return metadata.url