Example #1
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)
Example #2
0
def check_url(url):
    if not urlparse.urlparse(url)[1].endswith('borger.dk'):
        raise Invalid(_(u"Must be a URL from borger.dk."))

    return True
Example #3
0
from plone.i18n.normalizer.interfaces import IURLNormalizer
from plone.memoize.volatile import cache
from plone.app.z3cform.layout import wrap_form
from plone.z3cform import z2

from Products.statusmessages.interfaces import IStatusMessage
from Products.CMFCore.utils import getToolByName

from collective.borgerdk import MessageFactory as _
from collective.borgerdk import portal
from collective.borgerdk.content import get_article_metadata
from collective.borgerdk.content import update_content

NOT_AN_ARTICLE = _(
    u"No article information found at location. " \
    u"Make sure the link is for an article and " \
    u"not a news item or similar."
    )
NO_PERMANENT_LOCATION = _(u"Unable to find permanent link at location.")
CANT_DOWNLOAD = _(u"Unable to download page.")
CANT_PARSE = _(u"Unable to parse document.")
CANT_ADD = _(u"Unable to add article.")
SYSTEM_ERROR = _(u"System error.")
ALREADY_EXISTS = _(u"Article already exists.")
ADDED = _(u"Article added.")


def status(request, message, type='info'):
    IStatusMessage(request).addStatusMessage(
        message, type=type)