Changes between Version 1 and Version 2 of StreamingUpload
- Timestamp:
- Dec 20, 2006, 11:57:05 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
StreamingUpload
v1 v2 17 17 from models import SomeFile 18 18 from django import forms 19 from django.conf import settings 19 20 20 21 class AddFileManipulator(forms.Manipulator): 22 21 23 def __init__(self): 22 24 self.fields = ( 23 25 forms.TextField(field_name="description", length=30, maxlength=200, is_required=True), 24 forms.FileField(field_name="file", is_required=True)26 MyFileUploadField(field_name="file", is_required=True) 25 27 ) 28 29 def do_html2python(self, new_data): 30 31 new_new_data = {} 32 33 new_new_data['file_path'] = os.path.join(settings.MEDIA_ROOT, filename) 34 os.rename(new_data['file'], new_new_data['file_path']) 35 36 new_new_data['description'] = new_data['description'] 37 38 new_data = new_new_data 39 40 def save(self, new_data): 41 new_object = SomeField(**new_data) 42 new_object.save() 26 43 27 44 }}} … … 40 57 # If data was POSTed, we're trying to create a new Place. 41 58 new_data = request.POST.copy() 59 new_data.update(request.FILES) 42 60 43 61 # Check for errors. … … 47 65 # No errors. This means we can save the data! 48 66 manipulator.do_html2python(new_data) 49 new_ place= manipulator.save(new_data)67 new_object = manipulator.save(new_data) 50 68 51 69 # Redirect to the object's "edit" page. Always use a redirect … … 53 71 # duplicate entires, and so users don't see the confusing 54 72 # "Repost POST data?" alert box in their browsers. 55 return HttpResponseRedirect("/ places/edit/%i/" % new_place.id)73 return HttpResponseRedirect("/someurl/" % new_object.id) 56 74 else: 57 75 # No POST, so we want a brand new form without any data or errors.