Skip to content

Plugin for django-cookie-consent app that saves cookie preferences for authenticated users.

License

Notifications You must be signed in to change notification settings

briefmnews/django-cookie-consent-authenticateduser

Repository files navigation

django-cookie-consent-authenticateduser

Python 3 Django 3 Python CI codecov Code style: black

Plugin for django-cookie-consent app that saves user's cookie preferences in the database.

Installation

You need to install django-cookie-consent first:

pip install -e git://github.com/briefmnews/django-cookie-consent@plugin#egg=django-cookie-consent

Then, install the django-cookie-consent-authenticateduser plugin:

pip install -e git://github.com/briefmnews/django-cookie-consent-authenticateduser@main#egg=django-cookie-consent-authenticateduser

Setup

In order to make django-cookie-consent-authenticateduser works, you'll need to follow the steps below:

Settings

First, you need to add the app, the middleware and the context processor to your settings:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',

    'cookie_consent',
    'cookie_consent_authenticateduser',
    ...
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    
    'cookie_consent_authenticateduser.middleware.CheckAuthenticatedUserCookieContentMiddleware',
    ...
)

TEMPLATES = [
    {
        ...,
        "OPTIONS": {
            "context_processors": [
                ...,
                "cookie_consent_authenticateduser.context_processors.display_cookie_consent",
                ...,
            ],
        },
    }
]

Tests

Testing is managed by pytest. Required package for testing can be installed with:

pip install -r requirements.txt

To run testing locally:

pytest