I'm guessing you have something like this. However, kay's
login_required should adapt to methods
on classes as well so the following should work.
class MyHandler(RequestHandler):
@login_required
def get(self, request, ...):
...
Can you provide a traceback of the error that occurred?
Ian
> --
> You received this message because you are subscribed to the Google Groups "kay-users" group.
> To post to this group, send email to kay-...@googlegroups.com.
> To unsubscribe from this group, send email to kay-users+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/kay-users?hl=en.
>
>
--
Ian
On Fri, Aug 26, 2011 at 10:33 AM, someone1 <some...@gmail.com> wrote:
> I don't need to pass in the request parameter since the BaseHandler
> class handles this (sets a class attribute).
Well then, that's your reason right there. login_required expects that
a request is being
passed to your view. You'll either need to pass the request to the get() post()
views, or wrap the handler itself.
handler = login_required(MyHandler())
--
Ian
On 2011/08/27, at 1:39, someone1 <some...@gmail.com> wrote:
> Thanks for the reply, however, your suggestion did not work.
Yes I didn't test my code but it should have worked if the class is being called the normal way using the __call__() method. I was assuming you had made your own handler class and was calling it in the normal way with a request argument. i.e. The way kay's generic CRUD class based views work.
> I got it to work by adding a second decorator:
>
> def login_required2(func):
> def inner(self, *args, **kwargs):
> if self.request.user.is_anonymous():
> if self.request.is_xhr:
> raise Forbidden
> else:
> return redirect(create_login_url(self.request.url))
> return func(self, *args, **kwargs)
> update_wrapper(inner, func)
> return inner
>
> This seems to have done the trick, though since I'm not very familiar
> with decorators or the framework, I'm not sure if this is "best
> practice" or will break anything. Could anybody please confirm that
> this method will work correctly?
This looks like it will work correctly by placing it on the methods in your class.
> I also did not need to use the "adapt_to_methods" function on this
> since its meant for methods. Not sure if there's a way to update the
> login_required to detect a method call versus a function call and use
> the appropriate request variable.
The way you are calling holding the request object on the class is more like how webapp does things rather than how Kay does it. That's the reason why login required isn't working. I can't provide working code unless I know how your handler works.