AttributeError thrown by Validator

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

AttributeError thrown by Validator

Paul Childs

I am sure that I have read everything there is available in the
newsgroup and docs concerning uploading files.
If I missed something I apologize in advance.

Right now all I am trying to do is upload a file and use the
manipulator to validate that it is not missing. Everything seems to be
working except when I call the manipulator.get_validation_errors
method. It throws an exception (see traceback below).

If I don't update the new_data dictionary with request.FILES then I get
a  'This field is required.' error.

I commented out the method call and did verify that the file was
uploaded to the view.

Any help would be most appreciated.

I am using Django 0.95

-----------------------------------------
View:
-----------------------------------------
def upload_album(request):

    manipulator = AlbumUploadManipulator()

    if request.POST:
        new_data = request.POST.copy()


        # if this if statement is commented out then
        # 'error_dict': {'album_file': ['This field is required.']}
        if request.FILES:
            new_data = new_data.update(request.FILES)

        # exception gets thrown here
        errors = manipulator.get_validation_errors(new_data)


        if not errors:

            <snip>

            return HttpResponseRedirect("/albums/")

    else:
        errors = new_data = {}

    form = forms.FormWrapper(manipulator, new_data, errors)
    return render_to_response('upload_form.html', {'form': form})


-----------------------------------------
Manipulator:
-----------------------------------------
from django import forms

class AlbumUploadManipulator(forms.Manipulator):

    def __init__(self):
        self.fields = (
            forms.TextField(field_name="album_name",
                            length=30, maxlength=200,
                            is_required=True),
            forms.FileUploadField(field_name="album_file",
                                    is_required=True),
        )
------------------------------------------
Template:
------------------------------------------

<form method="post" action="." enctype="multipart/form-data">

     <p><label for="id_album_name">Name:</label>
     {{ form.album_name }}
     </p>
     <p><label for="id_album_file">File:</label>
     {{ form.album_file }}
     {{ form.album_file_file }}</p>

<p>
<input type="submit" value="upload" />
</p>

</form>

------------------------------------------
Traceback:
------------------------------------------
Traceback (most recent call last):
File
"c:\python24\lib\site-packages\django-0.95-py2.4.egg\django\core\handlers\base.py"
in get_response
  74. response = callback(request, *callback_args, **callback_kwargs)
File "C:\Documents and Settings\HIAPRC\My
Documents\Python\wilds\..\wilds\albums\views.py" in upload_album
  29. errors = manipulator.get_validation_errors(new_data)
File
"c:\python24\lib\site-packages\django-0.95-py2.4.egg\django\forms\__init__.py"
in get_validation_errors
  58. errors.update(field.get_validation_errors(new_data))
File
"c:\python24\lib\site-packages\django-0.95-py2.4.egg\django\forms\__init__.py"
in get_validation_errors
  345. if self.is_required and not new_data.get(self.field_name,
False):

  AttributeError at /albums/upload_album/
  'NoneType' object has no attribute 'get'


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: AttributeError thrown by Validator

Rajesh Dhawan


>         if request.FILES:
>             new_data = new_data.update(request.FILES)
>

Change that to:

    if request.FILES:
        new_data.update(request.FILES)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: AttributeError thrown by Validator

Paul Childs

Thanks a million Rajesh!

It is so great to have such a helpful community.

Cheers,
/Paul


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---