Skip to content

Commit fd3fc2a

Browse files
author
Jan Schrewe
committed
get the filename for uploaded files after an old file has been deleted
1 parent e071760 commit fd3fc2a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

mongodbforms/documents.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
from .fieldgenerator import MongoDefaultFormFieldGenerator
2525
from .documentoptions import DocumentMetaWrapper
26-
2726
from .util import with_metaclass
2827

2928

@@ -48,9 +47,9 @@ def __init__(self, key, field):
4847

4948
self._fields[key] = field
5049

51-
# don't care if anything gets marked on this
50+
# We don't care if anything gets marked on this
5251
# we do update a real field later though. That should
53-
# trigger the same thing on the real document though.
52+
# trigger the same thing on the real document.
5453
def _mark_as_changed(self, key):
5554
pass
5655

@@ -59,8 +58,6 @@ def _save_iterator_file(field, uploaded_file, file_data=None):
5958
Takes care of saving a file for a list field. Returns a Mongoengine
6059
fileproxy object or the file field.
6160
"""
62-
uploaded_file.seek(0)
63-
filename = _get_unique_filename(uploaded_file.name)
6461
fake_document = FakeDocument(field.name, field.field)
6562
overwrote_instance = False
6663
overwrote_key = False
@@ -79,7 +76,9 @@ def _save_iterator_file(field, uploaded_file, file_data=None):
7976

8077
if file_data.grid_id:
8178
file_data.delete()
82-
79+
80+
uploaded_file.seek(0)
81+
filename = _get_unique_filename(uploaded_file.name)
8382
file_data.put(uploaded_file, content_type=uploaded_file.content_type, filename=filename)
8483
file_data.close()
8584

@@ -123,7 +122,7 @@ def construct_instance(form, instance, fields=None, exclude=None, ignore=None):
123122
if isinstance(f, MapField):
124123
map_field = getattr(instance, f.name)
125124
uploads = cleaned_data[f.name]
126-
for key, uploaded_file in uploads.items():
125+
for key, uploaded_file in uploads.items():
127126
if uploaded_file is None:
128127
continue
129128
file_data = map_field.get(key, None)

0 commit comments

Comments
 (0)