Skip to content

Commit 5f8bd34

Browse files
committed
Update project settings
1 parent f76f11c commit 5f8bd34

File tree

7 files changed

+107
-82
lines changed

7 files changed

+107
-82
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ repos:
1212
rev: v3.19.0
1313
hooks:
1414
- id: pyupgrade
15-
args: ["--py37-plus"]
15+
args: ["--py39-plus"]
1616
- repo: https://github.com/adamchainz/django-upgrade
1717
rev: "1.22.1"
1818
hooks:
1919
- id: django-upgrade
20-
args: [--target-version, "2.2"]
20+
args: [--target-version, "4.2"]
2121
- repo: https://github.com/pycqa/isort
2222
rev: 5.13.2
2323
hooks:
@@ -28,9 +28,9 @@ repos:
2828
hooks:
2929
- id: flake8
3030
additional_dependencies:
31+
- flake8-pyproject
3132
- flake8-bugbear
3233
- flake8-builtins
3334
- flake8-django
3435
- flake8-length
3536
- flake8-logging-format
36-
- flake8-spellcheck

djangocms_frontend/common/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
from .attributes import AttributesMixin
66
from .title import TitleFormMixin, TitleMixin
77

8+
89
__common = {
910
"background": ("BackgroundFormMixin", "BackgroundMixin"),
1011
"responsive": ("ResponsiveFormMixin", "ResponsiveMixin"),
1112
"sizing": ("SizingFormMixin", "SizingMixin"),
12-
"spacing": ("SpacingFormMixin", "SpacingMixin", "MarginFormMixin", "MarginMixin", "PaddingFormMixin", "PaddingMixin"),
13+
"spacing": (
14+
"SpacingFormMixin",
15+
"SpacingMixin",
16+
"MarginFormMixin",
17+
"MarginMixin",
18+
"PaddingFormMixin",
19+
"PaddingMixin",
20+
),
1321
}
1422

1523
for module, classes in __common.items():

djangocms_frontend/contrib/navigation/cms_plugins.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from cms.plugin_pool import plugin_pool
21
from django.utils.translation import gettext_lazy as _
32

3+
from cms.plugin_pool import plugin_pool
4+
45
from ... import settings
56
from ...cms_plugins import CMSUIPlugin
67
from ...common import AttributesMixin, BackgroundMixin
@@ -9,6 +10,7 @@
910
from ..link.cms_plugins import LinkPluginMixin, TextLinkPlugin
1011
from . import forms, models
1112

13+
1214
mixin_factory = settings.get_renderer(navigation)
1315

1416
default_template = first_choice(settings.NAVIGATION_TEMPLATE_CHOICES)
@@ -176,7 +178,8 @@ class NavLinkPlugin(
176178
- `module` (str): The module where the plugin belongs, displayed in the plugin list when editing a page.
177179
- `model` (Model): The Django model used to store the plugin's data.
178180
- `form` (Form): The form used to render the plugin's settings in the admin interface.
179-
- `change_form_template` (str): The path to the template used to render the plugin's change form in the admin interface.
181+
- `change_form_template` (str): The path to the template used to render the plugin's change form in the admin
182+
interface.
180183
- `allow_children` (bool): Whether the plugin allows having child plugins.
181184
- `parent_classes` (list): List of parent plugin classes that this plugin can be nested within.
182185
- `child_classes` (list): List of child plugin classes that can be nested within this plugin.

djangocms_frontend/helpers.py

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import copy
22
import decimal
33

4-
from cms.constants import SLUG_REGEXP
5-
from cms.plugin_base import CMSPluginBase
6-
from cms.utils.conf import get_cms_setting
74
from django.apps import apps
85
from django.contrib.admin.helpers import AdminForm
96
from django.db.models import ObjectDoesNotExist
@@ -15,6 +12,10 @@
1512
from django.utils.safestring import mark_safe
1613
from django.utils.translation import gettext_lazy as _
1714

15+
from cms.constants import SLUG_REGEXP
16+
from cms.plugin_base import CMSPluginBase
17+
from cms.utils.conf import get_cms_setting
18+
1819
from djangocms_frontend import settings
1920
from djangocms_frontend.settings import FRAMEWORK_PLUGIN_INFO
2021

@@ -33,6 +34,7 @@ def get_related_object(scope, field_name):
3334

3435
class get_related:
3536
"""Descriptor lazily getting related objects from the config dict."""
37+
3638
def __init__(self, key):
3739
self.key = key
3840

@@ -74,12 +76,12 @@ def insert_fields(fieldsets, new_fields, block=None, position=-1, blockname=None
7476
modify[1]["fields"] = (
7577
list(fields[: position + 1] if position != -1 else fields)
7678
+ list(new_fields)
77-
+ list(fields[position + 1 :] if position != -1 else [])
79+
+ list(fields[position + 1:] if position != -1 else [])
7880
)
7981
fs = (
8082
list(fieldsets[:block] if block != -1 else fieldsets)
8183
+ [modify]
82-
+ list(fieldsets[block + 1 :] if block != -1 else [])
84+
+ list(fieldsets[block + 1:] if block != -1 else [])
8385
)
8486
return fs
8587

@@ -165,6 +167,7 @@ class FrontendEditableAdminMixin:
165167
in the frontend by double-clicking on fields rendered with the ``render_model`` template
166168
tag.
167169
"""
170+
168171
frontend_editable_fields = []
169172

170173
def get_urls(self): # pragma: no cover
@@ -177,7 +180,7 @@ def pat(regex, fn):
177180
return re_path(regex, self.admin_site.admin_view(fn), name=f"{info}_{fn.__name__}")
178181

179182
url_patterns = [
180-
pat(r'edit-field/(%s)/([a-z\-]+)/$' % SLUG_REGEXP, self.edit_field),
183+
pat(r"edit-field/(%s)/([a-z\-]+)/$" % SLUG_REGEXP, self.edit_field),
181184
]
182185
return url_patterns + super().get_urls()
183186

@@ -203,58 +206,53 @@ def edit_field(self, request, object_id, language):
203206
raw_fields = request.GET.get("edit_fields")
204207
fields = [field for field in raw_fields.split(",") if field in self.frontend_editable_fields]
205208
if not fields:
206-
context = {
207-
'opts': opts,
208-
'message': _("Field %s not found") % raw_fields
209-
}
210-
return render(request, 'admin/cms/page/plugin/error_form.html', context)
209+
context = {"opts": opts, "message": _("Field %s not found") % raw_fields}
210+
return render(request, "admin/cms/page/plugin/error_form.html", context)
211211
if not request.user.has_perm(f"{self.model._meta.app_label}.change_{self.model._meta.model_name}"):
212-
context = {
213-
'opts': opts,
214-
'message': _("You do not have permission to edit this item")
215-
}
216-
return render(request, 'admin/cms/page/plugin/error_form.html', context)
212+
context = {"opts": opts, "message": _("You do not have permission to edit this item")}
213+
return render(request, "admin/cms/page/plugin/error_form.html", context)
217214
# Dynamically creates the form class with only `field_name` field
218215
# enabled
219216
form_class = self.get_form(request, obj, fields=fields)
220-
if not cancel_clicked and request.method == 'POST':
217+
if not cancel_clicked and request.method == "POST":
221218
form = form_class(instance=obj, data=request.POST)
222219
if form.is_valid():
223220
new_object = form.save(commit=False)
224221
self.save_model(request, new_object, form, change=True)
225222
saved_successfully = True
226223
else:
227224
form = form_class(instance=obj)
228-
admin_form = AdminForm(form, fieldsets=[(None, {'fields': fields})], prepopulated_fields={},
229-
model_admin=self)
225+
admin_form = AdminForm(form, fieldsets=[(None, {"fields": fields})], prepopulated_fields={}, model_admin=self)
230226
media = self.media + admin_form.media
231227
context = {
232-
'CMS_MEDIA_URL': get_cms_setting('MEDIA_URL'),
233-
'title': opts.verbose_name,
234-
'plugin': None,
235-
'plugin_id': None,
236-
'adminform': admin_form,
237-
'add': False,
238-
'is_popup': True,
239-
'media': media,
240-
'opts': opts,
241-
'change': True,
242-
'save_as': False,
243-
'has_add_permission': False,
244-
'window_close_timeout': 10,
228+
"CMS_MEDIA_URL": get_cms_setting("MEDIA_URL"),
229+
"title": opts.verbose_name,
230+
"plugin": None,
231+
"plugin_id": None,
232+
"adminform": admin_form,
233+
"add": False,
234+
"is_popup": True,
235+
"media": media,
236+
"opts": opts,
237+
"change": True,
238+
"save_as": False,
239+
"has_add_permission": False,
240+
"window_close_timeout": 10,
245241
}
246242
if cancel_clicked:
247243
# cancel button was clicked
248-
context.update({
249-
'cancel': True,
250-
})
251-
return render(request, 'admin/cms/page/plugin/confirm_form.html', context)
252-
if not cancel_clicked and request.method == 'POST' and saved_successfully:
244+
context.update(
245+
{
246+
"cancel": True,
247+
}
248+
)
249+
return render(request, "admin/cms/page/plugin/confirm_form.html", context)
250+
if not cancel_clicked and request.method == "POST" and saved_successfully:
253251
if isinstance(self, CMSPluginBase):
254-
if hasattr(obj.placeholder, 'mark_as_dirty'):
252+
if hasattr(obj.placeholder, "mark_as_dirty"):
255253
# Only relevant for v3: mark the placeholder as dirty so user can publish changes
256254
obj.placeholder.mark_as_dirty(obj.language, clear_cache=False)
257255
# Update the structure board by populating the data bridge
258256
return self.render_close_frame(request, obj)
259-
return render(request, 'admin/cms/page/plugin/confirm_form.html', context)
260-
return render(request, 'admin/cms/page/plugin/change_form.html', context)
257+
return render(request, "admin/cms/page/plugin/confirm_form.html", context)
258+
return render(request, "admin/cms/page/plugin/change_form.html", context)

djangocms_frontend/management/bootstrap4_migration.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.conf import settings as django_setting
2+
23
from djangocms_bootstrap4.constants import DEVICE_SIZES
34

45
from djangocms_frontend import settings
@@ -305,7 +306,7 @@ def replace(item, old, new):
305306

306307
def replace_left(item, old, new):
307308
if item[: len(old)] == old:
308-
return new + item[len(old) :]
309+
return new + item[len(old):]
309310
return item
310311

311312
classes = new_obj.attributes["class"].split()
@@ -361,7 +362,7 @@ def a001_alignment(obj, new_obj, field):
361362
new_obj.config[field].replace("text-right", "end")
362363

363364

364-
def m001_spacing_mixin(obj, new_obj, type):
365+
def m001_spacing_mixin(obj, new_obj, type): # noqa: A002
365366
classes = new_obj.config["attributes"].get("class", "").split()
366367
if classes:
367368
for size, _ in list(settings.SPACER_SIZE_CHOICES) + ([("auto", "auto")] if type == "margin" else []):
@@ -404,7 +405,7 @@ def m002_responsive_mixin(obj, new_obj):
404405
visible = False
405406
hit = True
406407
classes.remove(f"{stump}{hidden}")
407-
for type in display:
408+
for type in display: # noqa: A001
408409
if f"{stump}{type}" in classes and not visible:
409410
visible = True
410411
hit = True

pyproject.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,51 @@ lint.select = [
3333
"F",
3434
"W",
3535
]
36+
37+
[tool.isort]
38+
line_length = 119
39+
skip = [
40+
"manage.py",
41+
"*migrations*",
42+
".tox",
43+
".eggs",
44+
".env",
45+
".venv",
46+
"data",
47+
]
48+
include_trailing_comma = true
49+
multi_line_output = 5
50+
lines_after_imports = 2
51+
default_section = "THIRDPARTY"
52+
sections = [
53+
"FUTURE",
54+
"STDLIB",
55+
"DJANGO",
56+
"CMS",
57+
"THIRDPARTY",
58+
"FIRSTPARTY",
59+
"LOCALFOLDER",
60+
]
61+
known_first_party = "djangocms_link"
62+
known_cms = [ "cms", "menus" ]
63+
known_django = "django"
64+
65+
[tool.flake8]
66+
max-line-length = 120
67+
exclude = [
68+
"*.egg-info",
69+
".eggs",
70+
".env",
71+
".git",
72+
".settings",
73+
".tox",
74+
".venv",
75+
"build",
76+
"data",
77+
"dist",
78+
"docs",
79+
"*migrations*",
80+
"requirements",
81+
"tmp",
82+
]
83+

setup.cfg

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)