RE: showing user data in a view

2009-10-13 Thread Ed Kawas

Thanks,

I guess I made it out to be harder than it was.

Eddie

-Original Message-
From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
On Behalf Of Brian McKeever
Sent: October-12-09 1:20 PM
To: Django users
Subject: Re: showing user data in a view


You could write a wrapper around it if you wanted.

def x_edit(request, x_id):
x = X.objects.get(id = x_id)
if x.user != request.user:
return HttpResponseRedirect('/you cant edit that/')
return update_object(request, model = X, object_id = x_id,)


On Oct 12, 1:51 pm, "Ed Kawas"  wrote:
> Ah, so there is no way to use 'create_object' when doing this, right?
>
> Thank you,
>
> Eddie
>
> -Original Message-
> From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
>
> On Behalf Of Brian McKeever
> Sent: October-12-09 12:50 PM
> To: Django users
> Subject: Re: showing user data in a view
>
> It's the same thing.
>
> Lets say this is your view:
> def x_edit(request, x_id):
>     x = X.objects.get(id = x_id)
>     if x.user != request.user:
>         return HttpResponseRedirect('/you cant edit that/')
>     if request.method == 'POST':
>         form = XForm(request.POST)
>         if form.is_valid():
>             #whatever you need to do to save an x object here
>             return HttpResponseRedirect('/thanks/')
>     else:
>         form = XForm()
>
>     return render_to_response('x_edit.html', {
>         'form': form,
>     })
>
> You can split that into multiple views if you want, but the idea is to
> do the check before saving the object.
>
> On Oct 12, 1:25 pm, "Ed Kawas"  wrote:
> > That works for retrieving information, but how can I save information
too?
>
> > Thanks for your patience,
>
> > Eddie
>
> > -Original Message-
> > From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com]
>
> > On Behalf Of Brian McKeever
> > Sent: October-12-09 11:52 AM
> > To: Django users
> > Subject: Re: showing user data in a view
>
> > The easy way is to just check that the owner of X is the user logged
> > in.
> > I don't know that you can pass an argument to the decorator, but you
> > could certainly just use an if statement.
>
> >http://docs.djangoproject.com/en/dev/topics/auth/#limiting-access-to-...
> > in-users-that-pass-a-test
>
> > On Oct 12, 11:40 am, Ed  wrote:
> > > Hi All,
>
> > > I am completely lost. I *think* that I have read most of the doc that
> > > i can find and I must be pretty dense, because I cannot figure this
> > > one out ...
>
> > > Let me outline what i have and where i want to go!
>
> > > model:
> > > # an X
> > > class X(db.Model):
> > >    user = models.ForeignKey(User, unique=True)
> > >    name = db.StringProperty(required=True)
>
> > > Form:
> > > class XForm(forms.ModelForm):
> > >     name = models.CharField(max_length=100)
> > >     class Meta:
> > >         model = X
> > >         fields = {'name'}
>
> > > views:
> > > def add_x(request):
> > >   return create_object(request,
> > >                                     form_class=XForm,
> > >                                     post_save_redirect=reverse
> > > ('myapp.views.show_x',
> > > kwargs=dict(key='%(key)s')))
>
> > > I am trying to allow authenticated users the ability to add X. I am
> > > trying to associate a user with a specific X so that only that user
> > > can modify it. How can I do this?
> > > Thanks.


--~--~-~--~~~---~--~~
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: showing user data in a view

2009-10-12 Thread Ed Kawas

Ah, so there is no way to use 'create_object' when doing this, right?

Thank you,

Eddie

-Original Message-
From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
On Behalf Of Brian McKeever
Sent: October-12-09 12:50 PM
To: Django users
Subject: Re: showing user data in a view


It's the same thing.

Lets say this is your view:
def x_edit(request, x_id):
x = X.objects.get(id = x_id)
if x.user != request.user:
return HttpResponseRedirect('/you cant edit that/')
if request.method == 'POST':
form = XForm(request.POST)
if form.is_valid():
#whatever you need to do to save an x object here
return HttpResponseRedirect('/thanks/')
else:
form = XForm()

return render_to_response('x_edit.html', {
'form': form,
})

You can split that into multiple views if you want, but the idea is to
do the check before saving the object.

On Oct 12, 1:25 pm, "Ed Kawas"  wrote:
> That works for retrieving information, but how can I save information too?
>
> Thanks for your patience,
>
> Eddie
>
> -Original Message-
> From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
>
> On Behalf Of Brian McKeever
> Sent: October-12-09 11:52 AM
> To: Django users
> Subject: Re: showing user data in a view
>
> The easy way is to just check that the owner of X is the user logged
> in.
> I don't know that you can pass an argument to the decorator, but you
> could certainly just use an if statement.
>
> http://docs.djangoproject.com/en/dev/topics/auth/#limiting-access-to-...
> in-users-that-pass-a-test
>
> On Oct 12, 11:40 am, Ed  wrote:
> > Hi All,
>
> > I am completely lost. I *think* that I have read most of the doc that
> > i can find and I must be pretty dense, because I cannot figure this
> > one out ...
>
> > Let me outline what i have and where i want to go!
>
> > model:
> > # an X
> > class X(db.Model):
> >    user = models.ForeignKey(User, unique=True)
> >    name = db.StringProperty(required=True)
>
> > Form:
> > class XForm(forms.ModelForm):
> >     name = models.CharField(max_length=100)
> >     class Meta:
> >         model = X
> >         fields = {'name'}
>
> > views:
> > def add_x(request):
> >   return create_object(request,
> >                                     form_class=XForm,
> >                                     post_save_redirect=reverse
> > ('myapp.views.show_x',
> > kwargs=dict(key='%(key)s')))
>
> > I am trying to allow authenticated users the ability to add X. I am
> > trying to associate a user with a specific X so that only that user
> > can modify it. How can I do this?
> > Thanks.


--~--~-~--~~~---~--~~
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: showing user data in a view

2009-10-12 Thread Ed Kawas

That works for retrieving information, but how can I save information too?

Thanks for your patience,

Eddie

-Original Message-
From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
On Behalf Of Brian McKeever
Sent: October-12-09 11:52 AM
To: Django users
Subject: Re: showing user data in a view


The easy way is to just check that the owner of X is the user logged
in.
I don't know that you can pass an argument to the decorator, but you
could certainly just use an if statement.

http://docs.djangoproject.com/en/dev/topics/auth/#limiting-access-to-logged-
in-users-that-pass-a-test

On Oct 12, 11:40 am, Ed  wrote:
> Hi All,
>
> I am completely lost. I *think* that I have read most of the doc that
> i can find and I must be pretty dense, because I cannot figure this
> one out ...
>
> Let me outline what i have and where i want to go!
>
> model:
> # an X
> class X(db.Model):
>    user = models.ForeignKey(User, unique=True)
>    name = db.StringProperty(required=True)
>
> Form:
> class XForm(forms.ModelForm):
>     name = models.CharField(max_length=100)
>     class Meta:
>         model = X
>         fields = {'name'}
>
> views:
> def add_x(request):
>   return create_object(request,
>                                     form_class=XForm,
>                                     post_save_redirect=reverse
> ('myapp.views.show_x',
> kwargs=dict(key='%(key)s')))
>
> I am trying to allow authenticated users the ability to add X. I am
> trying to associate a user with a specific X so that only that user
> can modify it. How can I do this?
> Thanks.


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