示例#1
0
    def handleAdd(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        body = {}
        if 'file_type' in data.keys():
            file_type = data['file_type']
        else:
            raise ActionExecutionError(Invalid(
                _(u"Error creating the report,please try again")))
        if 'IBasic.title' in data.keys():
            body['titulo'] = data['IBasic.title'].encode("utf-8", "ignore")
        if 'file_id' in data.keys():
            body['archivo'] = data['file_id']
        body['tipo'] = 'soy-reportero'
        
        multimedia_connect = MultimediaConnect()
        response, content = multimedia_connect.create_structure(body, file_type)

        if 'status' not in response.keys() or response['status'] != '200':
            raise ActionExecutionError(Invalid(_(u"Error creating the report,\
                please try again")))
        slug = None
        if "slug" in content:
            slug = content['slug']
        else:
            raise ActionExecutionError(Invalid(_(u"Error creating the report,\
                please try again")))

        data['file_slug'] = slug
        obj = self.createAndAdd(data)
        if obj is not None:
            # mark only as finished if we get the new object
            obj.file_slug = slug
            obj.reindexObject()
            self._finishedAdd = True
            IStatusMessage(self.request).addStatusMessage(_(u"Item created"),
                "info")

        return obj
示例#2
0
    def handleSaveAndSend(self, action):
        slug = None
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        if 'edited_file_id' in data.keys() and \
            self.context.edited_file_id != data['edited_file_id']:
            body = {}
            if 'file_type' in data.keys():
                file_type = data['file_type']
            else:
                raise ActionExecutionError(Invalid(
                    _(u"Error creating the report, please try again")))
            if 'IBasic.title' in data.keys():
                body['titulo'] = data['IBasic.title']
            if 'IBasic.description' in data.keys():
                body['descripcion'] = data['IBasic.description']
            body['archivo'] = data['edited_file_id']
            body['tipo'] = 'soy-reportero'

            multimedia_connect = MultimediaConnect()
            response, content = multimedia_connect.create_structure(body, file_type)
            slug = None
            if "slug" in content:
                slug = content['slug']
            if 'status' not in response.keys() or response['status'] != '200'\
                or not slug:
                raise ActionExecutionError(Invalid(_(u"Error creating the \
                    report, please try again")))
            data['edited_file_slug'] = slug
            if slug:
                self.context.edited_file_slug = slug
                self.context.reindexObject()
        self.applyChanges(data)
        IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"),
            "info")
        self.request.response.redirect(self.nextURL())
        notify(EditFinishedEvent(self.context))