New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3: File contents not rendered in ZMI #240

Closed
icemac opened this Issue Jan 17, 2018 · 2 comments

Comments

2 participants
@icemac
Member

icemac commented Jan 17, 2018

When uploading a text/plain file to a File object in the ZMI Python 2 and Python 3 behave differently:

  • Python 2: The file contents are rendered in the text area and can be edited
  • Python 3: The text area renders something like <File at my-file> and prevents saving the form with TypeError('Data can only be bytes or file-like. Unicode objects are expressly forbidden.',) even when trying to change some other fields.

I think the Python 2 behaviour is way more useful.

@icemac icemac added the help wanted label Jan 17, 2018

@icemac icemac added this to To do in Zope 4 final release Jul 12, 2018

@icemac

This comment has been minimized.

Show comment
Hide comment
@icemac

icemac Aug 30, 2018

Member

Ideas to resolve this issue:

  • Add a __str__ method for Python 3 returning a text representation of the file content to render the file in the browser.
  • manage_edit gets a text representation: decode it to bytes in Python 3.
  • As encoding the value of management_page_charset should be used . The default for this attribute is currently defined in App/dtml/manage_page_header.dtml. This could be moved as default_management_page_charset to the Request class. Arguably HTTPRequest.HTTPRequest.charset could be used, so it can be set by the ZConfig parameter default-zpublisher-encoding. But I'm not sure if this is the intend for default-zpublisher-encoding.

Additionally since the merge of #249 no file can be uploaded. (This should be fixed and tested, too.)

Member

icemac commented Aug 30, 2018

Ideas to resolve this issue:

  • Add a __str__ method for Python 3 returning a text representation of the file content to render the file in the browser.
  • manage_edit gets a text representation: decode it to bytes in Python 3.
  • As encoding the value of management_page_charset should be used . The default for this attribute is currently defined in App/dtml/manage_page_header.dtml. This could be moved as default_management_page_charset to the Request class. Arguably HTTPRequest.HTTPRequest.charset could be used, so it can be set by the ZConfig parameter default-zpublisher-encoding. But I'm not sure if this is the intend for default-zpublisher-encoding.

Additionally since the merge of #249 no file can be uploaded. (This should be fixed and tested, too.)

sallner added a commit that referenced this issue Sep 4, 2018

sallner added a commit that referenced this issue Sep 4, 2018

sallner added a commit that referenced this issue Sep 4, 2018

@icemac

This comment has been minimized.

Show comment
Hide comment
@icemac

icemac Sep 4, 2018

Member

Instead of a default_management_page_charset I'd prefer to remove the support for management_page_charset now, see #313.

Member

icemac commented Sep 4, 2018

Instead of a default_management_page_charset I'd prefer to remove the support for management_page_charset now, see #313.

sallner added a commit that referenced this issue Sep 4, 2018

@icemac icemac moved this from To do to Needs review in Zope 4 final release Oct 1, 2018

@icemac icemac closed this in #312 Oct 2, 2018

Zope 4 final release automation moved this from Needs review to Done Oct 2, 2018

icemac added a commit that referenced this issue Oct 2, 2018

Fix manage_edit of File (#312)
re #240:

* Ensure working file upload.
* Render the file content in textarea if it can be decoded.
* Edit content of text file with Python 3.
* Add changelog and documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment