This is the traceback:
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/
base.py" in get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/ast1/workspace/CMT/cmt/views.py" in home
46. userID = retrieveUserID(firstname, lastname)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/
decorators.py" in _wrapped_view
22. if test_func(request.user):
Exception Type: AttributeError at /
Exception Value: 'unicode' object has no attribute 'user'
I also found my error using your pointers. I was passing the user's
first and last name to another view that uses it in a function that
has the @login_required decorator.
That obviously doesn't work but I can remove the decorator there to
fix my issue, thanks for the help guy's.
Concerning my other question, the way I do it now is like this:
Template:
<form action="." method="post" enctype="multipart/form-data">{%
csrf_token %}
{{ form }}
<input type="submit" value="Create new CM item">
</form>
View:
class SimpleFileForm(forms.Form):
upload_file = forms.FileField(label='', widget=forms.FileInput,
required=True)
This gives me a file field, a browse button and a submit button. What
I'd like to have is a submit button only, click that opens a file
dialog.
Any ideas?
Thanks,
On 18 mei, 18:42, Oscar Carballal <[email protected]> wrote:
> 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 <[email protected]>:
>
> > On Wednesday, May 18, 2011 2:16:00 PM UTC+1,Michel30wrote:
>
> >> 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 [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.