From d951ffff2cec695d34d47b574f16bdd3a1dc7120 Mon Sep 17 00:00:00 2001 From: Diederik van der Boor Date: Tue, 16 Nov 2021 12:22:57 +0100 Subject: [PATCH] black and isort --- fluentcms_cookielaw/appsettings.py | 6 +- fluentcms_cookielaw/content_plugins.py | 4 +- .../migrations/0001_initial.py | 36 +++++--- fluentcms_cookielaw/models.py | 8 +- fluentcms_cookielaw/tests.py | 20 +++-- pyproject.toml | 14 +++ setup.py | 87 +++++++++---------- 7 files changed, 108 insertions(+), 67 deletions(-) create mode 100644 pyproject.toml diff --git a/fluentcms_cookielaw/appsettings.py b/fluentcms_cookielaw/appsettings.py index b768ce9..0ef12c2 100644 --- a/fluentcms_cookielaw/appsettings.py +++ b/fluentcms_cookielaw/appsettings.py @@ -1,7 +1,7 @@ from django.conf import settings -_default_js = ('fluentcms_cookielaw/js/cookielaw.js',) +_default_js = ("fluentcms_cookielaw/js/cookielaw.js",) # Allow overriding the complete FrontendMedia definition -FLUENTCMS_COOKIELAW_JS = getattr(settings, 'FLUENTCMS_COOKIELAW_JS', _default_js) -FLUENTCMS_COOKIELAW_CSS = getattr(settings, 'FLUENTCMS_COOKIELAW_CSS', {}) +FLUENTCMS_COOKIELAW_JS = getattr(settings, "FLUENTCMS_COOKIELAW_JS", _default_js) +FLUENTCMS_COOKIELAW_CSS = getattr(settings, "FLUENTCMS_COOKIELAW_CSS", {}) diff --git a/fluentcms_cookielaw/content_plugins.py b/fluentcms_cookielaw/content_plugins.py index 2e057d3..58ec9dc 100644 --- a/fluentcms_cookielaw/content_plugins.py +++ b/fluentcms_cookielaw/content_plugins.py @@ -1,5 +1,6 @@ from django.utils.translation import gettext_lazy as _ -from fluent_contents.extensions import plugin_pool, ContentPlugin +from fluent_contents.extensions import ContentPlugin, plugin_pool + from . import appsettings from .models import CookieLawItem @@ -9,6 +10,7 @@ class CookieLawPlugin(ContentPlugin): """ Showing a cookie law notification """ + model = CookieLawItem category = _("Footer") render_template = "fluentcms_cookielaw/banner.html" diff --git a/fluentcms_cookielaw/migrations/0001_initial.py b/fluentcms_cookielaw/migrations/0001_initial.py index 77117cf..bbbc660 100644 --- a/fluentcms_cookielaw/migrations/0001_initial.py +++ b/fluentcms_cookielaw/migrations/0001_initial.py @@ -1,26 +1,42 @@ -from django.db import models, migrations import fluent_contents.extensions +from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('fluent_contents', '0001_initial'), + ("fluent_contents", "0001_initial"), ] operations = [ migrations.CreateModel( - name='CookieLawItem', + name="CookieLawItem", fields=[ - ('contentitem_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='fluent_contents.ContentItem', on_delete=models.CASCADE)), - ('text', fluent_contents.extensions.PluginHtmlField(help_text="For example: 'We use cookies to ensure you get the best experience on our website'", verbose_name='Text')), - ('button_text', models.CharField(max_length=100, verbose_name='Button text')), + ( + "contentitem_ptr", + models.OneToOneField( + parent_link=True, + auto_created=True, + primary_key=True, + serialize=False, + to="fluent_contents.ContentItem", + on_delete=models.CASCADE, + ), + ), + ( + "text", + fluent_contents.extensions.PluginHtmlField( + help_text="For example: 'We use cookies to ensure you get the best experience on our website'", + verbose_name="Text", + ), + ), + ("button_text", models.CharField(max_length=100, verbose_name="Button text")), ], options={ - 'db_table': 'contentitem_fluentcms_cookielaw_cookielawitem', - 'verbose_name': 'Cookie notification', - 'verbose_name_plural': 'Cookie notifications', + "db_table": "contentitem_fluentcms_cookielaw_cookielawitem", + "verbose_name": "Cookie notification", + "verbose_name_plural": "Cookie notifications", }, - bases=('fluent_contents.contentitem',), + bases=("fluent_contents.contentitem",), ), ] diff --git a/fluentcms_cookielaw/models.py b/fluentcms_cookielaw/models.py index c46a972..6b3e97a 100644 --- a/fluentcms_cookielaw/models.py +++ b/fluentcms_cookielaw/models.py @@ -10,7 +10,13 @@ class CookieLawItem(ContentItem): """ Cookie law item """ - text = PluginHtmlField(_("Text"), help_text=_("For example: 'We use cookies to ensure you get the best experience on our website'")) + + text = PluginHtmlField( + _("Text"), + help_text=_( + "For example: 'We use cookies to ensure you get the best experience on our website'" + ), + ) button_text = models.CharField(_("Button text"), max_length=100) # e.g. "Close" or "Accept" class Meta: diff --git a/fluentcms_cookielaw/tests.py b/fluentcms_cookielaw/tests.py index eb53577..79b4337 100644 --- a/fluentcms_cookielaw/tests.py +++ b/fluentcms_cookielaw/tests.py @@ -1,6 +1,7 @@ from django.test import TestCase from fluent_contents.tests.factories import create_content_item from fluent_contents.tests.utils import render_content_items + from fluentcms_cookielaw.models import CookieLawItem @@ -13,16 +14,23 @@ def test_rendering(self): """ Test the standard button """ - item = create_content_item(CookieLawItem, text="Do you like cookies?", button_text="Jummie!") + item = create_content_item( + CookieLawItem, text="Do you like cookies?", button_text="Jummie!" + ) output = render_content_items([item]) - self.assertHTMLEqual(output.html, - '''
+ self.assertHTMLEqual( + output.html, + """
Jummie! Do you like cookies?
-
''') - self.assertHTMLEqual(str(output.media), '') +
""", + ) + self.assertHTMLEqual( + str(output.media), + '', + ) - self.assertEqual(str(item), 'Do you like cookies?') + self.assertEqual(str(item), "Do you like cookies?") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4e2a811 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[tool.isort] +profile = "black" +line_length = 99 + +[tool.black] +line-length = 99 +exclude = ''' +/( + \.git + | \.venv + | \.tox + | dist +)/ +''' diff --git a/setup.py b/setup.py index f26d620..c8ccc4f 100755 --- a/setup.py +++ b/setup.py @@ -1,28 +1,29 @@ #!/usr/bin/env python -from setuptools import setup, find_packages -from os import path import codecs import os import re import sys +from os import path +from setuptools import find_packages, setup # When creating the sdist, make sure the django.mo file also exists: -if 'sdist' in sys.argv or 'develop' in sys.argv: - os.chdir('fluentcms_cookielaw') +if "sdist" in sys.argv or "develop" in sys.argv: + os.chdir("fluentcms_cookielaw") try: from django.core import management - management.call_command('compilemessages', stdout=sys.stderr, verbosity=1) + + management.call_command("compilemessages", stdout=sys.stderr, verbosity=1) except ImportError: - if 'sdist' in sys.argv: + if "sdist" in sys.argv: raise finally: - os.chdir('..') + os.chdir("..") def read(*parts): file_path = path.join(path.dirname(__file__), *parts) - return codecs.open(file_path, encoding='utf-8').read() + return codecs.open(file_path, encoding="utf-8").read() def find_version(*parts): @@ -34,49 +35,43 @@ def find_version(*parts): setup( - name='fluentcms-cookielaw', - version=find_version('fluentcms_cookielaw', '__init__.py'), - license='Apache 2.0', - + name="fluentcms-cookielaw", + version=find_version("fluentcms_cookielaw", "__init__.py"), + license="Apache 2.0", install_requires=[ - 'django-fluent-contents>=2.0', # Need frontend_media support. + "django-fluent-contents>=2.0", # Need frontend_media support. ], requires=[ - 'Django (>=1.10)', + "Django (>=1.10)", ], - - description='A cookie notification banner for django-fluent-contents', - long_description=read('README.rst'), - - author='Diederik van der Boor', - author_email='opensource@edoburu.nl', - - url='https://github.com/edoburu/fluentcms-cookielaw', - download_url='https://github.com/edoburu/fluentcms-cookielaw/zipball/master', - - packages=find_packages(exclude=('example*',)), + description="A cookie notification banner for django-fluent-contents", + long_description=read("README.rst"), + author="Diederik van der Boor", + author_email="opensource@edoburu.nl", + url="https://github.com/edoburu/fluentcms-cookielaw", + download_url="https://github.com/edoburu/fluentcms-cookielaw/zipball/master", + packages=find_packages(exclude=("example*",)), include_package_data=True, - zip_safe=False, classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Environment :: Web Environment', - 'Framework :: Django', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.6', - 'Framework :: Django', - 'Framework :: Django :: 1.10', - 'Framework :: Django :: 1.11', - 'Framework :: Django :: 2.0', - 'Topic :: Internet :: WWW/HTTP', - 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', - 'Topic :: Software Development :: Libraries :: Python Modules', - ] + "Development Status :: 5 - Production/Stable", + "Environment :: Web Environment", + "Framework :: Django", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.6", + "Framework :: Django", + "Framework :: Django :: 1.10", + "Framework :: Django :: 1.11", + "Framework :: Django :: 2.0", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Internet :: WWW/HTTP :: Dynamic Content", + "Topic :: Software Development :: Libraries :: Python Modules", + ], )