django-lazysignup
django-lazysignup copied to clipboard
Django 3.0.5 compatibility problem
Hello I'm using Django 3.0.5 and django.utils.decorators.available_attrs
is not supported anymore but it is used in lazysignup/decorators.py
. I have substituted it with WRAPPER_ASSIGNMENTS
as suggested in the docs and this it works fine:
from functools import wraps
from django.conf import settings
from django.contrib.auth import SESSION_KEY
from django.contrib.auth import authenticate
from django.contrib.auth import get_user
from django.contrib.auth import login
from django.shortcuts import redirect
from functools import WRAPPER_ASSIGNMENTS
from lazysignup.constants import USER_AGENT_BLACKLIST
from lazysignup.utils import is_lazy_user
ALLOW_LAZY_REGISTRY = {}
def allow_lazy_user(func):
def wrapped(request, *args, **kwargs):
assert hasattr(request, 'session'), ("You need to have the session "
"app installed")
if getattr(settings, 'LAZYSIGNUP_ENABLE', True):
# If the user agent is one we ignore, bail early
ignore = False
request_user_agent = request.META.get('HTTP_USER_AGENT', '')
for user_agent in USER_AGENT_BLACKLIST:
if user_agent.search(request_user_agent):
ignore = True
break
# If there's already a key in the session for a valid user, then
# we don't need to do anything. If the user isn't valid, then
# get_user will return an anonymous user
if get_user(request).is_anonymous and not ignore:
# If not, then we have to create a user, and log them in.
from lazysignup.models import LazyUser
user, username = LazyUser.objects.create_lazy_user()
request.user = None
user = authenticate(username=username)
assert user, ("Lazy user creation and authentication "
"failed. Have you got "
"lazysignup.backends.LazySignupBackend in "
"AUTHENTICATION_BACKENDS?")
# Set the user id in the session here to prevent the login
# call cycling the session key.
request.session[SESSION_KEY] = user.id
login(request, user)
return func(request, *args, **kwargs)
return wraps(func)(wrapped)
def require_lazy_user(*redirect_args, **redirect_kwargs):
def decorator(func):
@wraps(func, assigned=WRAPPER_ASSIGNMENTS)
def inner(request, *args, **kwargs):
if is_lazy_user(request.user):
return func(request, *args, **kwargs)
else:
return redirect(*redirect_args, **redirect_kwargs)
return inner
return decorator
def require_nonlazy_user(*redirect_args, **redirect_kwargs):
def decorator(func):
@wraps(func, assigned=WRAPPER_ASSIGNMENTS)
def inner(request, *args, **kwargs):
if not is_lazy_user(request.user):
return func(request, *args, **kwargs)
else:
return redirect(*redirect_args, **redirect_kwargs)
return inner
return decorator
Sorry if I might have missed something or not used the right format but be patient this is the first issue that I open. Hope it helped :)
Sorry for not responding sooner, github mails go into a bit of a black hole for me :(
I've reproduced this locally and will push a fix over the next day or two. Thanks!
No problema, glad it helped :)
Reopening because I haven’t fixed it yet :)
This issue still haven't been fixed
Any progress on this? There are some forks that claim to work with Django 3.x, but I would rather use upstream
Would be nice if you can merge the related PR https://github.com/danfairs/django-lazysignup/pull/67
Django 2.2 LTS support will end soon
I hope this one will be fixed. BTW Thank You :)
It's merged but the in Pypi is not update, unfortunately, the PR was missing the version bump. In any case you can also install it like this as a temporary workaround
django-lazysignup = {git = "https://github.com/danfairs/django-lazysignup", rev = "42470be"}
@MattFanto I tried to install it based on your command and it was a no go. Is that command able to be used in requirements.txt? For example if this fixes the issue, would i have to manually change again lets say in 'heruko'? Thanks again.
@Jazzthedog depends on what you are using (poetry pipenv, ...) the pip command should be something like
pip install git+https://github.com/danfairs/django-lazysignup@42470be
Thanks Matt, I fixed the problem manually before you replied.. :)
The fact that i fixed it manually, when i update my requirements.txt, it will still be wrong? And, I can assume later when i publish this project to Heroku for example, i will have to go back manually correct it again :(
How do you 'pin' to a particular package commit# in requirements.txt?
Hi everyone! Unfortunately I haven't been able to reach Dan about this but a couple weeks ago I decided to create a spin-off package built from the ground up with modern Django and Python versions in mind.
If you're still waiting for Django 3.0+ support, I invite you to check out django-guest-user
I also added CBV mixins and an Allauth integration, among other things.
Awesome, thanks @julianwachholz, I'll switch to that.
I reached out to Dan on twitter, his company's twitter, and his linkedin. Hopefully something happens =)