Re-post: Issue when uploading a txt file to create a Page content type in Plone

classic Classic list List threaded Threaded
1 message Options
llcolombo llcolombo
Reply | Threaded
Open this post in threaded view
|

Re-post: Issue when uploading a txt file to create a Page content type in Plone

[I am reposting because my poist did not show in the whole day]

Hi all
I am running Plone 3.3.4 on windows platform, and need to upload a text file
generated by an external program to a specific folder in a Plone site.
I have used this approach for other websites and text files generated by
other programs without hitting any issue, but this time the Page that I get
into the website is missing the first line of text. This happens for any
text file generated by such external program, but I have looked at this file
without seeing anything special about it. Is a Unix file, and it contains
only ascii chars.
I did try to read the file with python and I do read all of the content.

I tried to find out what was going on and traced the manage_afterPUT in the
ATDocumentBase class.
I found out that, whilst the variable "content" is getting all of the text
from file.read(), at that point self.getRawText() returns the text without
the first line. And, as the txt file content is not html, is not manipulated
any longer.

I was not able to find where the text field value was set. The only
workaround I found was to create a custom type based on ATDocument and
override manage_afterPUT to set the text field with "content" as following:

    security.declarePrivate('manage_afterPUT')
    def manage_afterPUT(self, data, marshall_data, file, context, mimetype,
                        filename, REQUEST, RESPONSE):
        """After webdav/ftp PUT method

        Set content to text.
        """
        if '' == data:
            file.seek(0)
            content = file.read(65536)
        else:
            content = data
        if content:
            self.setText(content)

        ATDocument.manage_afterPUT(self, data, marshall_data, file,
                                    context, mimetype, filename, REQUEST,
                                    RESPONSE)

This works, but I still wonder what's going on, if I hit a bug, or what,
what can be in the txt file to hit this issue.

bye
Lucia