### Install Django LazySignup using Pip Source: https://django-lazysignup.readthedocs.io/en/latest/install This snippet shows the command to install the django-lazysignup package from PyPI using pip. Ensure pip is installed and accessible in your environment. ```bash pip install django-lazysignup ``` -------------------------------- ### Build and View Django LazySignup Documentation Source: https://django-lazysignup.readthedocs.io/en/latest/contributing This snippet shows how to build the documentation for the Django LazySignup project and then open the generated HTML files in a web browser. It requires installing project dependencies, including those for documentation building, and then executing the Sphinx build command. ```shell pip install -e .[all] python setup.py build_sphinx open docs/_build/html/index.html ``` -------------------------------- ### Configure Django LazySignup Authentication Backends Source: https://django-lazysignup.readthedocs.io/en/latest/install This code snippet demonstrates how to add django-lazysignup's authentication backend to your Django project's AUTHENTICATION_BACKENDS setting. This is crucial for the lazy signup functionality to work correctly. ```python AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'lazysignup.backends.LazySignupBackend', ) ``` -------------------------------- ### Run Django LazySignup Tests with Local Databases Source: https://django-lazysignup.readthedocs.io/en/latest/contributing This snippet demonstrates how to set up and run tests for Django LazySignup using local PostgreSQL, MySQL, and SQLite databases. It includes commands for cloning the repository, installing dependencies, configuring database connections via environment variables, and executing tests with coverage reporting. ```shell git clone https://github.com/danfairs/django-lazysignup cd django-lazysignup # Install dependencies and requirements pip install -e .[all] # To test against a PostgreSQL Database locally psql -c "CREATE USER lazysignup with login createdb password 'lazysignup';" psql -c "CREATE DATABASE lazysignup with OWNER lazysignup;" export DB="local-postgres" # To test against a MySQL Database locally mysql -e "CREATE DATABASE lazysignup CHARACTER SET utf8;" mysql -e "CREATE USER 'lazysignup'@'localhost' IDENTIFIED BY 'lazysignup';" mysql -e "GRANT ALL PRIVILEGES ON lazysignup.* to 'lazysignup'@'localhost';" mysql -e "FLUSH PRIVILEGES;" export DB="local-mysql" # To test against a SQLite Database locally export DB="sqlite" # Run the tests and report coverage coverage run manage.py test coverage report --fail-under=98 coverage run manage.py test --settings=custom_user_tests.settings coverage report --fail-under=98 ``` -------------------------------- ### Example Custom User Model with UserManager Source: https://django-lazysignup.readthedocs.io/en/latest/user An example of a custom user model inheriting from Django's AbstractUser and using UserManager. This ensures compatibility with lazysignup's expectations for the default manager's create_user method. ```python from django.contrib.auth.models import AbstractUser, UserManager from django.db import models class MyCustomUser(AbstractUser): objects = UserManager() notes = models.TextField(blank=True, null=True) ``` -------------------------------- ### Release Django LazySignup to PyPI Source: https://django-lazysignup.readthedocs.io/en/latest/contributing This snippet outlines the process for releasing a new version of the Django LazySignup project to the Python Package Index (PyPI). It involves installing project dependencies and then using the setup.py script to build source and wheel distributions and upload them. ```shell pip install -e .[all] python setup.py sdist bdist_wheel upload ``` -------------------------------- ### Include Django LazySignup URLs in URLConf Source: https://django-lazysignup.readthedocs.io/en/latest/install This Python code snippet shows how to include the lazysignup URLs into your project's main URL configuration (urls.py). This makes the lazysignup features accessible via specific URL patterns. ```python from django.conf.urls import url, include urlpatterns += ( url(r'^convert/', include('lazysignup.urls')), ) ``` -------------------------------- ### Handle User Conversion with Django Signals Source: https://django-lazysignup.readthedocs.io/en/latest/usage This Python code demonstrates how to listen for the 'converted' signal from Django LazySignup. When a temporary user account is converted to a real one, this signal is sent, allowing you to perform custom actions, such as printing a message with the new user's username. ```python from lazysignup.signals import converted from django.dispatch import receiver @receiver(converted) def my_callback(sender, **kwargs): print "New user account: %s!" % kwargs['user'].username ``` -------------------------------- ### Configure Custom User Creation Form in Django Settings Source: https://django-lazysignup.readthedocs.io/en/latest/usage This snippet shows how to configure a custom user creation form for Django LazySignup by setting the LAZYSIGNUP_CUSTOM_USER_CREATION_FORM variable in your Django settings file. This allows for customized user creation logic beyond the default. ```python LAZYSIGNUP_CUSTOM_USER_CREATION_FORM = 'myproject.apps.myapp.forms.MyForm' ``` -------------------------------- ### Run Django LazySignup User Cleanup Command Source: https://django-lazysignup.readthedocs.io/en/latest/maintenance Executes the management command to remove expired and unconverted user accounts from the system. This command is crucial for maintaining performance by preventing an accumulation of old user data. It should be run regularly, ideally via cron in production environments. ```python python manage.py remove_expired_users ``` -------------------------------- ### Allow Lazy User Decorator in Django Source: https://django-lazysignup.readthedocs.io/en/latest/usage The `allow_lazy_user` decorator from `lazysignup.decorators` enables the creation of temporary user accounts for anonymous users accessing a view. It's used to mark specific views that should trigger this lazy user creation behavior. The decorated view can then access the user object, which will be a temporary user if the original request was from an anonymous user. ```python from django.http import HttpResponse from lazysignup.decorators import allow_lazy_user @allow_lazy_user def my_view(request): return HttpResponse(request.user.username) ``` -------------------------------- ### Check if User is Lazy in Python Code Source: https://django-lazysignup.readthedocs.io/en/latest/usage The `is_lazy_user` function, importable from `lazysignup.utils`, allows programmatic checking of whether a user object is a temporary (lazy) user. This is useful in view logic or tests to determine the user's status. As of version 0.6.0, this check works independently of the `LazySignupBackend`. ```python from lazysignup.utils import is_lazy_user from django.contrib.auth.models import AnonymousUser def testIsLazyUserAnonymous(self): user = AnonymousUser() self.assertEqual(False, is_lazy_user(user)) ``` -------------------------------- ### Configure LAZYSIGNUP_USER_MODEL Setting Source: https://django-lazysignup.readthedocs.io/en/latest/user This setting specifies the dotted Django path to your custom user model. If you have already set AUTH_USER_MODEL to your custom model, this setting is not strictly necessary as it defaults to AUTH_USER_MODEL. ```python LAZYSIGNUP_USER_MODEL = 'myapp.CustomUser' ``` -------------------------------- ### Check if User is Lazy with Template Filter Source: https://django-lazysignup.readthedocs.io/en/latest/usage The `is_lazy_user` template filter, loaded via `lazysignup_tags`, checks if a given user object is a temporary (lazy) user. This is useful in templates to conditionally display content or navigation links based on whether the user is a regular or temporary account. It can also be imported as a utility function for use in Python code. ```django_template {% load i18n lazysignup_tags %} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.