├── .github └── workflows │ ├── pypi_upload.yaml │ └── tests.yaml ├── .gitignore ├── CHANGES.rst ├── LICENSE.rst ├── MANIFEST.in ├── Makefile ├── README.rst ├── cookielaw ├── __init__.py ├── context_processors.py ├── locale │ ├── ca │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── de │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── en │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── es │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── fi │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── fr │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── it │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── nl │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── pl │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ └── ru │ │ └── LC_MESSAGES │ │ ├── django.mo │ │ └── django.po ├── models.py ├── static │ └── cookielaw │ │ ├── css │ │ └── cookielaw.css │ │ ├── img │ │ └── close.png │ │ └── js │ │ └── cookielaw.js ├── templates │ └── cookielaw │ │ ├── banner.html │ │ └── rejectable.html ├── templatetags │ ├── __init__.py │ └── cookielaw_tags.py ├── test_project │ ├── __init__.py │ ├── test_app │ │ ├── __init__.py │ │ ├── models.py │ │ ├── templates │ │ │ ├── 500.html │ │ │ ├── accepted.html │ │ │ ├── base.html │ │ │ ├── home.html │ │ │ ├── rejectable.html │ │ │ └── rejected.html │ │ └── views.py │ ├── urls.py │ └── wsgi.py └── views.py ├── settings.py ├── setup.cfg ├── setup.py └── tests ├── __init__.py ├── test_base.py └── test_functional.py /.github/workflows/pypi_upload.yaml: -------------------------------------------------------------------------------- 1 | name: PYPI Upload 2 | 3 | on: 4 | - workflow_dispatch 5 | 6 | jobs: 7 | pypi_upload: 8 | name: pypi-upload 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v2 13 | - name: Setup Python 14 | uses: actions/setup-python@v1 15 | with: 16 | python-version: 3.9 17 | - name: Build Package 18 | run: | 19 | pip install wheel 20 | python setup.py sdist bdist_wheel 21 | - name: Publish to PyPI 22 | uses: pypa/gh-action-pypi-publish@master 23 | with: 24 | user: __token__ 25 | password: ${{ secrets.PYPI_API_TOKEN }} 26 | skip_existing: true 27 | verbose: true 28 | -------------------------------------------------------------------------------- /.github/workflows/tests.yaml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: 4 | - push 5 | - pull_request 6 | 7 | jobs: 8 | test: 9 | name: tests 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | python: [3.6, 3.7, 3.8, 3.9] 14 | django: [<2.3, <3.1, <3.2] 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v2 18 | - name: Setup Python 19 | uses: actions/setup-python@v1 20 | with: 21 | python-version: ${{ matrix.python }} 22 | - name: Setup Pip Cache 23 | uses: actions/cache@v2 24 | with: 25 | path: ${{ env.pythonLocation }} 26 | key: pip-${{ runner.os }}-${{ matrix.python }}-${{ matrix.django }}-${{ hashFiles('.github/**/*.yaml') }}-${{ hashFiles('setup.py') }} 27 | - name: Setup Virtualenv Cache 28 | id: cache-virtualenv 29 | uses: actions/cache@v2 30 | with: 31 | path: /home/runner/.local/share/virtualenvs 32 | key: virtualenv-${{ runner.os }}-${{ matrix.python }}-${{ matrix.django }}-${{ hashFiles('.github/**/*.yaml') }}-${{ hashFiles('setup.py') }} 33 | - name: Install Python dependencies 34 | if: steps.cache-virtualenv.outputs.cache-hit != 'true' 35 | run: | 36 | pip install --upgrade pip 37 | pip install --upgrade pipenv 38 | pipenv install $DJANGO 39 | pipenv install . 40 | pipenv install --dev six pytest pytest-django pytest-selenium selenium 41 | - name: Test 42 | run: | 43 | PYTHONPATH=`pwd` xvfb-run pipenv run pytest 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.egg 3 | 4 | build/ 5 | dist/ 6 | django_cookie_law.egg-info/ 7 | 8 | .idea/ 9 | 10 | /.Python 11 | /bin 12 | /include 13 | /lib 14 | /pip-selfcheck.json 15 | /Pipfile 16 | /Pipfile.lock 17 | /.cache 18 | /.eggs 19 | /.env 20 | /selenium 21 | /geckodriver.log 22 | /ghostdriver.log 23 | -------------------------------------------------------------------------------- /CHANGES.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | 2.2.0 5 | ----- 6 | 7 | * Removes any jQuery code from this project's JavaScript 8 | 9 | 10 | 2.0.0 11 | ----- 12 | 13 | * Add support for Django 1.11 14 | * Add support for Django 1.10 15 | * Drop support for Django < 1.8 as it is no `longer officially supported `__. 16 | * Switch to pytest 17 | 18 | 19 | Prior 1.1 20 | --------- 21 | 22 | * **1.0.12** added German translation thanks to dated_ 23 | * **1.0.11** added Catalan translation thanks to joansv_ 24 | * **1.0.9** added unofficial support for Django 1.10 thanks to farin_ 25 | * **1.0.8** added Spanish translation thanks to jonashagstedt_ 26 | * **1.0.7** added Russian translation thanks to paschembri_ 27 | * **1.0.6** ``django.core.context_processors.request`` is still required but if not available in template context a 28 | warning will be raise instead of a ``KeyError`` 29 | * **1.0.5** added Dutch translation thanks to douwevandermeij_ 30 | * **1.0.4** context_instance is now passed to the banner template 31 | * **1.0.3** added Italian translation thanks to Jiloc_ 32 | 33 | Some very minor changes have not been listed. 34 | 35 | 36 | .. _dated: https://github.com/dated 37 | .. _douwevandermeij: https://github.com/douwevandermeij 38 | .. _farin: https://github.com/farin 39 | .. _Jiloc: https://github.com/Jiloc 40 | .. _joansv: https://github.com/joansv 41 | .. _jonashagstedt: https://github.com/jonashagstedt 42 | .. _paschembri: https://github.com/paschembri 43 | -------------------------------------------------------------------------------- /LICENSE.rst: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Piotr Kilczuk 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE.rst 2 | include README.rst 3 | 4 | recursive-include cookielaw/locale * 5 | recursive-include cookielaw/static * 6 | recursive-include cookielaw/templates * 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean dist upload release 2 | 3 | TWINE_SIGN_WITH ?= gpg 4 | 5 | default: 6 | echo 'Please choose the Makefile target' 7 | 8 | clean: 9 | rm -rf build dist 10 | 11 | dist: 12 | python setup.py sdist bdist_wheel 13 | 14 | upload: 15 | twine check dist/* 16 | twine upload --sign --sign-with=$(TWINE_SIGN_WITH) --skip-existing dist/* 17 | 18 | release: clean dist upload 19 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ================== 2 | django-cookie-law 3 | ================== 4 | 5 | .. image:: https://github.com/TyMaszWeb/django-cookie-law/workflows/build/badge.svg 6 | :target: https://github.com/TyMaszWeb/django-cookie-law/actions 7 | 8 | `django-cookie-law` will display a dismissable banner, making your users aware of cookies being used. 9 | 10 | .. warning:: This app is known to be **not** complaint with the United Kingdom PECR/GDPR. 11 | It is your responsibility to find out whether `django-cookie-law` meets the specific local legal requirements. 12 | 13 | Contributions and comments are welcome using Github at: 14 | http://github.com/TyMaszWeb/django-cookie-law 15 | 16 | Please note that django-cookie-law requires: 17 | 18 | - Django >= 1.8 19 | - django-classy-tags >= 0.3.0 20 | 21 | Installation 22 | ============ 23 | 24 | #. ``pip install django-cookie-law`` 25 | #. Add ``'cookielaw'`` to ``INSTALLED_APPS`` 26 | #. Run ``collectstatic`` (Django 1.3+) or copy the statics to your media directory 27 | #. Add ``cookielaw/js/cookielaw.js`` to the markup directly or via your asset 28 | manager such as ``django-pipeline`` or ``django-compressor`` 29 | #. If you're using Django > 1.8, enable ``'django.core.context_processors.request'`` in your ``TEMPLATES['OPTIONS']`` setting, eg.: 30 | 31 | :: 32 | 33 | TEMPLATES = [ 34 | { 35 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 36 | 'DIRS': [], 37 | 'APP_DIRS': True, 38 | 'OPTIONS': { 39 | 'context_processors': [ 40 | 'django.template.context_processors.debug', 41 | 'django.core.context_processors.i18n', 42 | 'django.core.context_processors.media', 43 | 'django.template.context_processors.request', 44 | 'django.contrib.auth.context_processors.auth', 45 | 'django.core.context_processors.static', 46 | 'django.core.context_processors.tz', 47 | 'django.contrib.messages.context_processors.messages', 48 | ], 49 | }, 50 | }, 51 | ] 52 | 53 | If you're using an older version of Django (< 1.8) then you'll want to change the 54 | ``TEMPLATE_CONTEXT_PROCESSORS`` setting, eg.: 55 | 56 | :: 57 | 58 | TEMPLATE_CONTEXT_PROCESSORS = ( 59 | 'django.contrib.auth.context_processors.auth', 60 | 'django.core.context_processors.debug', 61 | 'django.core.context_processors.i18n', 62 | 'django.core.context_processors.media', 63 | 'django.core.context_processors.request', 64 | 'django.core.context_processors.static', 65 | 'django.core.context_processors.tz', 66 | 'django.contrib.messages.context_processors.messages' 67 | ) 68 | 69 | 70 | 71 | .. note:: N.b. versions below 1.8 are not officially supported. 72 | 73 | .. note:: If you don't have this setting defined, just add it to your settings module. 74 | 75 | #. ``{% load cookielaw_tags %}`` and add ``{% cookielaw_banner %}`` template 76 | tag where you want to display the cookielaw banner. Best place for this is 77 | your 'base' template, so you will have the cookie banner on every page of 78 | your website. 79 | 80 | Configuration 81 | ============= 82 | 83 | If you want to use our default template, add ``cookielaw/css/cookielaw.css`` to 84 | the markup and you should see the cookie law banner at the top of the page until 85 | you dismiss it with the button in the top-right. This CSS is Twitter Bootstrap 86 | compatible, but chances are, you'll like to adjust it anyway. 87 | 88 | To change the markup, just add a template named ``cookielaw/banner.html`` and 89 | make sure it is loaded before the default template (for example put the 90 | ``django.template.loaders.filesystem.Loader`` before 91 | ``django.template.loaders.app_directories.Loader`` and add your new template 92 | to any of the ``TEMPLATE_DIRS``). 93 | 94 | To change the CSS, just write your own rules and don't include the default 95 | stylesheet. 96 | 97 | If you want your visitors to be able to reject the cookies, you should setup 98 | `cookielaw` context processor by adding it to `TEMPLATE_CONTEXT_PROCESSORS` 99 | like this: 100 | 101 | :: 102 | 103 | TEMPLATE_CONTEXT_PROCESSORS = ( 104 | ... 105 | 'cookielaw.context_processors.cookielaw' 106 | ) 107 | 108 | That will add ``cookielaw`` context variable to the template context. That 109 | variable is a dict with 3 keys: ``notset``, ``accepted`` and ``rejected``, each 110 | with ``true`` or ``false`` value. 111 | 112 | Instead of default ``banner.html`` template, use ``rejectable.html`` one which 113 | shows an example of how to reject the cookies (of course, you may change the 114 | template to suit your own needs, just take care that you have 115 | ``
`` container. 116 | 117 | In your templates, you can choose to display the banner only for new visitors 118 | (case when cookie is not set): 119 | 120 | :: 121 | 122 | {% load cookielaw_tags %} 123 | {% if cookielaw.notset %}{% rejectable_cookielaw_banner %}{% endif %} 124 | 125 | Of course, you may use ``{% cookielaw_banner %}`` as well. 126 | 127 | Once the visitors accepts or rejects the cookies, you may choose to load or not 128 | load the analytics trackers: 129 | 130 | :: 131 | 132 | {% if cookielaw.accepted %} 133 | ... the code to load tracker ... 134 | {% endif %} 135 | 136 | Bugs & Contribution 137 | =================== 138 | 139 | Please use Github to report bugs, feature requests and submit your code: 140 | http://github.com/TyMaszWeb/django-cookie-law 141 | 142 | :author: Piotr Kilczuk 143 | :date: 2013/04/08 144 | 145 | -------------------------------------------------------------------------------- /cookielaw/__init__.py: -------------------------------------------------------------------------------- 1 | VERSION = (2, 2, 0) 2 | -------------------------------------------------------------------------------- /cookielaw/context_processors.py: -------------------------------------------------------------------------------- 1 | 2 | def cookielaw(request): 3 | """Add cookielaw context variable to the context.""" 4 | 5 | cookie = request.COOKIES.get('cookielaw_accepted') 6 | return { 7 | 'cookielaw': { 8 | 'notset': cookie is None, 9 | 'accepted': cookie == '1', 10 | 'rejected': cookie == '0', 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cookielaw/locale/ca/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/ca/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/ca/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2016-09-18 15:55+0200\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | 21 | #: templates/cookielaw/banner.html:5 tests.py:24 22 | msgid "COOKIE_INFO_HEADER" 23 | msgstr "Avís de cookies" 24 | 25 | #: templates/cookielaw/banner.html:7 tests.py:26 26 | msgid "COOKIE_INFO_OK" 27 | msgstr "Estic d'acord" 28 | 29 | #: templates/cookielaw/banner.html:8 tests.py:25 30 | msgid "COOKIE_INFO_PARA" 31 | msgstr "" 32 | "Aquesta plana web guarda petits fragments d'informació (cookies) en el vostre dispositiu amb la finalitat d'oferir " 33 | "un millor contingut i per a finalitats estadístiques. Vostè pot desactivar l'ús de cookies modificant la " 34 | "configuració del seu navegador. Navegar per la nostra plana web sense canviar la configuració del navegador fa que " 35 | "vostè ens està autoritzant a emmagatzemar aquesta informació en el seu dispositiu." 36 | -------------------------------------------------------------------------------- /cookielaw/locale/de/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/de/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/de/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2016-11-04 14:01+0200\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | 21 | #: templates/cookielaw/banner.html:5 22 | msgid "COOKIE_INFO_HEADER" 23 | msgstr "Cookie Warnung" 24 | 25 | #: templates/cookielaw/banner.html:7 26 | msgid "COOKIE_INFO_OK" 27 | msgstr "Akzeptieren" 28 | 29 | #: templates/cookielaw/banner.html:8 30 | msgid "COOKIE_INFO_PARA" 31 | msgstr "" 32 | "Für statistische Zwecke und um bestmögliche Funktionalität zu bieten, " 33 | "speichert diese Website Cookies auf Ihrem Gerät. Das Speichern von Cookies " 34 | "kann in den Browser-Einstellungen deaktiviert werden. Wenn Sie die Website " 35 | "weiter nutzen, stimmen Sie der Verwendung von Cookies zu." 36 | -------------------------------------------------------------------------------- /cookielaw/locale/en/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/en/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/en/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2021-07-07 11:32+0200\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | 20 | #: templates/cookielaw/banner.html:5 templates/cookielaw/rejectable.html:5 21 | msgid "COOKIE_INFO_HEADER" 22 | msgstr "Cookies disclaimer" 23 | 24 | #: templates/cookielaw/banner.html:7 templates/cookielaw/rejectable.html:7 25 | msgid "COOKIE_INFO_OK" 26 | msgstr "I agree" 27 | 28 | #: templates/cookielaw/banner.html:8 templates/cookielaw/rejectable.html:9 29 | msgid "COOKIE_INFO_PARA" 30 | msgstr "" 31 | "Our site saves small pieces of text information (cookies) on your device in " 32 | "order to deliver better content and for statistical purposes. You can " 33 | "disable the usage of cookies by changing the settings of your browser. By " 34 | "browsing our website without changing the browser settings you grant us " 35 | "permission to store that information on your device." 36 | 37 | #: templates/cookielaw/rejectable.html:8 38 | msgid "COOKIE_INFO_REJECT" 39 | msgstr "I disagree" 40 | -------------------------------------------------------------------------------- /cookielaw/locale/es/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/es/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/es/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | msgid "" 7 | msgstr "" 8 | "Project-Id-Version: PACKAGE VERSION\n" 9 | "Report-Msgid-Bugs-To: \n" 10 | "POT-Creation-Date: 2016-06-03 09:19+0200\n" 11 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 12 | "Last-Translator: FULL NAME \n" 13 | "Language-Team: LANGUAGE \n" 14 | "Language: \n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=UTF-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | 19 | #: templates/cookielaw/banner.html:5 20 | msgid "COOKIE_INFO_HEADER" 21 | msgstr "Aviso de cookies" 22 | 23 | #: templates/cookielaw/banner.html:7 24 | msgid "COOKIE_INFO_OK" 25 | msgstr "Estoy de acuerdo" 26 | 27 | #: templates/cookielaw/banner.html:8 28 | msgid "COOKIE_INFO_PARA" 29 | msgstr "" 30 | "Este sitio web guarda pequeños fragmentos de información (cookies) en su dispositivo con la finalidad de ofrecer un " 31 | "mejor contenido y para finalidades estadísticas. Usted puede desactivar el uso de cookies modificando la " 32 | "configuración de su navegador. Navegar por nuestro sitio web sin cambiar la configuración del navegador hace que " 33 | "usted nos esté autorizando a guardar esta información en su dispositivo." 34 | -------------------------------------------------------------------------------- /cookielaw/locale/fi/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/fi/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/fi/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2021-01-12 13:28+0200\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: Jyri Hämäläinen \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: Finnish\n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | 21 | #: templates/cookielaw/banner.html:5 22 | msgid "COOKIE_INFO_HEADER" 23 | msgstr "Evästehuomautus" 24 | 25 | #: templates/cookielaw/banner.html:7 26 | msgid "COOKIE_INFO_OK" 27 | msgstr "Selvä" 28 | 29 | #: templates/cookielaw/banner.html:8 30 | msgid "COOKIE_INFO_PARA" 31 | msgstr "Sivustomme tallentaa laitteellesi pieniä määriä tekstimuotoista dataa " 32 | "eli evästeitä (eng. cookie) tilastointitarkoituksiin ja voidaksemme tarjota " 33 | "parempaa sisältöä. Voit estää evästeiden käytön selaimesi asetuksista. " 34 | "Käyttämällä sivustoa muuttamatta selaimen asetuksia, annat meidän jatkaa " 35 | "tämän datan tallentamista laitteellesi." 36 | -------------------------------------------------------------------------------- /cookielaw/locale/fr/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/fr/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/fr/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # French translation for https://github.com/TyMaszWeb/django-cookie-law/. 2 | # Copyright (C) 2016 https://github.com/TyMaszWeb/ 3 | # This file is distributed under the same license as the https://github.com/TyMaszWeb/django-cookie-law/ package. 4 | # Lilian Besson , 2016. 5 | # Cognat Laurent , 2015. 6 | # 7 | #, fuzzy 8 | msgid "" 9 | msgstr "" 10 | "Project-Id-Version: PACKAGE VERSION\n" 11 | "Report-Msgid-Bugs-To: \n" 12 | "POT-Creation-Date: 2015-05-05 18:08+0200\n" 13 | "PO-Revision-Date: 2016-12-07 22:15+0200\n" 14 | "Last-Translator: Lilian Besson \n" 15 | "Language-Team: NETSACH \n" 16 | "Language: \n" 17 | "MIME-Version: 1.0\n" 18 | "Content-Type: text/plain; charset=UTF-8\n" 19 | "Content-Transfer-Encoding: 8bit\n" 20 | 21 | #: templates/cookielaw/banner.html:5 22 | msgid "COOKIE_INFO_HEADER" 23 | msgstr "Consentement d'utilisation des cookies" 24 | 25 | #: templates/cookielaw/banner.html:7 26 | msgid "COOKIE_INFO_OK" 27 | msgstr "J'accepte" 28 | 29 | #: templates/cookielaw/banner.html:8 30 | msgid "COOKIE_INFO_PARA" 31 | msgstr "" 32 | "Notre site sauvegarde des traceurs textes (cookies) sur votre appareil afin " 33 | "de vous garantir de meilleurs contenus et à des fins de collectes statistiques. " 34 | "Vous pouvez désactiver l'usage des cookies en changeant les paramètres de votre " 35 | "navigateur. En poursuivant votre navigation sur notre site sans changer vos " 36 | "paramètres de navigateur, vous nous accordez la permission de conserver des " 37 | "informations sur votre appareil." 38 | -------------------------------------------------------------------------------- /cookielaw/locale/it/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/it/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/it/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2015-06-03 16:17+0200\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | 21 | #: templates/cookielaw/banner.html:5 tests.py:24 22 | msgid "COOKIE_INFO_HEADER" 23 | msgstr "Informativa e consenso per l'uso dei cookie" 24 | 25 | #: templates/cookielaw/banner.html:7 tests.py:26 26 | msgid "COOKIE_INFO_OK" 27 | msgstr "Accetto" 28 | 29 | #: templates/cookielaw/banner.html:8 tests.py:25 30 | msgid "COOKIE_INFO_PARA" 31 | msgstr "" 32 | "Il nostro sito salva piccoli pezzi di informazioni (cookie) sul dispositivo, " 33 | "al fine di fornire contenuti migliori e per scopi statistici. È possibile " 34 | "disattivare l'utilizzo di cookies modificando le impostazioni del tuo browser. " 35 | "Continuando la navigazione si acconsente all'utilizzo dei cookie." 36 | -------------------------------------------------------------------------------- /cookielaw/locale/nl/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/nl/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/nl/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2015-07-17 14:17+0200\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | 21 | #: templates/cookielaw/banner.html:5 22 | msgid "COOKIE_INFO_HEADER" 23 | msgstr "Cookie melding" 24 | 25 | #: templates/cookielaw/banner.html:7 26 | msgid "COOKIE_INFO_OK" 27 | msgstr "Ik ga akkoord" 28 | 29 | #: templates/cookielaw/banner.html:8 30 | msgid "COOKIE_INFO_PARA" 31 | msgstr "" 32 | "Tijdens het surfen op het internet worden uw voorkeuren onthouden door middel van cookies. " 33 | "Cookies zijn kleine tekstbestanden die door een internetpagina op een pc, tablet of mobiele telefoon worden geplaatst. " 34 | "Cookies worden gebruikt om uw gebruikerservaring te verbeteren door het anoniem monitoren van webbezoek, " 35 | "het delen van informatie op social media mogelijk te maken, de effectiviteit van online marketingcampagnes te " 36 | "meten en om online advertenties aan te passen aan uw interesses. " 37 | "Door te surfen op deze website gaat u akkoord met het plaatsen van cookies." 38 | -------------------------------------------------------------------------------- /cookielaw/locale/pl/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/pl/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/pl/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2013-05-10 14:01+0200\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " 20 | "|| n%100>=20) ? 1 : 2);\n" 21 | 22 | #: templates/cookielaw/banner.html:5 23 | msgid "COOKIE_INFO_HEADER" 24 | msgstr "Informacja o cookies" 25 | 26 | #: templates/cookielaw/banner.html:7 27 | msgid "COOKIE_INFO_OK" 28 | msgstr "Zgadzam się" 29 | 30 | #: templates/cookielaw/banner.html:8 31 | msgid "COOKIE_INFO_PARA" 32 | msgstr "" 33 | "Nasza strona zapisuje niewielkie pliki tekstowe, nazywane ciasteczkami (ang. " 34 | "cookies) na Twoim urządzeniu w celu lepszego dostosowania treści oraz dla " 35 | "celów statystycznych. Możesz wyłączyć możliwość ich zapisu, zmieniając " 36 | "ustawienia Twojej przeglądarki. Korzystanie z naszej strony bez zmiany " 37 | "ustawień oznacza zgodę na przechowywanie cookies w Twoim urządzeniu." 38 | -------------------------------------------------------------------------------- /cookielaw/locale/ru/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/locale/ru/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /cookielaw/locale/ru/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2016-04-08 10:20+0100\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: Netsach SAS for MSF \n" 14 | "Language-Team: Netsach SAS \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" 20 | "%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n" 21 | "%100>=11 && n%100<=14)? 2 : 3);\n" 22 | 23 | #: templates/cookielaw/banner.html:5 tests.py:24 24 | msgid "COOKIE_INFO_HEADER" 25 | msgstr "Соглашение об использовании cookie-файлов" 26 | 27 | #: templates/cookielaw/banner.html:7 tests.py:26 28 | msgid "COOKIE_INFO_OK" 29 | msgstr "Принимаю" 30 | 31 | #: templates/cookielaw/banner.html:8 tests.py:25 32 | msgid "COOKIE_INFO_PARA" 33 | msgstr "Наш сайт сохранит анонимные идентификаторы (cookie-файлы) на ваше устройство. Это способствует персонализации контента, а также используется в статистических целях. Вы можете отключить использование cookie-файлов, изменив настройки Вашего браузера. Пользуясь этим сайтом при настройках браузера по умолчанию, вы соглашаетесь на использование cookie-файлов и сохранение информации на Вашем устройстве." 34 | -------------------------------------------------------------------------------- /cookielaw/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /cookielaw/static/cookielaw/css/cookielaw.css: -------------------------------------------------------------------------------- 1 | #CookielawBanner { 2 | background: #fff; 3 | padding: 15px 0; 4 | } 5 | 6 | #CookielawBanner .container { 7 | position: relative; 8 | } 9 | 10 | #CookielawBanner #CookielawCross { 11 | background: url('../img/close.png') no-repeat 0 0; 12 | cursor: pointer; 13 | display: block; 14 | position: absolute; 15 | top: 0; 16 | right: 0; 17 | width: 15px; 18 | height: 15px; 19 | } 20 | -------------------------------------------------------------------------------- /cookielaw/static/cookielaw/img/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/static/cookielaw/img/close.png -------------------------------------------------------------------------------- /cookielaw/static/cookielaw/js/cookielaw.js: -------------------------------------------------------------------------------- 1 | var Cookielaw = { 2 | ACCEPTED: '1', 3 | REJECTED: '0', 4 | 5 | createCookie: function (name, value, days, secure = true) { 6 | var date = new Date(), 7 | expires = ''; 8 | if (days) { 9 | date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 10 | expires = "; expires=" + date.toGMTString(); 11 | } else { 12 | expires = ""; 13 | } 14 | 15 | var secureString = ""; 16 | if (window.isSecureContext && secure) { 17 | secureString = "; Secure"; 18 | } 19 | 20 | document.cookie = name + "=" + value + expires + "; path=/" + secureString; 21 | }, 22 | 23 | setCookielawCookie: function (cookieValue, secure = true) { 24 | cookieValue = cookieValue || this.ACCEPTED; 25 | this.createCookie('cookielaw_accepted', cookieValue, 10 * 365, secure); 26 | }, 27 | 28 | hideCookielawBanner: function () { 29 | document.getElementById('CookielawBanner').remove(); 30 | }, 31 | 32 | accept: function () { 33 | this.setCookielawCookie(this.ACCEPTED); 34 | this.hideCookielawBanner(); 35 | }, 36 | 37 | reject: function () { 38 | this.setCookielawCookie(this.REJECTED); 39 | this.hideCookielawBanner(); 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /cookielaw/templates/cookielaw/banner.html: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | 3 |
4 |
5 |
{% trans "COOKIE_INFO_HEADER" %}
6 |

7 | {% trans "COOKIE_INFO_OK" %} 8 | {% trans "COOKIE_INFO_PARA" %} 9 |

10 |
11 |
12 | 13 | -------------------------------------------------------------------------------- /cookielaw/templates/cookielaw/rejectable.html: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | 3 |
4 |
5 |
{% trans "COOKIE_INFO_HEADER" %}
6 |

7 | {% trans "COOKIE_INFO_OK" %} 8 | {% trans "COOKIE_INFO_REJECT" %} 9 | {% trans "COOKIE_INFO_PARA" %} 10 |

11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /cookielaw/templatetags/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/templatetags/__init__.py -------------------------------------------------------------------------------- /cookielaw/templatetags/cookielaw_tags.py: -------------------------------------------------------------------------------- 1 | import warnings 2 | import django 3 | 4 | from classytags.helpers import InclusionTag 5 | from django import template 6 | from django.template.loader import render_to_string 7 | 8 | register = template.Library() 9 | 10 | 11 | class CookielawBanner(InclusionTag): 12 | """ 13 | Displays cookie law banner only if user has not dismissed it yet. 14 | """ 15 | 16 | template = "cookielaw/banner.html" 17 | 18 | def render_tag(self, context, **kwargs): 19 | template_filename = self.get_template(context, **kwargs) 20 | 21 | if "request" not in context: 22 | warnings.warn( 23 | "No request object in context. " 24 | "Are you sure you have django.core.context_processors.request enabled?" 25 | ) 26 | return "" 27 | 28 | elif context["request"].COOKIES.get("cookielaw_accepted", False): 29 | return "" 30 | 31 | data = self.get_context(context, **kwargs) 32 | 33 | if django.VERSION[:2] < (1, 10): 34 | return render_to_string(template_filename, data, context_instance=context) 35 | else: 36 | return render_to_string( 37 | template_filename, data, getattr(context, "request", None) 38 | ) 39 | 40 | 41 | class RejectableCookielawBanner(CookielawBanner): 42 | """Displays cookie law banner with options to accept or reject cookies.""" 43 | 44 | template = "cookielaw/rejectable.html" 45 | 46 | 47 | register.tag(CookielawBanner) 48 | register.tag(RejectableCookielawBanner) 49 | -------------------------------------------------------------------------------- /cookielaw/test_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/test_project/__init__.py -------------------------------------------------------------------------------- /cookielaw/test_project/test_app/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/cookielaw/test_project/test_app/__init__.py -------------------------------------------------------------------------------- /cookielaw/test_project/test_app/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /cookielaw/test_project/test_app/templates/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | django-cookie-law test suite 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

Server error

16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /cookielaw/test_project/test_app/templates/accepted.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block body %} 4 | {% if cookielaw.accepted %}

Cookies are good.

{% endif %} 5 | {% endblock %} 6 | -------------------------------------------------------------------------------- /cookielaw/test_project/test_app/templates/base.html: -------------------------------------------------------------------------------- 1 | {% load cookielaw_tags %} 2 | 3 | 4 | 5 | 6 | 7 | django-cookie-law test suite 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | {% block body %}{% endblock %} 17 | 18 | 19 | -------------------------------------------------------------------------------- /cookielaw/test_project/test_app/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% load cookielaw_tags %} 3 | 4 | {% block body %} 5 | 6 | {% cookielaw_banner %} 7 | 8 |
9 |

Lorem ipsum dolor sit amet

10 |

11 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. 12 | Vestibulum eu sem dictum, viverra enim at, iaculis nunc. 13 | Aliquam posuere pulvinar ex vitae venenatis. 14 | Nunc pellentesque, odio at malesuada feugiat, nunc turpis tincidunt orci, id cursus risus nisl nec mauris. 15 | Praesent vitae ligula ipsum. Curabitur commodo ante dapibus diam rutrum ultricies. 16 |

17 |
18 | 19 | {% endblock %} 20 | -------------------------------------------------------------------------------- /cookielaw/test_project/test_app/templates/rejectable.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% load cookielaw_tags %} 3 | 4 | {% block body %} 5 | {% if cookielaw.notset %}{% rejectable_cookielaw_banner %}{% endif %} 6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /cookielaw/test_project/test_app/templates/rejected.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% load cookielaw_tags %} 3 | 4 | {% block body %} 5 | {% if cookielaw.rejected %}

Cookies are bad.

{% endif %} 6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /cookielaw/test_project/test_app/views.py: -------------------------------------------------------------------------------- 1 | from django.views.generic import TemplateView 2 | 3 | 4 | class HomeView(TemplateView): 5 | template_name = 'home.html' 6 | 7 | 8 | class AcceptedView(TemplateView): 9 | template_name = 'accepted.html' 10 | 11 | 12 | class RejectableView(TemplateView): 13 | template_name = 'rejectable.html' 14 | 15 | 16 | class RejectedView(TemplateView): 17 | template_name = 'rejected.html' 18 | -------------------------------------------------------------------------------- /cookielaw/test_project/urls.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | from django.conf import settings 4 | from django.urls import re_path 5 | from django.views import static 6 | 7 | from .test_app.views import HomeView, AcceptedView, RejectableView, RejectedView 8 | 9 | urlpatterns = [ 10 | re_path(r'^$', HomeView.as_view()), 11 | re_path('^accepted$', AcceptedView.as_view()), 12 | re_path('^rejectable$', RejectableView.as_view()), 13 | re_path('^rejected$', RejectedView.as_view()), 14 | 15 | re_path(r'^static', static.serve, {'document_root': settings.STATIC_ROOT}), 16 | ] 17 | -------------------------------------------------------------------------------- /cookielaw/test_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for test_project project. 3 | 4 | This module contains the WSGI application used by Django's development server 5 | and any production WSGI deployments. It should expose a module-level variable 6 | named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover 7 | this application via the ``WSGI_APPLICATION`` setting. 8 | 9 | Usually you will have the standard Django WSGI application here, but it also 10 | might make sense to replace the whole Django WSGI application with a custom one 11 | that later delegates to the Django one. For example, you could introduce WSGI 12 | middleware here, or combine a Django application with an application of another 13 | framework. 14 | 15 | """ 16 | import os 17 | 18 | # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks 19 | # if running multiple sites in the same mod_wsgi process. To fix this, use 20 | # mod_wsgi daemon mode with each site in its own daemon process, or use 21 | # os.environ["DJANGO_SETTINGS_MODULE"] = "test_project.settings" 22 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings") 23 | 24 | # This application object is used by any WSGI server configured to use this 25 | # file. This includes Django's development server, if the WSGI_APPLICATION 26 | # setting points here. 27 | from django.core.wsgi import get_wsgi_application 28 | application = get_wsgi_application() 29 | 30 | # Apply WSGI middleware here. 31 | # from helloworld.wsgi import HelloWorldApplication 32 | # application = HelloWorldApplication(application) 33 | -------------------------------------------------------------------------------- /cookielaw/views.py: -------------------------------------------------------------------------------- 1 | # Create your views here. 2 | -------------------------------------------------------------------------------- /settings.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | SECRET_KEY = 'test' 4 | 5 | DATABASES = { 6 | 'default': { 7 | 'ENGINE': 'django.db.backends.sqlite3', 8 | } 9 | } 10 | INSTALLED_APPS = ( 11 | 'django.contrib.auth', 12 | 'django.contrib.contenttypes', 13 | 'django.contrib.sessions', 14 | 'django.contrib.sites', 15 | 'django.contrib.messages', 16 | 'django.contrib.staticfiles', 17 | 'cookielaw', 18 | 'cookielaw.test_project.test_app', 19 | ) 20 | MIDDLEWARE_CLASSES = ( 21 | 'django.middleware.common.CommonMiddleware', 22 | ) 23 | ROOT_URLCONF = 'cookielaw.test_project.urls' 24 | STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'cookielaw', 'static') 25 | STATIC_URL = '/static/' 26 | 27 | TEMPLATES = [ 28 | { 29 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 30 | 'DIRS': [ 31 | # insert your TEMPLATE_DIRS here 32 | ], 33 | 'APP_DIRS': True, 34 | 'OPTIONS': { 35 | 'context_processors': [ 36 | # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this 37 | # list if you haven't customized them: 38 | 'django.contrib.auth.context_processors.auth', 39 | 'django.template.context_processors.debug', 40 | 'django.template.context_processors.i18n', 41 | 'django.template.context_processors.media', 42 | 'django.template.context_processors.request', 43 | 'django.template.context_processors.static', 44 | 'django.template.context_processors.tz', 45 | 'django.contrib.messages.context_processors.messages', 46 | 'cookielaw.context_processors.cookielaw', 47 | ], 48 | }, 49 | }, 50 | ] 51 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [aliases] 2 | test=pytest 3 | 4 | [tool:pytest] 5 | DJANGO_SETTINGS_MODULE=settings 6 | norecursedirs=lib include 7 | addopts=--reuse-db --driver Chrome 8 | testpaths=tests 9 | python_files=test_*.py 10 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | from setuptools import setup, find_packages 5 | from itertools import chain 6 | from glob import glob 7 | 8 | import cookielaw 9 | 10 | 11 | CLASSIFIERS = [ 12 | 'Development Status :: 5 - Production/Stable', 13 | 'Environment :: Web Environment', 14 | 'Framework :: Django', 15 | 'Intended Audience :: Developers', 16 | 'License :: OSI Approved :: BSD License', 17 | 'Operating System :: OS Independent', 18 | 'Programming Language :: Python', 19 | 'Programming Language :: JavaScript', 20 | 'Topic :: Internet :: WWW/HTTP', 21 | 'Topic :: Internet :: WWW/HTTP :: Session', 22 | ] 23 | 24 | package_data_globs = ( 25 | 'cookielaw/templates/cookielaw/*.html', 26 | 'cookielaw/static/cookielaw/*/*', 27 | 'cookielaw/locale/*/*/*' 28 | ) 29 | 30 | package_data = [] 31 | for f in chain(*map(glob, package_data_globs)): 32 | package_data.append(f.split('/', 1)[1]) 33 | 34 | setup( 35 | author='Piotr Kilczuk', 36 | author_email='piotr@tymaszweb.pl', 37 | name='django-cookie-law', 38 | version='.'.join(str(v) for v in cookielaw.VERSION), 39 | description='Helps your Django project comply with EU cookie law regulations', 40 | long_description=open(os.path.join(os.path.dirname(__file__), 'README.rst')).read(), 41 | url='https://github.com/TyMaszWeb/django-cookie-law', 42 | license='BSD License', 43 | platforms=['OS Independent'], 44 | classifiers=CLASSIFIERS, 45 | install_requires=[ 46 | 'Django>=1.8', 47 | 'django-classy-tags>=0.3.0', 48 | ], 49 | packages=find_packages(), 50 | package_data={'cookielaw': package_data}, 51 | include_package_data=False, 52 | zip_safe=False, 53 | ) 54 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TyMaszWeb/django-cookie-law/a886bf602ebf2e71e7ed3db6aba654d7aa1a6083/tests/__init__.py -------------------------------------------------------------------------------- /tests/test_base.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from django.utils.translation import gettext as _ 3 | 4 | 5 | @pytest.fixture() 6 | def content(client): 7 | response = client.get("/") 8 | assert 200 == response.status_code 9 | return response.content.decode("utf-8") 10 | 11 | 12 | def test_banner_shows(content): 13 | assert "CookielawBanner" in content 14 | 15 | 16 | def test_banner_contains_correct_text(content): 17 | assert _("COOKIE_INFO_HEADER") in content 18 | assert _("COOKIE_INFO_PARA") in content 19 | assert _("COOKIE_INFO_OK") in content 20 | -------------------------------------------------------------------------------- /tests/test_functional.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from selenium.common.exceptions import NoSuchElementException 3 | 4 | 5 | @pytest.fixture 6 | def selenium(selenium): 7 | selenium.implicitly_wait(10) 8 | selenium.maximize_window() 9 | return selenium 10 | 11 | 12 | def test_banner_shows_and_hides(selenium, live_server): 13 | selenium.get(live_server.url) 14 | cookielaw_banner = selenium.find_element_by_id("CookielawBanner") 15 | 16 | # on click of the button, cookie set and banner hidden 17 | cookielaw_banner.find_element_by_class_name("btn").click() 18 | with pytest.raises(NoSuchElementException): 19 | selenium.find_element_by_id("CookielawBanner") 20 | assert "1" == selenium.get_cookie("cookielaw_accepted")["value"] 21 | 22 | # on come back, assert banner gone 23 | selenium.get(live_server.url) 24 | 25 | with pytest.raises(NoSuchElementException): 26 | selenium.find_element_by_id("CookielawBanner") 27 | 28 | 29 | def test_text_is_not_rendered_unless_cookies_are_accepted(selenium, live_server): 30 | selenium.get(f"{live_server.url}/accepted") 31 | with pytest.raises(NoSuchElementException): 32 | selenium.find_element_by_id("msg") 33 | 34 | 35 | def test_when_cookies_are_accepted(selenium, live_server): 36 | # accept cookies 37 | selenium.get(live_server.url) 38 | cookielaw_banner = selenium.find_element_by_id("CookielawBanner") 39 | cookielaw_banner.find_element_by_class_name("btn").click() 40 | 41 | # go to different page and test if context_processor filled the 42 | # cookielaw variable 43 | selenium.get(f"{live_server.url}/accepted") 44 | msg = selenium.find_element_by_id("msg") 45 | assert msg 46 | assert msg.text == "Cookies are good." 47 | 48 | 49 | def test_reject_cookies_hides_banner(selenium, live_server): 50 | # load page with rejectable banner and click reject button 51 | selenium.get(f"{live_server.url}/rejectable") 52 | selenium.find_element_by_id("CookielawBanner").find_element_by_class_name( 53 | "reject" 54 | ).click() 55 | 56 | # reload the page and the banner should not be displayed 57 | selenium.get(live_server.url) 58 | with pytest.raises(NoSuchElementException): 59 | selenium.find_element_by_id("CookielawBanner") 60 | 61 | 62 | def test_when_cookies_are_rejected(selenium, live_server): 63 | # load page with rejectable banner and click reject button 64 | selenium.get(f"{live_server.url}/rejectable") 65 | selenium.find_element_by_id("CookielawBanner").find_element_by_class_name( 66 | "reject" 67 | ).click() 68 | 69 | # go to different page and test if context_processor filled the 70 | # cookielaw variable 71 | selenium.get(f"{live_server.url}/rejected") 72 | msg = selenium.find_element_by_id("msg") 73 | assert msg 74 | assert msg.text == "Cookies are bad." 75 | --------------------------------------------------------------------------------