Skip to content

Commit

Permalink
Merge pull request #88 from jedie/req_update_20231107-19
Browse files Browse the repository at this point in the history
Update requirements
  • Loading branch information
jedie authored Nov 7, 2023
2 parents 71ae032 + 7e5344a commit 7f09a19
Show file tree
Hide file tree
Showing 4 changed files with 1,813 additions and 1,554 deletions.
21 changes: 20 additions & 1 deletion for_runners/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,27 @@
from django import forms


class MultipleFileInput(forms.ClearableFileInput):
# https://docs.djangoproject.com/en/4.2/topics/http/file-uploads/#uploading-multiple-files
allow_multiple_selected = True


class MultipleFileField(forms.FileField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("widget", MultipleFileInput())
super().__init__(*args, **kwargs)

def clean(self, data, initial=None):
single_file_clean = super().clean
if isinstance(data, (list, tuple)):
result = [single_file_clean(d, initial) for d in data]
else:
result = single_file_clean(data, initial)
return result


class UploadGpxFileForm(forms.Form):
gpx_files = forms.FileField(widget=forms.ClearableFileInput(attrs={"multiple": True}))
gpx_files = MultipleFileField()

def send_email(self):
# send email using the self.cleaned_data dictionary
Expand Down
13 changes: 9 additions & 4 deletions for_runners/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ def test_staff_upload(self):
data={"gpx_files": [file1, file2]},
HTTP_ACCEPT_LANGUAGE="en",
)
self.assertEqual(response.status_code, 302, response.content.decode())

# debug_response(response)
assert storage_stats.fields_saved == [
('for_runners', 'gpxmodel', 'track_svg'),
('for_runners', 'gpxmodel', 'gpx_file'),
]
self.assertEqual(
storage_stats.fields_saved,
[
('for_runners', 'gpxmodel', 'track_svg'),
('for_runners', 'gpxmodel', 'gpx_file'),
],
)
assert storage_stats.fields_read == []

tracks = GpxModel.objects.all()
Expand Down
Loading

0 comments on commit 7f09a19

Please sign in to comment.