Changes between Version 1 and Version 2 of StreamingUpload


Ignore:
Timestamp:
12/20/06 11:57:05 (8 years ago)
Author:
Øyvind Saltvik <oyvind.saltvik@…>
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • StreamingUpload

    v1 v2  
    1717from models import SomeFile
    1818from django import forms
     19from django.conf import settings
    1920
    2021class AddFileManipulator(forms.Manipulator):
     22
    2123    def __init__(self):
    2224        self.fields = (           
    2325            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)
    2527        )
     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()
    2643
    2744}}}
     
    4057        # If data was POSTed, we're trying to create a new Place.
    4158        new_data = request.POST.copy()
     59        new_data.update(request.FILES)
    4260
    4361        # Check for errors.
     
    4765            # No errors. This means we can save the data!
    4866            manipulator.do_html2python(new_data)
    49             new_place = manipulator.save(new_data)
     67            new_object = manipulator.save(new_data)
    5068
    5169            # Redirect to the object's "edit" page. Always use a redirect
     
    5371            # duplicate entires, and so users don't see the confusing
    5472            # "Repost POST data?" alert box in their browsers.
    55             return HttpResponseRedirect("/places/edit/%i/" % new_place.id)
     73            return HttpResponseRedirect("/someurl/" % new_object.id)
    5674    else:
    5775        # No POST, so we want a brand new form without any data or errors.
Back to Top