Let’s say I have the following form with 2 files:
<!-- the field below contains actual upload file -->
<input type=hidden name="http://localhost:XXXX/some_unique_name_generated_by_Picasa_and_not_controlled_by_me">
<!-- the name of field below is equal to the uploaded above filename -->
<input type=hidden name="DSC04310.jpg" value="description of first file">
<input type=hidden name="http://localhost:XXXX/some_unique_name_generated_by_Picasa_and_not_controlled_by_me">
<input type=hidden name="DSC04306.jpg" value="description of second file">
Somehow when they are uploaded, I get them on the server in different sequence – DSC04306.jpg first and then DSC04310.jpg. I use:
arguments = self.request.arguments()
files_arguments = []
for argument in arguments:
if 'localhost' in argument: # choose files only, not other fields
files_arguments.append(argument)
But I need to process them in the same sequence as they were in the form.
I think about the following solution:
<input type=hidden name="http://localhost:XXXX/some_unique_name">
<input type=hidden name="DSC04310.jpg" value="description of first file">
<input type=hidden name="seq_DSC04310.jpg" value="1">
<input type=hidden name="http://localhost:XXXX/some_unique_name">
<input type=hidden name="DSC04306.jpg" value="description of second file">
<input type=hidden name="seq_DSC04306.jpg" value="2">
Is it good approach? If so, then how can I sort values in files_arguments based on values in seq_FILENAME fields?
Don’t use
request.arguments(), unless you want all keys from request including keys from the query string (and not only POST). Also, it is not ordered.Instead, iterate over
request.POSTvalues, because it is ordered. You can userequest.POST.iteritems()orrequest.POST.itervalues():