コード例 #1
0
    def _handlePost(self):
        """ A POST fo the Edit-IRI can do one of two things. You can either add
            more metadata by posting an atom entry, or you can publish the
            module with an empty request and In-Progress set to false.
        """
        context = aq_inner(self.context)
        content_type = getHeader(self.request, 'Content-Type', '')
        if content_type.startswith('application/atom+xml'):
            # Apply more metadata to the item
            parent = context.aq_parent
            adapter = getMultiAdapter((parent, self.request),
                                      ISWORDContentUploadAdapter)

            body = self.request.get('BODYFILE')
            body.seek(0)
            adapter.updateMetadata(self.context, parse(body))
        elif content_type:
            # A content type is provided, and its not atom+xml
            raise BadRequest(
                "You cannot POST content of type %s to the SE-IRI" %
                content_type)

        # If In-Progress is set to false or omitted, try to publish
        in_progress = getHeader(self.request, 'In-Progress', 'false')
        if in_progress == 'false':
            self._handlePublish()
            # We SHOULD return a deposit receipt, status code 200, and the
            # Edit-IRI in the Location header.
            self.request.response.setHeader(
                'Location', '%s/sword' % context.absolute_url())
            self.request.response.setStatus(200)

        view = context.unrestrictedTraverse('@@sword')
        return view._handleGet()
コード例 #2
0
    def _handlePost(self):
        """ A POST fo the Edit-IRI can do one of two things. You can either add
            more metadata by posting an atom entry, or you can publish the
            module with an empty request and In-Progress set to false.
        """
        context = aq_inner(self.context)
        content_type = getHeader(self.request, 'Content-Type', '')
        if content_type.startswith('application/atom+xml'):
            # Apply more metadata to the item
            parent = context.aq_parent
            adapter = getMultiAdapter(
                (parent, self.request), ISWORDContentUploadAdapter)

            body = self.request.get('BODYFILE')
            body.seek(0)
            adapter.updateMetadata(self.context, parse(body))
        elif content_type:
            # A content type is provided, and its not atom+xml
            raise BadRequest(
                "You cannot POST content of type %s to the SE-IRI" % content_type)

        # If In-Progress is set to false or omitted, try to publish
        in_progress = getHeader(self.request, 'In-Progress', 'false')
        if in_progress == 'false':
            self._handlePublish()
            # We SHOULD return a deposit receipt, status code 200, and the
            # Edit-IRI in the Location header.
            self.request.response.setHeader('Location',
                '%s/sword' % context.absolute_url())
            self.request.response.setStatus(200)

        view = context.unrestrictedTraverse('@@sword')
        return view._handleGet()
コード例 #3
0
    def wrapper(*args, **kwargs):
        self = args[0]

        def _abort_and_show(status, **kw):
            transaction.abort()
            self.request.response.setStatus(status)
            view = ViewPageTemplateFile('errordocument.pt')
            if view.__class__.__name__ == 'ZopeTwoPageTemplateFile':
                # Zope 2.9
                return ViewPageTemplateFile('errordocument.pt').__of__(
                    self.context)(**kw)
            else:
                # Everthing else
                return ViewPageTemplateFile('errordocument.pt')(self, **kw)

        try:
            if getHeader(self.request, 'On-Behalf-Of') is not None:
                raise MediationNotAllowed, "Mediation not allowed"
            value = func(*args, **kwargs)
        except MethodNotAllowed, e:
            return _abort_and_show(
                405,
                title="Method Not Allowed",
                summary="Method not allowed",
                treatment=str(e),
                href="http://purl.org/net/sword/error/MethodNotAllowed")
コード例 #4
0
    def _handlePost(self):
        # First attempt to treat the content as something with an EditIRI.
        # Collections won't have one. We have to do it this way round
        # as our content is often Folderish and is mistaken for collections.
        adapter = queryMultiAdapter((aq_inner(self.context), self.request),
                                    ISWORDEditIRI)
        if adapter:
            return adapter._handlePost()

        # If our context does not have an Edit-IRI, treat it as a collection
        adapter = getMultiAdapter((aq_inner(self.context), self.request),
                                  ISWORDContentUploadAdapter)
        ob = adapter()

        # Get the Edit-IRI
        ob = ob.__of__(self.context)
        view = getMultiAdapter((ob, self.request), ISWORDEditIRI)

        # Optionally publish
        if getHeader(self.request, 'In-Progress', 'false') == 'false':
            view._handlePublish()

        # We must return status 201, and Location must be set to the edit IRI
        self.request.response.setHeader('Location',
                                        '%s/sword' % ob.absolute_url())
        self.request.response.setStatus(201)

        # Return the optional deposit receipt
        return view._handleGet(upload=True)
コード例 #5
0
    def _handlePost(self):
        # First attempt to treat the content as something with an EditIRI.
        # Collections won't have one. We have to do it this way round
        # as our content is often Folderish and is mistaken for collections.
        adapter = queryMultiAdapter(
            (aq_inner(self.context), self.request), ISWORDEditIRI)
        if adapter:
            return adapter._handlePost()

        # If our context does not have an Edit-IRI, treat it as a collection
        adapter = getMultiAdapter(
            (aq_inner(self.context), self.request), ISWORDContentUploadAdapter)
        ob = adapter()

        # Get the Edit-IRI
        ob = ob.__of__(self.context)
        view = getMultiAdapter((ob, self.request), ISWORDEditIRI)

        # Optionally publish
        if getHeader(self.request, 'In-Progress', 'false') == 'false':
            view._handlePublish()

        # We must return status 201, and Location must be set to the edit IRI
        self.request.response.setHeader('Location', '%s/sword' % ob.absolute_url())
        self.request.response.setStatus(201)

        # Return the optional deposit receipt
        return view._handleGet(upload=True)
コード例 #6
0
 def wrapper(*args, **kwargs):
     self = args[0]
     def _abort_and_show(status, **kw):
         transaction.abort()
         self.request.response.setStatus(status)
         view = ViewPageTemplateFile('errordocument.pt')
         if view.__class__.__name__ == 'ZopeTwoPageTemplateFile':
             # Zope 2.9
             return ViewPageTemplateFile('errordocument.pt').__of__(
                 self.context)(**kw)
         else:
             # Everthing else
             return ViewPageTemplateFile('errordocument.pt')(self, **kw)
     try:
         if getHeader(self.request, 'On-Behalf-Of') is not None:
             raise MediationNotAllowed, "Mediation not allowed"
         value = func(*args, **kwargs)
     except MethodNotAllowed, e:
         return _abort_and_show(405, title="Method Not Allowed",
             summary="Method not allowed",
             treatment=str(e),
             href="http://purl.org/net/sword/error/MethodNotAllowed")