开发者

Django: handling browser's BACK button in file uploads

I'm making a site that has a 3-step form process.

Step 1: let me know how many files you're uploading

Step 2: generate # of forms depending on the # of files, and allow upload

Step 3: payment

Suppose some guy goes to step 3, but then changes his mind and goes all the back to step 1.

Step 1 is easy enough, all I have to do is put a variable in the session and then just update the existing record if there's an active order happening (instead of creating a new one).

Step 2 gets difficult. Say the guy went back and changed Step 1's # of files, changing the # of forms displayed on Step 2. Also say that he decides to change several of the files he uploaded.

The only thing I can think of here is to completely delete all the files the guy originally uploaded in his first time through the site, delete all the database records associated with those files, and just start from the beginning. If I don't do that, I run into some weird problems of comparing the new files he uploaded to my old files to see if they've changed... that just seems like a lot of hassle and more time consuming than simply deleting them.

In the same vein, if the user clicked on "browse" again to upload a new file, is there a way for me to know they've changed that field? If the name of the file is exactly the same then you'd have to compare the new one with the old one.

But if I just outright delete everything it's gonna create problems for the user. If he originally uploaded 10 files, but now decides that he wants to upload 12 files, except he wants to keep the 8 out of the original 10 files and all the associated information the same then upload 4 new files - he ends up having to do all 12 files from scratch again.

I suppose I could 开发者_C百科pre-populate Step 2 with what I've got in the database so far, but then I still run into having to compare the new files vs. the ones I have right now.

Is there a better way to do this? Never realized how big of a pain the BACK button is....


Why you want to allow user to go from step 3 to step 2?

Anyway, you shouldn't compare files! Just write new ones. And files, that are not bounded to user - can be deleted in background.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜