예제 #1
0
 def test_extract_and_add_attachments(self):
     file_field = self._create_test_file_field()
     extract_and_add_attachments(file_field, self.document)
     attachments = IAttachmentStorage(self.document)
     self.assertEquals(len(attachments.values()), 1)
     res = attachments.get(file_field.filename)
     self.assertEquals(res.id, file_field.filename)
예제 #2
0
 def test_extract_and_add_attachments(self):
     file_field = self._create_test_file_field()
     extract_and_add_attachments(file_field, self.document)
     attachments = IAttachmentStorage(self.document)
     self.assertEquals(len(attachments.values()), 1)
     res = attachments.get(file_field.filename)
     self.assertEquals(res.id, file_field.filename)
예제 #3
0
    def create_post_attachment(self, post):
        """ Check:
         - if the post supports attachments
         - if we have an attachment posted

        If both are True attach the data to the post
        """
        if IAttachmentStoragable is None:
            return
        if not IAttachmentStoragable.providedBy(post):
            return
        if not self.post_attachment:
            return
        token = self.request.get("attachment-form-token")
        extract_and_add_attachments(self.post_attachment, post, workspace=self.context, token=token)
예제 #4
0
    def create_post_attachment(self, post):
        """ Check:
         - if the post supports attachments
         - if we have an attachment posted

        If both are True attach the data to the post
        """
        if not IAttachmentStoragable.providedBy(post):
            return
        if not self.post_attachment:
            return
        token = self.request.get('attachment-form-token')
        extract_and_add_attachments(self.post_attachment,
                                    post,
                                    workspace=self.microblog_context,
                                    token=token)
예제 #5
0
 def test_extract_and_add_attachments_with_token(self):
     token = "{0}-{1}".format(TEST_USER_ID,
                              datetime.utcnow().strftime('%Y%m%d%H%M%S%f'))
     temp_attachment = self._create_test_temp_attachment(token)
     temp_attachments = IAttachmentStorage(self.workspace)
     temp_attachments.add(temp_attachment)
     file_field = self._create_test_file_field()
     extract_and_add_attachments(file_field, self.document, self.workspace,
                                 token)
     attachments = IAttachmentStorage(self.document)
     self.assertEquals(len(attachments.values()), 1)
     self.assertTrue(file_field.filename in attachments.keys())
     res = attachments.get(file_field.filename)
     self.assertEquals(res.id, file_field.filename)
     self.assertTrue('/'.join(res.getPhysicalPath()).startswith('/'.join(
         self.workspace.getPhysicalPath())))
예제 #6
0
 def test_extract_and_add_attachments_with_token(self):
     token = "{0}-{1}".format(
         TEST_USER_ID,
         datetime.utcnow().strftime('%Y%m%d%H%M%S%f'))
     temp_attachment = self._create_test_temp_attachment(token)
     temp_attachments = IAttachmentStorage(self.workspace)
     temp_attachments.add(temp_attachment)
     file_field = self._create_test_file_field()
     extract_and_add_attachments(
         file_field, self.document, self.workspace, token)
     attachments = IAttachmentStorage(self.document)
     self.assertEquals(len(attachments.values()), 1)
     self.assertTrue(file_field.filename in attachments.keys())
     res = attachments.get(file_field.filename)
     self.assertEquals(res.id, file_field.filename)
     self.assertTrue(
         '/'.join(res.getPhysicalPath()).startswith(
             '/'.join(self.workspace.getPhysicalPath())))
예제 #7
0
    def handleComment(self, action):

        # Validation form
        data, errors = self.extractData()
        if errors:
            return

        container = queryUtility(IMicroblogTool)
        microblog_context = get_microblog_context(self.context)
        if hasattr(self.context, 'thread_id') and self.context.thread_id:
            thread_id = self.context.thread_id  # threaded
        elif self.context.__class__.__name__ == 'StatusUpdate':
            thread_id = self.context.id  # first reply
        else:
            thread_id = None  # new
        status = StatusUpdate(data['text'],
                              context=microblog_context,
                              thread_id=thread_id)

        file_upload = self.request.get('form.widgets.attachments')
        attachments_supported = (IAttachmentStoragable is not None
                                 and IAttachmentStoragable.providedBy(status))
        if attachments_supported and file_upload:
            token = self.request.get('attachment-form-token')
            extract_and_add_attachments(file_upload,
                                        status,
                                        workspace=self.context,
                                        token=token)

        # debugging only


#        container.clear()

# save the status update
        container.add(status)

        # Redirect to portal home
        self.request.response.redirect(self.action)
예제 #8
0
    def handleComment(self, action):

        # Validation form
        data, errors = self.extractData()
        if errors:
            return

        container = queryUtility(IMicroblogTool)
        microblog_context = get_microblog_context(self.context)
        if hasattr(self.context, 'thread_id') and self.context.thread_id:
            thread_id = self.context.thread_id  # threaded
        elif self.context.__class__.__name__ == 'StatusUpdate':
            thread_id = self.context.id  # first reply
        else:
            thread_id = None  # new
        status = StatusUpdate(data['text'],
                              context=microblog_context,
                              thread_id=thread_id)

        file_upload = self.request.get('form.widgets.attachments')
        attachments_supported = (
            IAttachmentStoragable is not None and
            IAttachmentStoragable.providedBy(status))
        if attachments_supported and file_upload:
            token = self.request.get('attachment-form-token')
            extract_and_add_attachments(
                file_upload, status, workspace=self.context, token=token)

        # debugging only
#        container.clear()

        # save the status update
        container.add(status)

        # Redirect to portal home
        self.request.response.redirect(self.action)