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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xlsform_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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



def clean_name(name):
Expand Down