As Daniel said, I dont' think also that the entire view is that, but if it helps, I'll let you a piece of my code for a form (gpl, no problem if you copy it).
@permission_required('spaces.add_space') def create_space(request): """ Create new spaces. In this view the author field is automatically filled so we can't use a generic view. """ space = Space() form = SpaceForm(request.POST or None, request.FILES or None, instance=space) if request.POST: form_uncommited = form.save(commit=False) form_uncommited.author = request.user if form.is_valid(): form_uncommited.save() # We add the created spaces to the user allowed spaces space = get_object_or_404(Space, name=form_uncommited.name) request.user.profile.spaces.add(space) return redirect('/spaces/' + space.url) return render_to_response('spaces/space_add.html', {'form': form}, context_instance=RequestContext(request)) 2011/5/18 Daniel Roseman <dan...@roseman.org.uk>: > On Wednesday, May 18, 2011 2:16:00 PM UTC+1, Michel30 wrote: >> >> Hey all, >> >> I have a Django 1.3 app that retrieves user credentials from LDAP. >> Most views require the user to be authenticated so I use the >> @login_required decorator. >> >> Now, in a form a user can upload a document using a form: >> >> <form action="." method="post" enctype="multipart/form-data">{% >> csrf_token %} >> {{ form }} >> <input type="submit" value="Create new CM item"> >> </form> >> >> I want to log the user's first and lastname who submitted the file in >> a model. So, in my view I've tried a number of solutions but all came >> up with various errors either related to the @login_required decorator >> or complaining that no user exists in the POST object. >> >> This is the latest attempt I have in my view: >> >> def home(request): >> form = SimpleFileForm() >> if request.method == 'POST': >> if 'upload_file' in request.FILES: >> upload_file = request.FILES['upload_file'] >> filename = request.FILES['upload_file'].name >> user = request.user >> firstname = user.first_name >> lastname = user.last_name >> etc... >> >> It throws this error: 'unicode' object has no attribute 'user' >> >> Does someone know a good way how to do this? (Any suggestions on how >> to get rid of the file textfield / browse button and only leave a >> submit button to open a select dialog are also very much appreciated) >> >> Thanks, >> Michel > > That is the correct way to do it. I don't think that is the real code you're > running, because `request` is clearly not a unicode object in the line > beginning with `filename`, and yet it is one line later. > The full traceback would help, as would the actual code. > I don't know what you mean by "a submit button to open a select dialog". > -- > DR. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.