Re: updating a user form?

2011-06-22 Thread raj
nevermind, i figured it out. thanks anyway

On Jun 22, 5:11 pm, raj  wrote:
> I think I'm starting to get the hang of it a little. I was able to
> extract the data from the profile and set it as the initial value.
> From what I understand, you would like me to set each user field one
> at a time, but if I have 20-30 fields that need to be updated at once,
> I'm at a loss. The way that I have my files set up is that I have a
> view with the following code:
> ### views.py ###
> def profileFields(request):
>     user = request.user
>     if request.method == 'POST':
>         form = userProf(request.POST)
>         if form.is_valid():
>             user = form.save(request.POST, user)
>             return HttpResponseRedirect('/user/update/success')
>     else:
>         form = userProf(instance=user.get_profile())
>     return render_to_response("/home/oneadmin/webapps/oneadmin/
> oneadmin/templates/oneadmissions/profile.html", {'form': form},
> context_instance = RequestContext(request))
>
> now my userProf form module has the following save function:
> def save(self, new_data, user):
>         user.get_profile().colleges = new_data['colleges']
>         .dozen other new_data fields would go here...
>         user.save()
>         return user
>
> From what I understand, you want me to put the save information in the
> views.py file, but my actual form class is in a different document. So
> i decided that it would be better to put it there. Am I on the right
> track? Why isn't any information actually being updated?
>
> On Jun 22, 5:05 am, Herman Schistad  wrote:
>
>
>
>
>
>
>
> > On Wed, Jun 22, 2011 at 10:14, raj  wrote:
> > > If I didn't have the url
> > > set up in this manner, how would I manage to extract the userprofile?
>
> > If you have the "AuthenticationMiddleware" activated you would use 
> > request.user
> > This returns a User object, which you then can use to further edit things.
>
> > E.g.
> > user = request.user
> > user.username = "Somethingnew"
> > user.save()
>
> > Or, as Kevin Renskers said, you would create a seperate model for the
> > userprofile if you wanted to extend it. Here you will need to get the
> > user profile with user.get_profile() and remember to set the
> > following: AUTH_PROFILE_MODULE = "myapp.mysiteprofile"
>
> > Then you could use the above example like this:
> > user = request.user
> > user.get_profile().homepage = "http://example.org;
> > user.save()
>
> > --
> > With regards, Herman Schistad

-- 
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.



Re: updating a user form?

2011-06-22 Thread raj
I think I'm starting to get the hang of it a little. I was able to
extract the data from the profile and set it as the initial value.
>From what I understand, you would like me to set each user field one
at a time, but if I have 20-30 fields that need to be updated at once,
I'm at a loss. The way that I have my files set up is that I have a
view with the following code:
### views.py ###
def profileFields(request):
user = request.user
if request.method == 'POST':
form = userProf(request.POST)
if form.is_valid():
user = form.save(request.POST, user)
return HttpResponseRedirect('/user/update/success')
else:
form = userProf(instance=user.get_profile())
return render_to_response("/home/oneadmin/webapps/oneadmin/
oneadmin/templates/oneadmissions/profile.html", {'form': form},
context_instance = RequestContext(request))

now my userProf form module has the following save function:
def save(self, new_data, user):
user.get_profile().colleges = new_data['colleges']
.dozen other new_data fields would go here...
user.save()
return user

>From what I understand, you want me to put the save information in the
views.py file, but my actual form class is in a different document. So
i decided that it would be better to put it there. Am I on the right
track? Why isn't any information actually being updated?


On Jun 22, 5:05 am, Herman Schistad  wrote:
> On Wed, Jun 22, 2011 at 10:14, raj  wrote:
> > If I didn't have the url
> > set up in this manner, how would I manage to extract the userprofile?
>
> If you have the "AuthenticationMiddleware" activated you would use 
> request.user
> This returns a User object, which you then can use to further edit things.
>
> E.g.
> user = request.user
> user.username = "Somethingnew"
> user.save()
>
> Or, as Kevin Renskers said, you would create a seperate model for the
> userprofile if you wanted to extend it. Here you will need to get the
> user profile with user.get_profile() and remember to set the
> following: AUTH_PROFILE_MODULE = "myapp.mysiteprofile"
>
> Then you could use the above example like this:
> user = request.user
> user.get_profile().homepage = "http://example.org;
> user.save()
>
> --
> With regards, Herman Schistad

-- 
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.



Re: updating a user form?

2011-06-22 Thread Herman Schistad
On Wed, Jun 22, 2011 at 10:14, raj  wrote:
> If I didn't have the url
> set up in this manner, how would I manage to extract the userprofile?

If you have the "AuthenticationMiddleware" activated you would use request.user
This returns a User object, which you then can use to further edit things.

E.g.
user = request.user
user.username = "Somethingnew"
user.save()

Or, as Kevin Renskers said, you would create a seperate model for the
userprofile if you wanted to extend it. Here you will need to get the
user profile with user.get_profile() and remember to set the
following: AUTH_PROFILE_MODULE = "myapp.mysiteprofile"

Then you could use the above example like this:
user = request.user
user.get_profile().homepage = "http://example.org;
user.save()

-- 
With regards, Herman Schistad

-- 
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.



Re: updating a user form?

2011-06-22 Thread raj
This is an interesting way of doing it. I don't have it set up so that
every user has their own url that contains their db id. Django checks
to see if the user is authenticated or not. If I didn't have the url
set up in this manner, how would I manage to extract the userprofile?
I was seeing something called request.user, but I couldn't get this to
work.
I googled some more and I got a post talking about the ModelForm. This
allowed me to restrict the form fields for the user profile. The issue
is that each form field didn't have the default values set to those in
the database. (The form "value" parameter). I looked through the
ModelForm section of the djangobook, as well as the forms section, and
I couldn't come up with anything.

On Jun 22, 2:37 am, Herman Schistad  wrote:
> On Wed, Jun 22, 2011 at 08:28, raj  wrote:
> > I'm trying to create an update_profile form. This form will be able to
> > update extended user information that is not in the original form.
>
> > So, I have a form that allows you to create an account. There a lot of
> > other fields that aren't listed in this form. The rest of these fields
> > will be found when the user actually logs in. What I can't figure out
> > is how to make the class that allows them to update this information.
> > Like in the extended user class that I made, I have a save function
> > that creates a user and saves it. But I don't want to create another
> > user with this form. I simply want to update the current authenticated
> > user. I thought there would be an update_user type function in the
> > UserManager(), but there isn't. I tried googling and didn't come up
> > with much. Help Please?
>
> I don't quite understand what you mean...
>
> When you say load the url: /userprofile/1234/ at got your urls.py to
> get  from the URL.
> Then you could load that userprofile from the db with e.g.
>
> def a_nice_view(request, id):
> from django.auth.models import User
> userprofile = User.objects.get(pk=id)
> ## Then do updating on that profile here ##
> userprofile.username = "Somethingnew"
>
> It's the same way with a form/request, and you can get the userprofile
> with: request.user
>
> All this is pretty basic stuff, and as I've seen you ask a lot of
> these questions on django-users I would really advise you to read a
> introductory book or do some more tutorials before trying to make
> something advanced yourselves.
>
> --
> With regards, Herman Schistad

-- 
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.



Re: updating a user form?

2011-06-22 Thread Kevin Renskers
I'd advise you to 
read 
https://docs.djangoproject.com/en/1.3/topics/auth/#storing-additional-information-about-users.
 
So, create a separate model for the profile, which can be edited by the user 
once he is logged in.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/VWn5hNS6tXkJ.
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.



Re: updating a user form?

2011-06-22 Thread Herman Schistad
On Wed, Jun 22, 2011 at 08:28, raj  wrote:
> I'm trying to create an update_profile form. This form will be able to
> update extended user information that is not in the original form.
>
> So, I have a form that allows you to create an account. There a lot of
> other fields that aren't listed in this form. The rest of these fields
> will be found when the user actually logs in. What I can't figure out
> is how to make the class that allows them to update this information.
> Like in the extended user class that I made, I have a save function
> that creates a user and saves it. But I don't want to create another
> user with this form. I simply want to update the current authenticated
> user. I thought there would be an update_user type function in the
> UserManager(), but there isn't. I tried googling and didn't come up
> with much. Help Please?

I don't quite understand what you mean...

When you say load the url: /userprofile/1234/ at got your urls.py to
get  from the URL.
Then you could load that userprofile from the db with e.g.

def a_nice_view(request, id):
from django.auth.models import User
userprofile = User.objects.get(pk=id)
## Then do updating on that profile here ##
userprofile.username = "Somethingnew"

It's the same way with a form/request, and you can get the userprofile
with: request.user

All this is pretty basic stuff, and as I've seen you ask a lot of
these questions on django-users I would really advise you to read a
introductory book or do some more tutorials before trying to make
something advanced yourselves.

-- 
With regards, Herman Schistad

-- 
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.



updating a user form?

2011-06-22 Thread raj
I'm trying to create an update_profile form. This form will be able to
update extended user information that is not in the original form.

So, I have a form that allows you to create an account. There a lot of
other fields that aren't listed in this form. The rest of these fields
will be found when the user actually logs in. What I can't figure out
is how to make the class that allows them to update this information.
Like in the extended user class that I made, I have a save function
that creates a user and saves it. But I don't want to create another
user with this form. I simply want to update the current authenticated
user. I thought there would be an update_user type function in the
UserManager(), but there isn't. I tried googling and didn't come up
with much. Help Please?

-- 
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.