Skip to content
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

UploadFileForm: filter uploadable files to Excel spreadsheets #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alxndrsn
Copy link

@alxndrsn alxndrsn commented Aug 3, 2023

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.

@@ -18,7 +18,7 @@
DJANGO_TMP_HOME = os.environ['DJANGO_TMP_HOME']

class UploadFileForm(forms.Form):
file = forms.FileField()
file = forms.FileField(attrs={ 'accept': '.xls, .xlsx' })
Copy link
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
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.

None yet

2 participants