danfairs / django-lazysignup

django-lazysignup is a package designed to allow users to interact with a site as if they were authenticated users, but without signing up. At any time, they can convert their temporary user account to a real user account.
BSD 3-Clause "New" or "Revised" License
410 stars 89 forks source link

"AssertionError: You need to have the session app intsalled" #39

Closed aschriner closed 10 years ago

aschriner commented 10 years ago

I am trying to use the allow_lazy_user decorator on the dispatch method of a class- based view.

class SomeView(CreateView):
    @allow_lazy_user
    def dispatch(self, request, *args, **kwargs):
        ...stuff...

but I am getting AssertionError: You need to have the session app intsalled. I do have the session app installed, and I do have it in the MIDDLEWARE_CLASSES setting. If I put import pdb;pdb.set_trace() inside the dispatch method I can verify that hasattr(request, "session") is True.

aschriner commented 10 years ago

Totally my mistake: decorator should look like @method_decorator(allow_lazy_user) instead.

StErMi commented 10 years ago

aschriner I got the same problem. Can you please explain your solution?

I was watching https://github.com/danfairs/django-lazysignup/blob/master/lazysignup/tests.py#L66

and as far as I can see (also on the documentation) I should use the decorator as

@allow_lazy_user
def lazy_view(request):
    r = HttpResponse()
    if request.user.is_anonymous() or request.user.has_usable_password():
        r.status_code = 500
    return r

Cheers, Ema.

aschriner commented 10 years ago

Ema,

The difference is whether your view is a function based view or class based view. If it's a class based view, you need to use the method_decorator decorator on the dispatch method. If it's a function based view, then I don't know what the issue is.