Ticket #2360: create_update.diff

File create_update.diff, 2.2 KB (added by nicolaslara@…, 18 years ago)

Ok, here's the patch i promised. it only adds suport for the create view. I was going to do/post the rest but seeing this "manipulator to crud views" issue hasn't been welcomed by the developers i'll wait for feed back

  • django/views/generic/create_update.py

     
    1010
    1111def create_object(request, model, template_name=None,
    1212        template_loader=loader, extra_context=None, post_save_redirect=None,
    13         login_required=False, follow=None, context_processors=None):
     13        login_required=False, follow=None, context_processors=None,
     14        extra_content={}, new_manipulator=None, pre_populate=False):
    1415    """
    1516    Generic object-creation function.
    1617
     
    2324    if login_required and not request.user.is_authenticated():
    2425        return redirect_to_login(request.path)
    2526
    26     manipulator = model.AddManipulator(follow=follow)
     27    if new_manipulator:
     28        manipulator = new_manipulator()
     29    else:
     30        manipulator = model.AddManipulator(follow=follow)
     31
    2732    if request.POST:
    2833        # If data was POSTed, we're trying to create a new object
    2934        new_data = request.POST.copy()
     
    3338
    3439        # Check for errors
    3540        errors = manipulator.get_validation_errors(new_data)
     41        new_data.update(extra_content)
    3642        manipulator.do_html2python(new_data)
    3743
    3844        if not errors:
     
    5359    else:
    5460        # No POST, so we want a brand new form without any data or errors
    5561        errors = {}
    56         new_data = manipulator.flatten_data()
     62        if new_manipulator():
     63            new_data = {}
     64#           for field in manipulator.fields:
     65#               new_data[field] = ''
     66        else:
     67            new_data = manipulator.flatten_data()
    5768
     69        if pre_populate:
     70            new_data.update(extra_content)
     71
    5872    # Create the FormWrapper, template, context, response
    5973    form = forms.FormWrapper(manipulator, new_data, errors)
    6074    if not template_name:
     
    7488        slug_field=None, template_name=None, template_loader=loader,
    7589        extra_context=None, post_save_redirect=None,
    7690        login_required=False, follow=None, context_processors=None,
    77         template_object_name='object'):
     91        template_object_name='object', explicit_manipulator=None):
    7892    """
    7993    Generic object-update function.
    8094
Back to Top