0

I need help implementing this package into this django project:

When viewing the page source, I see the app's HTML loaded from the render tags. But on the actual page, I am not seeing any of the outputted HTML from those render tags.

Can someone please summarize a step by step set of instructions to get this package to work? The instructions provided can be confusing sometimes.

I did not do the following and am not sure how to do these parts:

1) install the add-on on divio.com or via pypi (would rather not install this since it seems to costs money - unless there is a way to use it for free)

2) update your templates/django_privacy_mgmt to reflect your frontend toolchain situation (not sure where in my project to put these files.

3) Then check what kind of tracking items your website is using (either in the templates or via Google Tag Manager or in any imaginable other way) and add them in the "Django Privacy Mgmt" section of the Django Admin interface to the list of 'Tracking Items'. This is necessary so that we can show a list of tracking items to the user in the 'privacy settings' modal.

4) Then implement conditional logic that enables or disables the tracking items that you identified in the previous step (see next chapter).

Here are the steps I followed:

pip3 install django-privacy-mgmt
pip3 install django-parler
pip3 install django-sekizai
python3 manage.py migrate

​TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,"templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
        'sekizai.context_processors.sekizai',
            ],
        },
    },
]
​
SITE_ID = 1
INSTALLED_APPS = [
    'django.contrib.sites',
    'sekizai',
    'django_privacy_mgmt',
    'parler',
]

{% load privacy %}
<!DOCTYPE html>
<html lang="en">
<head>
{% load static %}
{% render_privacy_api %}
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>

<body>

{% render_privacy_banner %}
{% render_privacy_settings_modal %}
{% render_privacy_settings_modal_link %}

</body>
gerkojafyu
  • 21
  • 2

1 Answers1

0

I just started using django two weeks ago and stumbled over the django-privacy-mgmt package. I wanted to use it in my project as well and had some trouble in the beginning. That's why I think I might be able to help you out here. I had a look at your project, checked it out and integrated the package successfully.

I did the following steps:

  1. Installed the package with pip pip install django-privacy-mgmt
  2. Add the installed apps as you did
INSTALLED_APPS = [
...
    'django.contrib.sites',
    'sekizai',
    'django_privacy_mgmt',
    'parler',
...
]
  1. And the django.contrib.messages.context_processors.messages to the context-processors

  2. Added the privacy definitions to your base.html in ./courses/templates

{% load privacy %}
{% load sekizai_tags %}
<!DOCTYPE html>
<html>
<head>
    <title>Django Video Membership</title>
    {% render_privacy_api %}
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" ...
    {% render_block 'css' %}
</head>
<body>

    {% include 'courses/messages.html' %}

    <div class="container">
        <ol class='breadcrumb'>
            <li><a href="{% url 'memberships:profile' %}">Profile</a></li>

            {% block post_detail_link %}
            {% endblock %}

            {% if not request.user.is_authenticated %}
            <li class='pull-right'><a href='/register'>Register</a></li>
            <li class='pull-right'><a href='/login'>Login</a></li>
            {% else %}
            <li class='pull-right'><a href='/memberships'>Memberships</a></li>
            {% endif %}
            {% render_privacy_settings_modal_link %}
        </ol>
    </div>

    {% block content %}
    {% endblock content %}

    <script
    src="https://code.jquery.com/jquery-3.3.1.js" ...
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ...
    {% render_privacy_banner %}
    {% render_privacy_settings_modal %}
    {% render_block "js" %}
</body>
</html>
  1. python manage.py migration

  2. python manage.py runserver and login with any user will show the link in the navigation, if you click on it the popup appears

Explanations:

In the first step, we install the package. You don't need to install the django-parler and django-sekizai, they are dependencies of the django-privacy-mgmt and will be automatically installed by pip After the package is successfully installed, we can use the tags in your base.html file, which is situated in ./courses/templates/courses/base.html. First, we include the load privacy in order to be able to use the tags from the django-privacy-mgmt package. Afterward, we load sekizai_tags. This is not described in the documentation, but it is necessary to add the render_block tags for 'js' and 'css', which are used by the package to add javascript and css to your base.html. The creator of the package plans to remove it in the future, please have a look here. You need to put the render_privacy_settings_modal_link where you want to show the link for the user, probably the footer is the best place. I put it in your navigation. I added the render_privacy_api, render_privacy_banner and render_privacy_settings_modal according to the documentation into your base.html. Please note that the banner is optional. In step number 5, I migrate the SQL scripts, which will create the tables necessary to create the TrackingItem's. After you started your local server and you logged in with any user, you should be able to see the 'privacy-setting'-link in the navigation.

1) install the add-on on divio.com or via pypi

I didn't use it. As described here installing with pip works

2) update your templates/django_privacy_mgmt to reflect

What the creator of the package means by that is that you can override his templates. He has for templates, these are the render-tags you are including in you application. I needed to do this in my project, because I use Django 3 and staticfiles are not supported anymore. You don't need to worry about that, everything works fine in your project, but if you want to change the layout of the banner, or the link or the popup, than you have to override the template. you can do this by creating a folder called django_privacy_mgmt in your ./courses/templates and create HTML-files with the names as you find here. Copy the content from the repository and adjust it to your needs.

3) + 4) Then check what kind of tracking items your website is using

If you log into the admin-area by using localhost:8000/admin you should see the model TrackingItem, where you can create items for the django-privacy-mgmt. In order to exclude scripts depending on the privacy-setting of a user, you have to follow the explanation here. As you can see in the example, it does not load the googletagamanager if the user denied the statistics in the cookie-settings.

Hope this helps!

Enrico
  • 11
  • 2