Skip to content

UploadFileForm: filter uploadable files to Excel spreadsheets#73

Open
alxndrsn wants to merge 1 commit into
getodk:masterfrom
alxndrsn:filter-upload-files
Open

UploadFileForm: filter uploadable files to Excel spreadsheets#73
alxndrsn wants to merge 1 commit into
getodk:masterfrom
alxndrsn:filter-upload-files

Conversation

@alxndrsn

@alxndrsn alxndrsn commented Aug 3, 2023

Copy link
Copy Markdown

Untested.

This change should filter files shown in the native file picker so that only .xls and .xlsx files are visible. This might be a usability improvement.

Comment thread xlsform_app/views.py

class UploadFileForm(forms.Form):
file = forms.FileField()
file = forms.FileField(attrs={ 'accept': '.xls, .xlsx' })

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You made this change to Central, and I've been a fan! However, when I checked this out locally, I saw an error:

  File "xlsform-online/xlsform_app/views.py", line 21, in UploadFileForm
    file = forms.FileField(attrs={ 'accept': '.xls, .xlsx' })
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/forms/fields.py", line 562, in __init__
    super().__init__(**kwargs)
TypeError: Field.__init__() got an unexpected keyword argument 'attrs'

I did a quick search, but I don't see an extremely simple option along these lines. Possibly you pass a FileInput as a widget to the FileField and specify accept on the FileInput?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing! It would be great to be able to run this project locally. 👋 #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants