What is the best Google App Engine blobstore workflow?
What is the best workflow for uploading file to the blobstore while开发者_StackOverflow saving information about the blob and other fields to a model record?
For example, should I submit the form to the blobstore upload url (blobstore.create_upload_url), clean the form, redirect if errors and save and redirect if not?
What is the best way to pass the errors back? GET variables? I tried using models to the save the form errors and redirecting based on the form error model instance, but that was messy. Any ideas?
The solution I've come up with for this is not the prettiest but it gets the job done. On the upload view (view that is specified in the create_upload_url function) I'm passing the post variables to the same form class from the first page. If the form is valid I'm saving the variables along with the BlobInfo.key to the model. If it is not a valid form I'm saving the errors in memcache and redirecting back to the first page with the variable of error that triggers the view to retrieve the errors from memcache and add them to the form instance.
So again here's the steps.
- Create form view
- Check POST variables with the same form from the first view
- If the form is valid save it along with the BlobInfo.key, if not save errors to memcache with a small lifespan and redirect to first view with the memcache key in the url
- Retrieve the form errors from memcache and add them to the new form instance
- Resubmit the form with errors fixed and save
精彩评论