diff --git a/djangocms_alias/admin.py b/djangocms_alias/admin.py index cd653b5..0f32954 100644 --- a/djangocms_alias/admin.py +++ b/djangocms_alias/admin.py @@ -1,3 +1,6 @@ +from cms.admin.utils import GrouperModelAdmin +from cms.utils.permissions import get_model_permission_codename +from cms.utils.urlutils import admin_reverse from django import forms from django.contrib import admin from django.http import ( @@ -8,11 +11,6 @@ ) from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ - -from cms.admin.utils import GrouperModelAdmin -from cms.utils.permissions import get_model_permission_codename -from cms.utils.urlutils import admin_reverse - from parler.admin import TranslatableAdmin from .cms_config import AliasCMSConfig @@ -32,7 +30,6 @@ is_versioning_enabled, ) - __all__ = [ "AliasAdmin", "CategoryAdmin", @@ -94,9 +91,7 @@ def get_actions_list(self) -> list: """Add alias usage list actions""" return super().get_actions_list() + [self._get_alias_usage_link] - def can_change_content( - self, request: HttpRequest, content_obj: AliasContent - ) -> bool: + def can_change_content(self, request: HttpRequest, content_obj: AliasContent) -> bool: """Returns True if user can change content_obj""" if content_obj and is_versioning_enabled(): version = Version.objects.get_for_content(content_obj) @@ -114,9 +109,7 @@ def has_delete_permission(self, request: HttpRequest, obj: Alias = None) -> bool return request.user.is_superuser return False - def save_model( - self, request: HttpRequest, obj: Alias, form: forms.Form, change: bool - ) -> None: + def save_model(self, request: HttpRequest, obj: Alias, form: forms.Form, change: bool) -> None: super().save_model(request, obj, form, change) # Only emit content changes if Versioning is not installed because @@ -150,9 +143,7 @@ def delete_model(self, request: HttpRequest, obj: Alias): sender=self.model, ) - def _get_alias_usage_link( - self, obj: Alias, request: HttpRequest, disabled: bool = False - ) -> str: + def _get_alias_usage_link(self, obj: Alias, request: HttpRequest, disabled: bool = False) -> str: url = admin_reverse(USAGE_ALIAS_URL_NAME, args=[obj.pk]) return self.admin_action_button(url, "info", _("View usage"), disabled=disabled) @@ -172,9 +163,7 @@ class AliasContentAdmin(admin.ModelAdmin): actions = None change_form_template = "admin/djangocms_alias/aliascontent/change_form.html" - def changelist_view( - self, request: HttpRequest, extra_context: dict = None - ) -> HttpResponse: + def changelist_view(self, request: HttpRequest, extra_context: dict = None) -> HttpResponse: """Needed for the Alias Content Admin breadcrumbs""" return HttpResponseRedirect( admin_reverse( @@ -194,8 +183,7 @@ def change_view( if not obj: raise Http404() return HttpResponseRedirect( - admin_reverse(CHANGE_ALIAS_URL_NAME, args=(obj.alias_id,)) - + f"?language={obj.language}" + admin_reverse(CHANGE_ALIAS_URL_NAME, args=(obj.alias_id,)) + f"?language={obj.language}" ) def has_module_permission(self, request: HttpRequest) -> bool: diff --git a/djangocms_alias/cms_config.py b/djangocms_alias/cms_config.py index 463b4d3..027278d 100644 --- a/djangocms_alias/cms_config.py +++ b/djangocms_alias/cms_config.py @@ -1,12 +1,10 @@ +from cms.app_base import CMSAppConfig from django.apps import apps from django.conf import settings -from cms.app_base import CMSAppConfig - from .models import AliasContent, AliasPlugin, copy_alias_content from .rendering import render_alias_content - try: apps.get_app_config("djangocms_internalsearch") from .internal_search import AliasContentConfig @@ -21,17 +19,13 @@ class AliasCMSConfig(CMSAppConfig): cms_toolbar_enabled_models = [(AliasContent, render_alias_content)] moderated_models = [AliasContent] - djangocms_moderation_enabled = getattr( - settings, "MODERATING_ALIAS_MODELS_ENABLED", True - ) + djangocms_moderation_enabled = getattr(settings, "MODERATING_ALIAS_MODELS_ENABLED", True) djangocms_versioning_enabled = ( - getattr(settings, "VERSIONING_ALIAS_MODELS_ENABLED", True) - and djangocms_versioning_installed + getattr(settings, "VERSIONING_ALIAS_MODELS_ENABLED", True) and djangocms_versioning_installed ) if djangocms_versioning_enabled: from cms.utils.i18n import get_language_tuple - from djangocms_versioning.datastructures import VersionableItem versioning = [ @@ -45,9 +39,7 @@ class AliasCMSConfig(CMSAppConfig): ), ] - djangocms_references_enabled = getattr( - settings, "REFERENCES_ALIAS_MODELS_ENABLED", True - ) + djangocms_references_enabled = getattr(settings, "REFERENCES_ALIAS_MODELS_ENABLED", True) reference_fields = [ (AliasPlugin, "alias"), ] diff --git a/djangocms_alias/cms_menus.py b/djangocms_alias/cms_menus.py index bfad7a6..cb9bc32 100644 --- a/djangocms_alias/cms_menus.py +++ b/djangocms_alias/cms_menus.py @@ -9,9 +9,7 @@ class AliasDisableMenu(Modifier): """Disable menu rendering on alias pages""" def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): - if request.toolbar.app_name == PLUGIN_URL_NAME_PREFIX or isinstance( - request.toolbar.obj, AliasContent - ): + if request.toolbar.app_name == PLUGIN_URL_NAME_PREFIX or isinstance(request.toolbar.obj, AliasContent): return [] return nodes diff --git a/djangocms_alias/cms_plugins.py b/djangocms_alias/cms_plugins.py index 19afddf..4bc764a 100644 --- a/djangocms_alias/cms_plugins.py +++ b/djangocms_alias/cms_plugins.py @@ -1,10 +1,5 @@ from copy import copy -from django.utils.translation import ( - get_language_from_request, - gettext_lazy as _, -) - from cms.plugin_base import CMSPluginBase, PluginMenuItem from cms.plugin_pool import plugin_pool from cms.toolbar.utils import get_object_edit_url @@ -14,11 +9,17 @@ ) from cms.utils.plugins import copy_plugins_to_placeholder from cms.utils.urlutils import add_url_parameters, admin_reverse +from django.utils.translation import ( + get_language_from_request, +) +from django.utils.translation import ( + gettext_lazy as _, +) from .constants import CREATE_ALIAS_URL_NAME, DETACH_ALIAS_PLUGIN_URL_NAME from .forms import AliasPluginForm -from .models import Alias as AliasModel, AliasContent, AliasPlugin - +from .models import Alias as AliasModel +from .models import AliasContent, AliasPlugin __all__ = [ "Alias", @@ -32,10 +33,7 @@ class Alias(CMSPluginBase): form = AliasPluginForm def get_render_template(self, context, instance, placeholder): - if ( - isinstance(instance.placeholder.source, AliasContent) - and instance.is_recursive() - ): + if isinstance(instance.placeholder.source, AliasContent) and instance.is_recursive(): return "djangocms_alias/alias_recursive.html" return f"djangocms_alias/{instance.template}/alias.html" @@ -117,9 +115,7 @@ def can_create_alias(cls, user, plugins=None, replace=False): return True elif replace: target_placeholder = plugins[0].placeholder - if not target_placeholder.check_source(user) or not has_plugin_permission( - user, Alias.__name__, "add" - ): + if not target_placeholder.check_source(user) or not has_plugin_permission(user, Alias.__name__, "add"): return False return all( @@ -144,9 +140,7 @@ def can_detach(cls, user, target_placeholder, plugins): @classmethod def detach_alias_plugin(cls, plugin, language): - source_placeholder = plugin.alias.get_placeholder( - language, show_draft_content=True - ) # We're in edit mode + source_placeholder = plugin.alias.get_placeholder(language, show_draft_content=True) # We're in edit mode target_placeholder = plugin.placeholder # Deleting uses a copy of a plugin to preserve pk on existing diff --git a/djangocms_alias/cms_toolbars.py b/djangocms_alias/cms_toolbars.py index 773f320..dc8043b 100644 --- a/djangocms_alias/cms_toolbars.py +++ b/djangocms_alias/cms_toolbars.py @@ -1,15 +1,6 @@ import itertools from copy import copy -from django.urls import NoReverseMatch -from django.utils.encoding import force_str -from django.utils.http import urlencode -from django.utils.translation import ( - get_language_from_request, - gettext, - gettext_lazy as _, -) - from cms.cms_toolbars import ( ADMIN_MENU_IDENTIFIER, ADMINISTRATION_BREAK, @@ -27,6 +18,16 @@ ) from cms.utils.permissions import get_model_permission_codename from cms.utils.urlutils import add_url_parameters, admin_reverse +from django.urls import NoReverseMatch +from django.utils.encoding import force_str +from django.utils.http import urlencode +from django.utils.translation import ( + get_language_from_request, + gettext, +) +from django.utils.translation import ( + gettext_lazy as _, +) from .constants import ( DELETE_ALIAS_URL_NAME, @@ -36,7 +37,6 @@ from .models import Alias, AliasContent from .utils import is_versioning_enabled - __all__ = [ "AliasToolbar", ] @@ -71,11 +71,7 @@ def add_aliases_link_to_admin_menu(self): url = admin_reverse(LIST_ALIAS_URL_NAME) obj = self.toolbar.get_object() - language = ( - obj.language - if hasattr(obj, "language") - else get_language_from_request(self.request) - ) + language = obj.language if hasattr(obj, "language") else get_language_from_request(self.request) if language is None: language = get_default_language() url += f'?{urlencode({"language": language})}' @@ -152,9 +148,7 @@ def get_insert_position(cls, admin_menu, item_name): return end.index def enable_create_wizard_button(self): - button_lists = [ - result.item for result in self.toolbar.find_items(item_type=ButtonList) - ] + button_lists = [result.item for result in self.toolbar.find_items(item_type=ButtonList)] buttons = list( # flatten the list itertools.chain.from_iterable([item.buttons for item in button_lists]) @@ -162,9 +156,7 @@ def enable_create_wizard_button(self): # There will always be this button, because we are in the context of # alias app views - create_wizard_button = [ - button for button in buttons if button.name == gettext("Create") - ][0] + create_wizard_button = [button for button in buttons if button.name == gettext("Create")][0] from cms.wizards.wizard_pool import entry_choices @@ -216,17 +208,13 @@ def change_language_menu(self): current_placeholder = alias_content.placeholder remove = [ - (code, languages.get(code, code)) - for code in alias_content.alias.get_languages() - if code in languages + (code, languages.get(code, code)) for code in alias_content.alias.get_languages() if code in languages ] add = [code for code in languages.items() if code not in remove] copy = [ (code, name) for code, name in languages.items() - if code != self.current_lang - and (code, name) in remove - and current_placeholder + if code != self.current_lang and (code, name) in remove and current_placeholder ] if add or remove or copy: @@ -240,9 +228,7 @@ def change_language_menu(self): add_url = admin_reverse("djangocms_alias_aliascontent_add") for code, name in add: - url = add_url_parameters( - add_url, language=code, alias=alias_content.alias_id - ) + url = add_url_parameters(add_url, language=code, alias=alias_content.alias_id) add_plugins_menu.add_modal_item(name, url=url) if remove: diff --git a/djangocms_alias/cms_wizards.py b/djangocms_alias/cms_wizards.py index 45573b6..bf75516 100644 --- a/djangocms_alias/cms_wizards.py +++ b/djangocms_alias/cms_wizards.py @@ -1,12 +1,12 @@ -from django.utils.translation import gettext_lazy as _ - from cms.utils.permissions import get_model_permission_codename from cms.wizards.wizard_base import Wizard from cms.wizards.wizard_pool import wizard_pool +from django.utils.translation import gettext_lazy as _ from .cms_plugins import Alias from .forms import CreateAliasWizardForm, CreateCategoryWizardForm -from .models import Alias as AliasModel, Category +from .models import Alias as AliasModel +from .models import Category class CreateAliasWizard(Wizard): diff --git a/djangocms_alias/compat.py b/djangocms_alias/compat.py index c4168af..96e705f 100644 --- a/djangocms_alias/compat.py +++ b/djangocms_alias/compat.py @@ -2,5 +2,4 @@ import django - DJANGO_GTE_21 = LooseVersion(django.get_version()) >= LooseVersion("2.1") diff --git a/djangocms_alias/filters.py b/djangocms_alias/filters.py index 9ed8da6..e16e925 100644 --- a/djangocms_alias/filters.py +++ b/djangocms_alias/filters.py @@ -1,8 +1,8 @@ +from cms.forms.utils import get_sites from django.contrib import admin from django.utils.encoding import smart_str -from django.utils.translation import get_language, gettext_lazy as _ - -from cms.forms.utils import get_sites +from django.utils.translation import get_language +from django.utils.translation import gettext_lazy as _ from .cms_config import AliasCMSConfig from .constants import ( @@ -12,7 +12,6 @@ ) from .models import Category - djangocms_versioning_enabled = AliasCMSConfig.djangocms_versioning_enabled @@ -39,17 +38,13 @@ def choices(self, changelist): } yield { "selected": self.value() == SITE_FILTER_NO_SITE_VALUE, - "query_string": changelist.get_query_string( - {self.parameter_name: SITE_FILTER_NO_SITE_VALUE} - ), + "query_string": changelist.get_query_string({self.parameter_name: SITE_FILTER_NO_SITE_VALUE}), "display": _("No site"), } for lookup, title in self.lookup_choices: yield { "selected": self.value() == str(lookup), - "query_string": changelist.get_query_string( - {self.parameter_name: lookup} - ), + "query_string": changelist.get_query_string({self.parameter_name: lookup}), "display": title, } @@ -63,11 +58,7 @@ def lookups(self, request, model_admin): qs = model_admin.get_queryset(request) cat_id = qs.values_list("category", flat=True) # Ensure the category is ordered by the name alphabetically by default - cat = ( - Category.objects.filter(pk__in=cat_id) - .translated(get_language()) - .order_by("translations__name") - ) + cat = Category.objects.filter(pk__in=cat_id).translated(get_language()).order_by("translations__name") for obj in cat: yield str(obj.pk), smart_str(obj) @@ -84,8 +75,6 @@ def choices(self, changelist): for lookup, title in self.lookup_choices: yield { "selected": self.value() == str(lookup), - "query_string": changelist.get_query_string( - {self.parameter_name: lookup} - ), + "query_string": changelist.get_query_string({self.parameter_name: lookup}), "display": title, } diff --git a/djangocms_alias/forms.py b/djangocms_alias/forms.py index b246e57..d128b49 100644 --- a/djangocms_alias/forms.py +++ b/djangocms_alias/forms.py @@ -1,3 +1,10 @@ +from cms.models import CMSPlugin, Placeholder +from cms.utils import get_current_site +from cms.utils.permissions import ( + get_model_permission_codename, + has_plugin_permission, +) +from cms.utils.urlutils import admin_reverse from django import forms from django.contrib import admin from django.contrib.admin.widgets import ( @@ -7,28 +14,20 @@ from django.contrib.sites.models import Site from django.db import transaction from django.utils.translation import gettext_lazy as _ - -from cms.models import CMSPlugin, Placeholder -from cms.utils import get_current_site -from cms.utils.permissions import ( - get_model_permission_codename, - has_plugin_permission, -) -from cms.utils.urlutils import admin_reverse - from parler.forms import TranslatableModelForm from .constants import CATEGORY_SELECT2_URL_NAME, SELECT2_ALIAS_URL_NAME from .models import ( Alias, - Alias as AliasModel, AliasContent, AliasPlugin, Category, ) +from .models import ( + Alias as AliasModel, +) from .utils import emit_content_change, is_versioning_enabled - __all__ = [ "AliasPluginForm", "BaseCreateAliasForm", @@ -76,9 +75,7 @@ def clean(self): placeholder = cleaned_data.get("placeholder") if not plugin and not placeholder: - raise forms.ValidationError( - _("A plugin or placeholder is required to create an alias.") - ) + raise forms.ValidationError(_("A plugin or placeholder is required to create an alias.")) if plugin and placeholder: raise forms.ValidationError( @@ -126,9 +123,7 @@ def clean(self): language=cleaned_data.get("language"), alias__category=cleaned_data.get("category"), ).exists(): - raise forms.ValidationError( - _("Alias with this Name and Category already exists.") - ) + raise forms.ValidationError(_("Alias with this Name and Category already exists.")) return cleaned_data @@ -174,9 +169,7 @@ def save(self): class CreateAliasWizardForm(forms.Form): - name = forms.CharField( - label=_("Name"), required=True, widget=AdminTextInputWidget() - ) + name = forms.CharField(label=_("Name"), required=True, widget=AdminTextInputWidget()) site = forms.ModelChoiceField( queryset=Site.objects.all(), required=False, @@ -273,9 +266,7 @@ class AliasPluginForm(forms.ModelForm): queryset=Category.objects.all(), widget=CategorySelectWidget( attrs={ - "data-placeholder": _( - "Select category to restrict the list of aliases below" - ), # noqa: E501 + "data-placeholder": _("Select category to restrict the list of aliases below"), # noqa: E501 }, ), empty_label="", @@ -331,8 +322,6 @@ def clean(self): language=cleaned_data.get("language"), alias__category=cleaned_data.get("category"), ).exists(): - raise forms.ValidationError( - _("Alias with this Name and Category already exists.") - ) + raise forms.ValidationError(_("Alias with this Name and Category already exists.")) return cleaned_data diff --git a/djangocms_alias/internal_search.py b/djangocms_alias/internal_search.py index 0a2e899..9fb516d 100644 --- a/djangocms_alias/internal_search.py +++ b/djangocms_alias/internal_search.py @@ -1,3 +1,4 @@ +from cms.toolbar.utils import get_toolbar_from_request from django.template import RequestContext from django.utils.translation import gettext_lazy as _ diff --git a/djangocms_alias/migrations/0001_initial.py b/djangocms_alias/migrations/0001_initial.py index a8b484d..1867163 100644 --- a/djangocms_alias/migrations/0001_initial.py +++ b/djangocms_alias/migrations/0001_initial.py @@ -1,12 +1,12 @@ # Generated by Django 2.1.1 on 2018-09-07 11:12 import cms.utils.i18n -from django.db import migrations, models -from django.conf import settings import django.db.models.deletion import parler.models +from django.conf import settings +from django.db import migrations, models -from djangocms_alias.models import get_templates, TEMPLATE_DEFAULT +from djangocms_alias.models import TEMPLATE_DEFAULT, get_templates class Migration(migrations.Migration): @@ -148,9 +148,7 @@ class Migration(migrations.Migration): ), ( "language_code", - models.CharField( - db_index=True, max_length=15, verbose_name="Language" - ), + models.CharField(db_index=True, max_length=15, verbose_name="Language"), ), ( "name", diff --git a/djangocms_alias/migrations/0002_auto_20200723_1424.py b/djangocms_alias/migrations/0002_auto_20200723_1424.py index dbc91d2..3e7865e 100644 --- a/djangocms_alias/migrations/0002_auto_20200723_1424.py +++ b/djangocms_alias/migrations/0002_auto_20200723_1424.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.13 on 2020-07-23 14:24 -from django.db import migrations, models import django.db.models.deletion import parler.fields +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/djangocms_alias/migrations/0003_auto_20230725_1547.py b/djangocms_alias/migrations/0003_auto_20230725_1547.py index 872e77d..156d655 100644 --- a/djangocms_alias/migrations/0003_auto_20230725_1547.py +++ b/djangocms_alias/migrations/0003_auto_20230725_1547.py @@ -1,7 +1,7 @@ # Generated by Django 4.1.8 on 2023-07-25 15:47 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/djangocms_alias/migrations/0004_alter_aliascontent_language.py b/djangocms_alias/migrations/0004_alter_aliascontent_language.py index 0fdd5bf..a8ef3da 100644 --- a/djangocms_alias/migrations/0004_alter_aliascontent_language.py +++ b/djangocms_alias/migrations/0004_alter_aliascontent_language.py @@ -1,7 +1,7 @@ # Generated by Django 3.2.20 on 2023-07-26 13:43 -from django.db import migrations, models import django.utils.translation +from django.db import migrations, models class Migration(migrations.Migration): @@ -13,8 +13,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="aliascontent", name="language", - field=models.CharField( - default=django.utils.translation.get_language, max_length=10 - ), + field=models.CharField(default=django.utils.translation.get_language, max_length=10), ), ] diff --git a/djangocms_alias/models.py b/djangocms_alias/models.py index db87ce0..4e0b397 100644 --- a/djangocms_alias/models.py +++ b/djangocms_alias/models.py @@ -1,27 +1,25 @@ import operator from collections import defaultdict -from django.conf import settings -from django.contrib.sites.models import Site -from django.db import models, transaction -from django.db.models import F, Q -from django.utils.encoding import force_str -from django.utils.functional import cached_property -from django.utils.translation import get_language, gettext_lazy as _ - from cms.api import add_plugin from cms.models import CMSPlugin, Placeholder from cms.models.fields import PlaceholderRelationField from cms.models.managers import WithUserMixin from cms.utils.plugins import copy_plugins_to_placeholder from cms.utils.urlutils import admin_reverse - +from django.conf import settings +from django.contrib.sites.models import Site +from django.db import models, transaction +from django.db.models import F, Q +from django.utils.encoding import force_str +from django.utils.functional import cached_property +from django.utils.translation import get_language +from django.utils.translation import gettext_lazy as _ from parler.models import TranslatableModel, TranslatedFields from .constants import CHANGE_CATEGORY_URL_NAME from .utils import is_versioning_enabled - __all__ = [ "Category", "Alias", @@ -105,9 +103,7 @@ class Meta: verbose_name = _("alias") verbose_name_plural = _("aliases") ordering = ["position"] - unique_together = ( - ("static_code", "site"), - ) # Only restrict instances that have a site specified + unique_together = (("static_code", "site"),) # Only restrict instances that have a site specified def __init__(self, *args, **kwargs): self._plugins_cache = {} @@ -131,9 +127,7 @@ def is_in_use(self): def objects_using(self): objects = set() object_ids = defaultdict(set) - plugins = self.cms_plugins.select_related("placeholder").prefetch_related( - "placeholder__source" - ) + plugins = self.cms_plugins.select_related("placeholder").prefetch_related("placeholder__source") for plugin in plugins: obj = plugin.placeholder.source obj_class_name = obj.__class__.__name__ @@ -148,11 +142,7 @@ def objects_using(self): else: objects.update([obj]) objects.update( - [ - obj - for model_class, ids in object_ids.items() - for obj in model_class.objects.filter(pk__in=ids) - ] + [obj for model_class, ids in object_ids.items() for obj in model_class.objects.filter(pk__in=ids)] ) return list(objects) @@ -192,9 +182,7 @@ def get_content(self, language=None, show_draft_content=False): return self._content_cache[language] def get_placeholder(self, language=None, show_draft_content=False): - content = self.get_content( - language=language, show_draft_content=show_draft_content - ) + content = self.get_content(language=language, show_draft_content=show_draft_content) return getattr(content, "placeholder", None) def get_plugins(self, language=None): @@ -414,7 +402,5 @@ def is_recursive(self, language=None): plugins = AliasPlugin.objects.filter( placeholder_id=placeholder, ) - plugins = plugins.filter( - Q(pk=self) | Q(alias__contents__placeholders=placeholder) - ) + plugins = plugins.filter(Q(pk=self) | Q(alias__contents__placeholders=placeholder)) return plugins.exists() diff --git a/djangocms_alias/templatetags/djangocms_alias_tags.py b/djangocms_alias/templatetags/djangocms_alias_tags.py index 6818968..27fd754 100644 --- a/djangocms_alias/templatetags/djangocms_alias_tags.py +++ b/djangocms_alias/templatetags/djangocms_alias_tags.py @@ -1,8 +1,7 @@ from collections import ChainMap -from django import template -from django.utils.translation import get_language - +from classytags.arguments import Argument, MultiValueArgument +from classytags.core import Tag from cms.templatetags.cms_tags import PlaceholderOptions from cms.toolbar.utils import get_object_preview_url, get_toolbar_from_request from cms.utils import get_current_site, get_language_from_request @@ -10,9 +9,8 @@ from cms.utils.i18n import get_default_language, get_language_list from cms.utils.placeholder import validate_placeholder_name from cms.utils.urlutils import add_url_parameters, admin_reverse - -from classytags.arguments import Argument, MultiValueArgument -from classytags.core import Tag +from django import template +from django.utils.translation import get_language from ..constants import ( DEFAULT_STATIC_ALIAS_CATEGORY_NAME, @@ -21,7 +19,6 @@ from ..models import Alias, AliasContent, Category from ..utils import is_versioning_enabled - register = template.Library() @@ -127,13 +124,9 @@ def _get_alias(self, request, static_code, extra_bits): return None # Parler's get_or_create doesn't work well with translations, so we must perform our own get or create - default_category = Category.objects.filter( - translations__name=DEFAULT_STATIC_ALIAS_CATEGORY_NAME - ).first() + default_category = Category.objects.filter(translations__name=DEFAULT_STATIC_ALIAS_CATEGORY_NAME).first() if not default_category: - default_category = Category.objects.create( - name=DEFAULT_STATIC_ALIAS_CATEGORY_NAME - ) + default_category = Category.objects.create(name=DEFAULT_STATIC_ALIAS_CATEGORY_NAME) alias_creation_kwargs = { "static_code": static_code, @@ -143,13 +136,9 @@ def _get_alias(self, request, static_code, extra_bits): if "site" in extra_bits: alias_creation_kwargs["site"] = current_site - alias = Alias.objects.create( - category=default_category, **alias_creation_kwargs - ) + alias = Alias.objects.create(category=default_category, **alias_creation_kwargs) - if not AliasContent._base_manager.filter( - alias=alias, language=language - ).exists(): + if not AliasContent._base_manager.filter(alias=alias, language=language).exists(): # Create a first content object if none exists in the given language. # If versioning is enabled we can only create the records with a logged-in user / staff member if is_versioning_enabled() and not request.user.is_authenticated: @@ -194,9 +183,7 @@ def render_tag(self, context, static_code, extra_bits, nodelist=None): get_draft_content = True language = get_language_from_request(request) - placeholder = alias.get_placeholder( - language=language, show_draft_content=get_draft_content - ) + placeholder = alias.get_placeholder(language=language, show_draft_content=get_draft_content) if placeholder: content = renderer.render_placeholder( diff --git a/djangocms_alias/test_utils/text/models.py b/djangocms_alias/test_utils/text/models.py index dedc922..86048a0 100644 --- a/djangocms_alias/test_utils/text/models.py +++ b/djangocms_alias/test_utils/text/models.py @@ -1,6 +1,5 @@ -from django.db import models - from cms.models import CMSPlugin +from django.db import models class Text(CMSPlugin): diff --git a/djangocms_alias/urls.py b/djangocms_alias/urls.py index 28c5d6d..9fb1058 100644 --- a/djangocms_alias/urls.py +++ b/djangocms_alias/urls.py @@ -1,6 +1,5 @@ from django.urls import path - from . import constants, views # isort:skip diff --git a/djangocms_alias/views.py b/djangocms_alias/views.py index 0928ade..068ac76 100644 --- a/djangocms_alias/views.py +++ b/djangocms_alias/views.py @@ -1,5 +1,7 @@ import json +from cms.models import Page +from cms.toolbar.utils import get_plugin_toolbar_info, get_plugin_tree_as_json from django.contrib import admin from django.core.exceptions import PermissionDenied from django.db.models import Q @@ -9,19 +11,18 @@ from django.utils.translation import ( get_language, get_language_from_request, +) +from django.utils.translation import ( gettext_lazy as _, ) from django.views.generic import ListView -from cms.models import Page -from cms.toolbar.utils import get_plugin_toolbar_info, get_plugin_tree_as_json - from .cms_plugins import Alias from .forms import BaseCreateAliasForm, CreateAliasForm -from .models import Alias as AliasModel, AliasPlugin, Category +from .models import Alias as AliasModel +from .models import AliasPlugin, Category from .utils import emit_content_change - JAVASCRIPT_SUCCESS_RESPONSE = """
@@ -144,9 +145,7 @@ def create_alias_view(request): return HttpResponse(JAVASCRIPT_SUCCESS_RESPONSE) -def render_replace_response( - request, new_plugins, source_placeholder=None, source_plugin=None -): +def render_replace_response(request, new_plugins, source_placeholder=None, source_plugin=None): move_plugins, add_plugins = [], [] for plugin in new_plugins: root = plugin.parent.get_bound_plugin() if plugin.parent else plugin diff --git a/package-lock.json b/package-lock.json index 5a04b4c..f0c2013 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2592,13 +2592,14 @@ } }, "node_modules/es5-ext": { - "version": "0.10.61", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.61.tgz", - "integrity": "sha512-yFhIqQAzu2Ca2I4SE2Au3rxVfmohU9Y7wqGR+s7+H7krk26NXhIRAZDgqd6xqjCEFUomDEA3/Bo/7fKmIkW1kA==", + "version": "0.10.63", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.63.tgz", + "integrity": "sha512-hUCZd2Byj/mNKjfP9jXrdVZ62B8KuA/VoK7X8nUh5qT+AxDmcbvZz041oDVZdbIN1qW6XY9VDNwzkvKnZvK2TQ==", "hasInstallScript": true, "dependencies": { "es6-iterator": "^2.0.3", "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", "next-tick": "^1.1.0" }, "engines": { @@ -2841,6 +2842,25 @@ "node": ">=4" } }, + "node_modules/esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", + "dependencies": { + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esniff/node_modules/type": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", + "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" + }, "node_modules/espree": { "version": "3.5.4", "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", @@ -2927,6 +2947,15 @@ "node": ">=0.10.0" } }, + "node_modules/event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", + "dependencies": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "node_modules/events": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", @@ -10748,12 +10777,13 @@ } }, "es5-ext": { - "version": "0.10.61", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.61.tgz", - "integrity": "sha512-yFhIqQAzu2Ca2I4SE2Au3rxVfmohU9Y7wqGR+s7+H7krk26NXhIRAZDgqd6xqjCEFUomDEA3/Bo/7fKmIkW1kA==", + "version": "0.10.63", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.63.tgz", + "integrity": "sha512-hUCZd2Byj/mNKjfP9jXrdVZ62B8KuA/VoK7X8nUh5qT+AxDmcbvZz041oDVZdbIN1qW6XY9VDNwzkvKnZvK2TQ==", "requires": { "es6-iterator": "^2.0.3", "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", "next-tick": "^1.1.0" } }, @@ -10953,6 +10983,24 @@ "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", "dev": true }, + "esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", + "requires": { + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + }, + "dependencies": { + "type": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", + "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" + } + } + }, "espree": { "version": "3.5.4", "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", @@ -11015,6 +11063,15 @@ "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true }, + "event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", + "requires": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "events": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", diff --git a/pyproject.toml b/pyproject.toml index a10167b..63c8c96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ +[tool.ruff] +line-length = 119 + [tool.ruff.lint] select=[ "E", # pycodestyle errors @@ -10,14 +13,15 @@ select=[ "PLR", # pylint refactor "PLW", # pylint warning "UP", # pyupgrade + ] extend-ignore = [ - "PLR0915", - "C901", - "PLR0913", - "PLW1510", - "I001" , - "PLR0912" , - "E501" + "C901", # Too complex + "PLR0911", # Too many return statements + "PLR0912", # Too many branches + "PLR0913", # Too many arguments to function call + "PLR0915", # Too many statements + # TODO + "PLW1510" # subprocess.run without explicit argument ] diff --git a/setup.py b/setup.py index a545cae..5fcc3e1 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ import djangocms_alias - CLASSIFIERS = [ "Environment :: Web Environment", "Framework :: Django", diff --git a/test_settings.py b/test_settings.py index a3facd1..9edd3d2 100644 --- a/test_settings.py +++ b/test_settings.py @@ -1,7 +1,6 @@ import os from distutils.util import strtobool - BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ENABLE_VERSIONING = strtobool(os.environ.get("ENABLE_VERSIONING", "1")) EXTRA_INSTALLED_APPS = [] diff --git a/tests/base.py b/tests/base.py index 3bfe1aa..dfd53dc 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1,8 +1,3 @@ -from django.contrib.auth import get_permission_codename -from django.contrib.auth.models import Permission -from django.http import QueryDict -from django.test.client import RequestFactory - from cms.api import add_plugin, create_page, create_page_content from cms.middleware.toolbar import ToolbarMiddleware from cms.test_utils.testcases import CMSTestCase @@ -13,6 +8,10 @@ ) from cms.utils.conf import get_cms_setting from cms.utils.urlutils import admin_reverse +from django.contrib.auth import get_permission_codename +from django.contrib.auth.models import Permission +from django.http import QueryDict +from django.test.client import RequestFactory from djangocms_alias.constants import ( CATEGORY_LIST_URL_NAME, @@ -21,7 +20,8 @@ DETACH_ALIAS_PLUGIN_URL_NAME, LIST_ALIAS_URL_NAME, ) -from djangocms_alias.models import Alias as AliasModel, AliasContent, Category +from djangocms_alias.models import Alias as AliasModel +from djangocms_alias.models import AliasContent, Category from djangocms_alias.utils import is_versioning_enabled @@ -63,9 +63,7 @@ def setUp(self): self.category = Category.objects.create(name="test category") def _get_draft_page_placeholder(self): - page_content = create_page_content( - self.language, "Draft Page", self.page, created_by=self.superuser - ) + page_content = create_page_content(self.language, "Draft Page", self.page, created_by=self.superuser) return page_content.get_placeholders().get(slot="content") def _create_alias( @@ -100,9 +98,7 @@ def _create_alias( if is_versioning_enabled(): from djangocms_versioning.models import Version - version = Version.objects.create( - content=alias_content, created_by=self.superuser - ) + version = Version.objects.create(content=alias_content, created_by=self.superuser) if published: version.publish(self.superuser) @@ -115,14 +111,9 @@ def _get_version(self, grouper, version_state, language=None): from djangocms_versioning.models import Version - versions = Version.objects.filter_by_grouper(grouper).filter( - state=version_state - ) + versions = Version.objects.filter_by_grouper(grouper).filter(state=version_state) for version in versions: - if ( - hasattr(version.content, "language") - and version.content.language == language - ): + if hasattr(version.content, "language") and version.content.language == language: return version def _publish(self, grouper, language=None): @@ -161,9 +152,7 @@ def _create_page(self, title, language=None, site=None, published=True, **kwargs def get_alias_request(self, alias, lang_code="en", *args, **kwargs): request = self._get_instance_request(alias, *args, **kwargs) request.current_page = None - request = self._process_request_by_toolbar_middleware( - request, obj=alias.get_content(lang_code) - ) + request = self._process_request_by_toolbar_middleware(request, obj=alias.get_content(lang_code)) return request def get_page_request(self, page, obj=None, *args, **kwargs): @@ -239,23 +228,11 @@ def add_alias_plugin_to_page(self, page, alias, language=None): def get_staff_user_with_alias_permissions(self): staff_user = self._create_user("alias staff", is_staff=True, is_superuser=False) # noqa: E501 - self.add_permission( - staff_user, get_permission_codename("add", AliasModel._meta) - ) # noqa: E501 - self.add_permission( - staff_user, get_permission_codename("change", AliasModel._meta) - ) # noqa: E501 - self.add_permission( - staff_user, get_permission_codename("delete", AliasModel._meta) - ) # noqa: E501 - self.add_permission( - staff_user, get_permission_codename("add", AliasContent._meta) - ) # noqa: E501 - self.add_permission( - staff_user, get_permission_codename("change", AliasContent._meta) - ) # noqa: E501 - self.add_permission( - staff_user, get_permission_codename("delete", AliasContent._meta) - ) # noqa: E501 + self.add_permission(staff_user, get_permission_codename("add", AliasModel._meta)) # noqa: E501 + self.add_permission(staff_user, get_permission_codename("change", AliasModel._meta)) # noqa: E501 + self.add_permission(staff_user, get_permission_codename("delete", AliasModel._meta)) # noqa: E501 + self.add_permission(staff_user, get_permission_codename("add", AliasContent._meta)) # noqa: E501 + self.add_permission(staff_user, get_permission_codename("change", AliasContent._meta)) # noqa: E501 + self.add_permission(staff_user, get_permission_codename("delete", AliasContent._meta)) # noqa: E501 self.add_permission(staff_user, get_permission_codename("add", Category._meta)) # noqa: E501 return staff_user diff --git a/tests/requirements/compile.py b/tests/requirements/compile.py index e334076..7fd78bc 100755 --- a/tests/requirements/compile.py +++ b/tests/requirements/compile.py @@ -6,7 +6,6 @@ import sys from pathlib import Path - COMPILE_SETTINGS = { "py39-dj32-cms41": [], "py310-dj32-cms41": [], diff --git a/tests/test_admin.py b/tests/test_admin.py index 77b7b59..8908e88 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -1,5 +1,9 @@ from unittest import skipUnless +from bs4 import BeautifulSoup +from cms.api import add_plugin +from cms.utils.i18n import force_language +from cms.utils.urlutils import add_url_parameters, admin_reverse from django.contrib.auth.models import Permission from django.urls import reverse from django.utils.formats import localize @@ -18,10 +22,12 @@ ) from djangocms_alias.models import ( Alias, - Alias as AliasModel, AliasContent, Category, ) +from djangocms_alias.models import ( + Alias as AliasModel, +) from djangocms_alias.utils import is_versioning_enabled from tests.base import BaseAliasPluginTestCase @@ -67,14 +73,9 @@ def test_alias_content_manager_rendering_without_versioning_actions(self): response_content_decoded, ) - usage_url = admin_reverse( - USAGE_ALIAS_URL_NAME, args=[expected_en_content.alias.pk] - ) + usage_url = admin_reverse(USAGE_ALIAS_URL_NAME, args=[expected_en_content.alias.pk]) change_category_and_site_url = admin_reverse( - "{}_{}_change".format( - expected_en_content._meta.app_label, - expected_en_content.alias._meta.model_name, - ), + f"{expected_en_content._meta.app_label}_{expected_en_content.alias._meta.model_name}_change", args=(expected_en_content.alias.pk,), ) @@ -88,10 +89,7 @@ def test_alias_content_manager_rendering_without_versioning_actions(self): ) # check for add content admin link add_alias_link = admin_reverse( - "{}_{}_add".format( - expected_en_content._meta.app_label, - expected_en_content._meta.model_name, - ) + f"{expected_en_content._meta.app_label}_{expected_en_content._meta.model_name}_add" ) self.assertNotIn( # It is not currently possible to add an alias from the django admin changelist issue #97 @@ -175,14 +173,9 @@ def test_alias_changelist_rendering_with_versioning_actions(self): response_content_decoded, ) - usage_url = admin_reverse( - USAGE_ALIAS_URL_NAME, args=[expected_en_content.alias.pk] - ) + usage_url = admin_reverse(USAGE_ALIAS_URL_NAME, args=[expected_en_content.alias.pk]) settings_url = admin_reverse( - "{}_{}_change".format( - expected_en_content._meta.app_label, - expected_en_content.alias._meta.model_name, - ), + f"{expected_en_content._meta.app_label}_{expected_en_content.alias._meta.model_name}_change", args=(expected_en_content.alias.pk,), ) @@ -231,10 +224,7 @@ def test_alias_content_manager_rendering_preview_add_url(self): ) # check for add content admin link add_aliascontent_url = admin_reverse( - "{}_{}_add".format( - expected_en_content._meta.app_label, - expected_en_content._meta.model_name, - ) + f"{expected_en_content._meta.app_label}_{expected_en_content._meta.model_name}_add" ) self.assertNotIn( add_aliascontent_url, @@ -246,9 +236,7 @@ def _create_alias_and_categories(self, category_name, alias_content_name=None): alias_content_name = category_name category = Category.objects.create(name=category_name) alias = AliasModel.objects.create(category=category, position=0) - alias_content = AliasContent.objects.create( - alias=alias, name=alias_content_name, language="en" - ) + alias_content = AliasContent.objects.create(alias=alias, name=alias_content_name, language="en") return category, alias, alias_content @skipUnless(is_versioning_enabled(), "Test only relevant for versioning") @@ -288,13 +276,9 @@ def test_category_field_ordering_versioned(self): from djangocms_versioning.models import Version Version.objects.create(content=first_alias_content, created_by=self.superuser) - Version.objects.create( - content=first_alias_content_lower, created_by=self.superuser - ) + Version.objects.create(content=first_alias_content_lower, created_by=self.superuser) Version.objects.create(content=middle_alias_content, created_by=self.superuser) - Version.objects.create( - content=last_alias_content_lower, created_by=self.superuser - ) + Version.objects.create(content=last_alias_content_lower, created_by=self.superuser) Version.objects.create(content=last_alias_content, created_by=self.superuser) with self.login_user_context(self.superuser): @@ -467,15 +451,9 @@ def test_aliascontent_list_view(self): alias1_content = alias1.get_content(language=self.language) alias2_content = alias2.get_content(language=self.language) alias3_content = alias3.get_content(language=self.language) - aliascontent1_url = admin_reverse( - CHANGE_ALIAS_URL_NAME, args=[alias1_content.pk] - ) - aliascontent2_url = admin_reverse( - CHANGE_ALIAS_URL_NAME, args=[alias2_content.pk] - ) - aliascontent3_url = admin_reverse( - CHANGE_ALIAS_URL_NAME, args=[alias3_content.pk] - ) + aliascontent1_url = admin_reverse(CHANGE_ALIAS_URL_NAME, args=[alias1_content.pk]) + aliascontent2_url = admin_reverse(CHANGE_ALIAS_URL_NAME, args=[alias2_content.pk]) + aliascontent3_url = admin_reverse(CHANGE_ALIAS_URL_NAME, args=[alias3_content.pk]) self.assertContains(response, aliascontent1_url) self.assertContains(response, aliascontent2_url) @@ -544,9 +522,7 @@ def test_changelist_staff_user_without_permission(self): def test_changelist_staff_user_with_permission(self): user = self.get_staff_user_with_std_permissions() user.user_permissions.add( - Permission.objects.get( - content_type__app_label="djangocms_alias", codename="change_category" - ) + Permission.objects.get(content_type__app_label="djangocms_alias", codename="change_category") ) with self.login_user_context(user): response = self.client.get(self.get_category_list_endpoint()) @@ -556,9 +532,7 @@ def test_changelist_edit_button(self): with self.login_user_context(self.superuser): response = self.client.get(self.get_category_list_endpoint()) - self.assertContains( - response, '' "Alias contents" + ) expected_content = 'Aliases' self.assertEqual(response.status_code, 200) diff --git a/tests/test_admin_filters.py b/tests/test_admin_filters.py index fb9deaf..6934b14 100644 --- a/tests/test_admin_filters.py +++ b/tests/test_admin_filters.py @@ -1,16 +1,16 @@ from unittest import skipUnless +from cms.utils import get_current_site from django.contrib import admin from django.contrib.sites.models import Site -from cms.utils import get_current_site - from djangocms_alias.constants import ( SITE_FILTER_NO_SITE_VALUE, SITE_FILTER_URL_PARAM, ) from djangocms_alias.filters import CategoryFilter -from djangocms_alias.models import Alias as AliasModel, AliasContent, Category +from djangocms_alias.models import Alias as AliasModel +from djangocms_alias.models import AliasContent, Category from djangocms_alias.utils import is_versioning_enabled from .base import BaseAliasPluginTestCase @@ -57,15 +57,9 @@ def test_site_filter(self): if is_versioning_enabled(): from djangocms_versioning.models import Version - Version.objects.create( - content=current_site_alias_content, created_by=self.superuser - ) - Version.objects.create( - content=another_site_alias_content, created_by=self.superuser - ) - Version.objects.create( - content=no_site_alias_content, created_by=self.superuser - ) + Version.objects.create(content=current_site_alias_content, created_by=self.superuser) + Version.objects.create(content=another_site_alias_content, created_by=self.superuser) + Version.objects.create(content=no_site_alias_content, created_by=self.superuser) base_url = self.get_admin_url(AliasModel, "changelist") @@ -73,21 +67,13 @@ def test_site_filter(self): # en is the default language configured for the site response_default = self.client.get(base_url) # filter by aliases with the current site - response_current_site = self.client.get( - f"{base_url}?{SITE_FILTER_URL_PARAM}={current_site.pk}" - ) + response_current_site = self.client.get(f"{base_url}?{SITE_FILTER_URL_PARAM}={current_site.pk}") # filter by aliases with a different site set - response_other_site = self.client.get( - f"{base_url}?{SITE_FILTER_URL_PARAM}={another_site.pk}" - ) + response_other_site = self.client.get(f"{base_url}?{SITE_FILTER_URL_PARAM}={another_site.pk}") # filter by aliases with an empty site set - response_empty_site = self.client.get( - f"{base_url}?{SITE_FILTER_URL_PARAM}={empty_site.pk}" - ) + response_empty_site = self.client.get(f"{base_url}?{SITE_FILTER_URL_PARAM}={empty_site.pk}") # filter by aliases with no site set - response_no_site = self.client.get( - f"{base_url}?{SITE_FILTER_URL_PARAM}={SITE_FILTER_NO_SITE_VALUE}" - ) + response_no_site = self.client.get(f"{base_url}?{SITE_FILTER_URL_PARAM}={SITE_FILTER_NO_SITE_VALUE}") # By default, all alias are shown self.assertEqual( @@ -99,13 +85,9 @@ def test_site_filter(self): }, ) # Only alias attached to the current site are shown when filtered by the current site - self.assertEqual( - set(response_current_site.context["cl"].queryset), {current_site_alias} - ) + self.assertEqual(set(response_current_site.context["cl"].queryset), {current_site_alias}) # Only alias attached to the current site are shown when filtered by another site - self.assertEqual( - set(response_other_site.context["cl"].queryset), {another_site_alias} - ) + self.assertEqual(set(response_other_site.context["cl"].queryset), {another_site_alias}) # Only alias attached to the current site are shown when filtered by no site self.assertEqual(set(response_no_site.context["cl"].queryset), {no_site_alias}) # No are shown when filtered by an empty site @@ -144,13 +126,9 @@ def test_category_filter_no_verisoning(self): with self.login_user_context(self.superuser): response_default = self.client.get(base_url) # category one should have a result - category_one_filter_response = self.client.get( - f"{base_url}?category={category_one.id}" - ) + category_one_filter_response = self.client.get(f"{base_url}?category={category_one.id}") # category two should have a result - category_two_filter_response = self.client.get( - f"{base_url}?category={category_two.id}" - ) + category_two_filter_response = self.client.get(f"{base_url}?category={category_two.id}") # By default all alias contents are shown self.assertEqual( @@ -189,9 +167,7 @@ def test_category_filter_with_verisoning(self): name="EN Alias Content one", language="en", ) - Version.objects.create( - content=expected_category_one_content, created_by=self.superuser - ) + Version.objects.create(content=expected_category_one_content, created_by=self.superuser) category_two = Category.objects.create(name="two") alias_two = AliasModel.objects.create( category=category_two, @@ -202,21 +178,15 @@ def test_category_filter_with_verisoning(self): name="EN Alias Content two", language="en", ) - Version.objects.create( - content=expected_category_two_content, created_by=self.superuser - ) + Version.objects.create(content=expected_category_two_content, created_by=self.superuser) base_url = self.get_admin_url(AliasModel, "changelist") with self.login_user_context(self.superuser): response_default = self.client.get(base_url) # category one should have a result - category_one_filter_response = self.client.get( - f"{base_url}?category={category_one.id}" - ) + category_one_filter_response = self.client.get(f"{base_url}?category={category_one.id}") # categopry two should have a result - category_two_filter_response = self.client.get( - f"{base_url}?category={category_two.id}" - ) + category_two_filter_response = self.client.get(f"{base_url}?category={category_two.id}") # By default, all alias contents are shown self.assertEqual( @@ -227,13 +197,9 @@ def test_category_filter_with_verisoning(self): }, ) # show alias contents filter by category one - self.assertEqual( - set(category_one_filter_response.context["cl"].queryset), {alias_one} - ) + self.assertEqual(set(category_one_filter_response.context["cl"].queryset), {alias_one}) # show alias contents filter by category two - self.assertEqual( - set(category_two_filter_response.context["cl"].queryset), {alias_two} - ) + self.assertEqual(set(category_two_filter_response.context["cl"].queryset), {alias_two}) def test_category_filter_lookups_ordered_alphabetical(self): """ @@ -261,9 +227,7 @@ def test_category_filter_lookups_ordered_alphabetical(self): ) version_admin = admin.site._registry[AliasModel] - category_filter = CategoryFilter( - None, {"category": [""]}, AliasModel, version_admin - ) + category_filter = CategoryFilter(None, {"category": [""]}, AliasModel, version_admin) # Get the first choice in the filter lookup object first_lookup_value = category_filter.lookup_choices[0][1] # Lookup value should match the category name linked to alias content @@ -292,9 +256,7 @@ def test_category_filter_lookup_should_only_show_aliases_linked_to_content(self) category_two = Category.objects.create(name="a - category") version_admin = admin.site._registry[AliasModel] - category_filter = CategoryFilter( - None, {"category": [""]}, AliasModel, version_admin - ) + category_filter = CategoryFilter(None, {"category": [""]}, AliasModel, version_admin) # Get the first choice in the filter lookup object first_lookup_value = category_filter.lookup_choices[0][1] diff --git a/tests/test_cms_plugins.py b/tests/test_cms_plugins.py index ceb65c9..9ce4e37 100644 --- a/tests/test_cms_plugins.py +++ b/tests/test_cms_plugins.py @@ -37,18 +37,14 @@ def test_extra_plugin_items_for_alias_plugins(self): page_content = None if is_versioning_enabled(): # Can only edit page/content that is in DRAFT - page_content = create_title( - self.language, "Draft Page", self.page, created_by=self.superuser - ) + page_content = create_title(self.language, "Draft Page", self.page, created_by=self.superuser) placeholder = page_content.get_placeholders().get(slot="content") alias_plugin = alias.get_content(self.language).populate( replaced_placeholder=placeholder, ) extra_items = Alias.get_extra_plugin_menu_items( - self.get_page_request( - page=self.page, obj=page_content, user=self.superuser - ), + self.get_page_request(page=self.page, obj=page_content, user=self.superuser), alias_plugin, ) @@ -261,10 +257,7 @@ def test_create_alias_from_plugin_list(self): ) self.assertEqual( plugins[0].get_bound_plugin().body, - alias.get_placeholder(self.language) - .get_plugins()[0] - .get_bound_plugin() - .body, + alias.get_placeholder(self.language).get_plugins()[0].get_bound_plugin().body, ) def test_replace_plugin_with_alias(self): @@ -279,9 +272,7 @@ def test_replace_plugin_with_alias(self): plugins, ) self.assertEqual(plugins[0].get_bound_plugin(), alias_plugin) - self.assertEqual( - alias_content.placeholder.get_plugins()[0].get_bound_plugin().body, "test" - ) # noqa: E501 + self.assertEqual(alias_content.placeholder.get_plugins()[0].get_bound_plugin().body, "test") # noqa: E501 def test_replace_plugin_with_alias_correct_position(self): second_plugin = add_plugin( @@ -297,9 +288,7 @@ def test_replace_plugin_with_alias_correct_position(self): body="test 3", ) alias = self._create_alias() - alias_plugin = alias.get_content(self.language).populate( - replaced_plugin=second_plugin - ) + alias_plugin = alias.get_content(self.language).populate(replaced_plugin=second_plugin) plugins = self.placeholder.get_plugins() self.assertNotIn( self.plugin, diff --git a/tests/test_models.py b/tests/test_models.py index 5efa588..d14c54d 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,20 +1,19 @@ from distutils.version import LooseVersion +from cms.api import add_plugin, create_title +from cms.models import Placeholder from django import get_version from django.contrib.sites.models import Site from django.core.exceptions import ValidationError from django.urls import reverse -from cms.api import add_plugin, create_title -from cms.models import Placeholder - from djangocms_alias.cms_plugins import Alias -from djangocms_alias.models import Alias as AliasModel, AliasContent, Category +from djangocms_alias.models import Alias as AliasModel +from djangocms_alias.models import AliasContent, Category from djangocms_alias.utils import is_versioning_enabled from .base import BaseAliasPluginTestCase - DJANGO_VERSION = get_version() DJANGO_4_0 = LooseVersion(DJANGO_VERSION) < LooseVersion("4.1") diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 423989e..14cf90e 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -1,8 +1,7 @@ +from cms.api import add_plugin from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType -from cms.api import add_plugin - from djangocms_alias.cms_plugins import Alias from djangocms_alias.models import Alias as AliasModel from djangocms_alias.utils import is_versioning_enabled diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 9876257..73f5248 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -1,23 +1,21 @@ from unittest import skipUnless -from django.contrib.sites.models import Site -from django.test.utils import override_settings - from cms.api import add_plugin, create_page, create_page_content from cms.toolbar.utils import get_object_edit_url, get_object_preview_url +from django.contrib.sites.models import Site +from django.test.utils import override_settings from djangocms_alias.cms_plugins import Alias from djangocms_alias.constants import DEFAULT_STATIC_ALIAS_CATEGORY_NAME -from djangocms_alias.models import Alias as AliasModel, Category +from djangocms_alias.models import Alias as AliasModel +from djangocms_alias.models import Category from djangocms_alias.utils import is_versioning_enabled from .base import BaseAliasPluginTestCase class AliasTemplateTagsTestCase(BaseAliasPluginTestCase): - alias_template = ( - """{% load djangocms_alias_tags %}{% render_alias plugin.alias %}""" # noqa: E501 - ) + alias_template = """{% load djangocms_alias_tags %}{% render_alias plugin.alias %}""" # noqa: E501 def test_render_alias(self): alias = self._create_alias() @@ -83,9 +81,7 @@ def test_render_alias_dont_render_draft_aliases(self): class AliasTemplateTagAliasPlaceholderTestCase(BaseAliasPluginTestCase): - alias_template = ( - """{% load djangocms_alias_tags %}{% static_alias "some_unique_id" %}""" # noqa: E501 - ) + alias_template = """{% load djangocms_alias_tags %}{% static_alias "some_unique_id" %}""" # noqa: E501 def test_no_alias_rendered_when_no_alias_exists(self): alias = self._create_alias(static_code="") @@ -141,9 +137,7 @@ def test_alias_auto_creation_in_template(self): alias_template = """{% load djangocms_alias_tags %}{% static_alias "category_unique_code" %}""" # noqa: E501 # No Alias or Category exist - category = Category.objects.filter( - translations__name=DEFAULT_STATIC_ALIAS_CATEGORY_NAME - ) + category = Category.objects.filter(translations__name=DEFAULT_STATIC_ALIAS_CATEGORY_NAME) alias = AliasModel.objects.filter(static_code="category_unique_code") self.assertEqual(category.count(), 0) @@ -174,9 +168,7 @@ def test_alias_auto_creation_in_template_site_limited_alias(self): When a template discovers a static code for a site and with no site with the same static_code entries are created for both scenarios """ - unlimited_template = ( - """{% load djangocms_alias_tags %}{% static_alias "limited_alias_code" %}""" # noqa: E501 - ) + unlimited_template = """{% load djangocms_alias_tags %}{% static_alias "limited_alias_code" %}""" # noqa: E501 site_limited_template = """{% load djangocms_alias_tags %}{% static_alias "limited_alias_code" site %}""" # noqa: E501 site_id = 1 @@ -242,24 +234,16 @@ def test_site_limited_alias_displays_the_correct_contents(self): # Should show the contents of the unlimited template with override_settings(SITE_ID=site1.pk): - site1_unlimited_preview = self.render_template_obj( - unlimited_template, {}, self.get_request("/") - ) - site1_limited_preview = self.render_template_obj( - site_limited_template, {}, self.get_request("/") - ) + site1_unlimited_preview = self.render_template_obj(unlimited_template, {}, self.get_request("/")) + site1_limited_preview = self.render_template_obj(site_limited_template, {}, self.get_request("/")) self.assertEqual(site1_unlimited_preview, "unlimited text") self.assertEqual(site1_limited_preview, "") # Should show the contents of the site limited template with override_settings(SITE_ID=site2.pk): - site2_unlimited_preview = self.render_template_obj( - unlimited_template, {}, self.get_request("/") - ) - site2_limited_preview = self.render_template_obj( - site_limited_template, {}, self.get_request("/") - ) + site2_unlimited_preview = self.render_template_obj(unlimited_template, {}, self.get_request("/")) + site2_limited_preview = self.render_template_obj(site_limited_template, {}, self.get_request("/")) self.assertEqual(site2_unlimited_preview, "unlimited text") self.assertEqual(site2_limited_preview, "site limited text") @@ -318,9 +302,7 @@ def test_static_alias_shows_correct_content_for_versioning_states(self): # The live page should still contain the published contents live_response = self.client.get(page_live_url) - self.assertContains( - live_response, "Published content for: template_example_global_alias_code" - ) + self.assertContains(live_response, "Published content for: template_example_global_alias_code") self.assertNotContains( live_response, "Updated Draft content for: template_example_global_alias_code", @@ -372,19 +354,11 @@ def page_edit_url(lang): return get_object_edit_url(page.get_content_obj(lang), language=lang) with self.login_user_context(self.superuser): - self.client.get( - page_edit_url("en"), follow=True - ) # supposed to create the alias and alias content for en - self.client.get( - page_edit_url("en"), follow=True - ) # supposed to create no additional object - self.client.get( - page_edit_url("de"), follow=True - ) # supposed to create the alias content for de - - alias = AliasModel.objects.filter( - static_code="template_example_global_alias_code" - ).first() + self.client.get(page_edit_url("en"), follow=True) # supposed to create the alias and alias content for en + self.client.get(page_edit_url("en"), follow=True) # supposed to create no additional object + self.client.get(page_edit_url("de"), follow=True) # supposed to create the alias content for de + + alias = AliasModel.objects.filter(static_code="template_example_global_alias_code").first() self.assertIsNotNone(alias, "Alias not created") self.assertIsNotNone(alias.get_content("en", show_draft_content=True)) @@ -393,9 +367,7 @@ def page_edit_url(lang): self.assertEqual(alias.contents(manager="admin_manager").count(), 2) def test_alias_rendered_when_identifier_is_variable(self): - alias_template = ( - """{% load djangocms_alias_tags %}{% static_alias foo_variable %}""" # noqa: E501 - ) + alias_template = """{% load djangocms_alias_tags %}{% static_alias foo_variable %}""" # noqa: E501 alias = self._create_alias(static_code="some_unique_id") add_plugin( diff --git a/tests/test_toolbar.py b/tests/test_toolbar.py index b0b1fdb..b46b087 100644 --- a/tests/test_toolbar.py +++ b/tests/test_toolbar.py @@ -2,9 +2,6 @@ from collections import ChainMap from unittest import skipUnless -from django.contrib.auth.models import Permission -from django.urls import reverse - from cms.cms_toolbars import ( ADMIN_MENU_IDENTIFIER, ADMINISTRATION_BREAK, @@ -14,6 +11,8 @@ from cms.toolbar.utils import get_object_edit_url from cms.utils.i18n import force_language from cms.utils.urlutils import admin_reverse +from django.contrib.auth.models import Permission +from django.urls import reverse from djangocms_alias.cms_toolbars import ALIAS_MENU_IDENTIFIER from djangocms_alias.constants import USAGE_ALIAS_URL_NAME @@ -25,9 +24,7 @@ class AliasToolbarTestCase(BaseAliasPluginTestCase): def _get_wizard_create_button(self, request): - button_lists = [ - result.item for result in request.toolbar.find_items(item_type=ButtonList) - ] + button_lists = [result.item for result in request.toolbar.find_items(item_type=ButtonList)] buttons = list( # flatten the list itertools.chain.from_iterable([item.buttons for item in button_lists]) @@ -44,9 +41,7 @@ def test_add_aliases_submenu_to_admin_menu_no_permission(self): def test_add_aliases_submenu_to_admin_menu(self): user = self.get_staff_user_with_std_permissions() user.user_permissions.add( - Permission.objects.get( - content_type__app_label="djangocms_alias", codename="change_category" - ) + Permission.objects.get(content_type__app_label="djangocms_alias", codename="change_category") ) try: page_url = get_object_edit_url(self.page.get_title_obj(self.language)) @@ -70,9 +65,7 @@ def test_add_alias_menu_showing_only_on_alias_plugin_views(self): self.get_list_alias_endpoint(), self.page.get_absolute_url(language=self.language), ]: - request = self.get_page_request( - page=None, path=endpoint, user=self.superuser - ) + request = self.get_page_request(page=None, path=endpoint, user=self.superuser) alias_menu = request.toolbar.get_menu(ALIAS_MENU_IDENTIFIER) self.assertEqual(alias_menu, None) @@ -126,8 +119,7 @@ def test_alias_toolbar_language_menu(self): self.assertEqual(language_menu.get_item_count(), 4) language_menu_dict = { - menu.name: [menu_item.name for menu_item in menu.items] - for key, menu in language_menu.menus.items() + menu.name: [menu_item.name for menu_item in menu.items] for key, menu in language_menu.menus.items() } self.assertIn("Add Translation", language_menu_dict.keys()) self.assertIn("Delete Translation", language_menu_dict.keys()) @@ -148,9 +140,7 @@ def test_alias_toolbar_language_menu(self): from djangocms_versioning.constants import PUBLISHED from djangocms_versioning.models import Version - Version.objects.create( - content=alias_content, created_by=self.superuser, state=PUBLISHED - ) + Version.objects.create(content=alias_content, created_by=self.superuser, state=PUBLISHED) request = self.get_alias_request( alias=alias, @@ -161,8 +151,7 @@ def test_alias_toolbar_language_menu(self): self.assertEqual(language_menu.get_item_count(), 6) language_menu_dict = { - menu.name: [menu_item.name for menu_item in menu.items] - for key, menu in language_menu.menus.items() + menu.name: [menu_item.name for menu_item in menu.items] for key, menu in language_menu.menus.items() } self.assertEqual( {"Deutsche...", "Italiano..."}, @@ -179,8 +168,7 @@ def test_alias_toolbar_language_menu(self): language_menu_first_items = { menu.name: next( filter( - lambda item: item.name - in ["Française...", "Deutsche...", "from Française"], + lambda item: item.name in ["Française...", "Deutsche...", "from Française"], menu.items, ) ) @@ -220,9 +208,7 @@ def test_language_switcher_when_toolbar_object_is_alias_content(self): from djangocms_versioning.constants import DRAFT from djangocms_versioning.models import Version - Version.objects.create( - content=alias_content, created_by=self.superuser, state=DRAFT - ) + Version.objects.create(content=alias_content, created_by=self.superuser, state=DRAFT) alias_content.populate(replaced_placeholder=self.placeholder) alias_content.alias.clear_cache() @@ -274,9 +260,7 @@ def test_page_toolbar_no_language_menu(self): break else: self.fail("No AliasToolbar in alias request") - language_menu = request.toolbar.get_menu( - LANGUAGE_MENU_IDENTIFIER, _("Language") - ) + language_menu = request.toolbar.get_menu(LANGUAGE_MENU_IDENTIFIER, _("Language")) self.assertIsNone(language_menu) def test_change_alias_settings_button_is_visible_on_alias_edit_view(self): @@ -449,8 +433,7 @@ def test_site_dropdown_url_renders_admin_changelist_url(self): admin_menu = request.toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER) site_aliases_url = admin_menu.items[3].url admin_changelist_aliases_url = ( - reverse(f"admin:{AliasContent._meta.app_label}_alias_changelist") - + "?language=en" + reverse(f"admin:{AliasContent._meta.app_label}_alias_changelist") + "?language=en" ) with self.login_user_context(self.superuser): diff --git a/tests/test_views.py b/tests/test_views.py index 0541a14..aa287c2 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,11 +1,6 @@ import re from unittest import skip, skipIf, skipUnless -from django.contrib.auth.models import Permission -from django.contrib.contenttypes.models import ContentType -from django.contrib.sites.models import Site -from django.test.utils import override_settings - from cms.api import add_plugin from cms.models import Placeholder from cms.toolbar.utils import get_object_edit_url, get_object_preview_url @@ -13,6 +8,10 @@ from cms.utils.i18n import force_language from cms.utils.plugins import downcast_plugins from cms.utils.urlutils import add_url_parameters, admin_reverse +from django.contrib.auth.models import Permission +from django.contrib.contenttypes.models import ContentType +from django.contrib.sites.models import Site +from django.test.utils import override_settings from djangocms_alias.constants import ( CATEGORY_SELECT2_URL_NAME, @@ -481,9 +480,7 @@ def test_view_aliases_using_site_filter(self): # when no filtering by site 1 only first object displayed with self.login_user_context(self.superuser): with force_language("en"): - site1_aliases_filter_url = ( - f"{alias_list_url}?site={site1_alias.site.id}" - ) + site1_aliases_filter_url = f"{alias_list_url}?site={site1_alias.site.id}" list_response = self.client.get(site1_aliases_filter_url) self.assertContains(list_response, site1_alias.name) @@ -492,9 +489,7 @@ def test_view_aliases_using_site_filter(self): # when no filtering by site 2 only first object displayed with self.login_user_context(self.superuser): with force_language("en"): - site2_aliases_filter_url = ( - f"{alias_list_url}?site={site2_alias.site.id}" - ) + site2_aliases_filter_url = f"{alias_list_url}?site={site2_alias.site.id}" list_response = self.client.get(site2_aliases_filter_url) self.assertNotContains(list_response, site1_alias.name) @@ -550,9 +545,7 @@ def test_select2_view(self): # This will show because it's a new draft version of the same alias draft_content = alias2.contents.create(name="foo", language=self.language) - Version.objects.create( - content=draft_content, created_by=self.superuser, state=DRAFT - ) + Version.objects.create(content=draft_content, created_by=self.superuser, state=DRAFT) # This shouldn't show because it hasn't content in current language self._create_alias(name="foo2", language="fr", position=1) @@ -896,10 +889,7 @@ def test_alias_usage_view(self): self.assertContains(response, "Alias") self.assertRegex( str(response.content), - r'href="{}"[\w+]?>{}<\/a>'.format( - re.escape(self.page.get_absolute_url(self.language)), - str(self.page), - ), + rf'href="{re.escape(self.page.get_absolute_url(self.language))}"[\w+]?>{str(self.page)}<\/a>', ) self.assertRegex( str(response.content), @@ -960,9 +950,7 @@ def test_delete_alias_view_get_using_objects(self): ), ) self.assertContains(response, "This alias is used by following objects:") - test = ( - r"
  • [\s\\n]*Page:[\s\\n]*test<\/a>[\s\\n]*<\/li>" - ) + test = r"
  • [\s\\n]*Page:[\s\\n]*test<\/a>[\s\\n]*<\/li>" self.assertRegex(str(response.content), test) def test_delete_alias_view_get_alias_not_used_on_any_page(self): @@ -988,9 +976,7 @@ def test_delete_alias_view_post(self): ), data={"post": "yes"}, ) - self.assertEqual( - response.status_code, 302 - ) # Successful delete returns a redirect + self.assertEqual(response.status_code, 302) # Successful delete returns a redirect self.assertFalse(Alias.objects.filter(pk=alias.pk).exists()) # Ensure it's gone def test_delete_alias_view_user_with_no_perms(self): @@ -1479,11 +1465,7 @@ def test_alias_not_shown_when_draft_when_visiting_page(self): is not visible """ unpublished_alias = self._create_alias(published=False) - content = ( - unpublished_alias.contents(manager="admin_manager") - .filter(language=self.language) - .first() - ) + content = unpublished_alias.contents(manager="admin_manager").filter(language=self.language).first() alias_placeholder = content.placeholder body = "unpublished alias" @@ -1538,13 +1520,9 @@ def test_view_multilanguage(self): if is_versioning_enabled(): from djangocms_versioning.models import Version - version_de = Version.objects.create( - content=alias_content_de, created_by=self.superuser - ) + version_de = Version.objects.create(content=alias_content_de, created_by=self.superuser) version_de.publish(user=self.superuser) - version_fr = Version.objects.create( - content=alias_content_fr, created_by=self.superuser - ) + version_fr = Version.objects.create(content=alias_content_fr, created_by=self.superuser) version_fr.publish(user=self.superuser) with self.login_user_context(self.superuser): diff --git a/tests/test_wizards.py b/tests/test_wizards.py index c4d22a5..a78e976 100644 --- a/tests/test_wizards.py +++ b/tests/test_wizards.py @@ -5,6 +5,8 @@ from cms.utils import get_current_site from cms.wizards.forms import WizardStep2BaseForm, step2_form_factory from cms.wizards.helpers import get_entries as get_wizard_entires +from django.contrib.sites.models import Site +from django.utils import translation from djangocms_alias.models import Category from djangocms_alias.utils import is_versioning_enabled @@ -14,11 +16,7 @@ class WizardsTestCase(BaseAliasPluginTestCase): def _get_wizard_instance(self, wizard_name): - return [ - wizard - for wizard in get_wizard_entires() - if wizard.__class__.__name__ == wizard_name - ][0] + return [wizard for wizard in get_wizard_entires() if wizard.__class__.__name__ == wizard_name][0] def _get_form_kwargs(self, data, language=None): language = language or self.language @@ -37,9 +35,7 @@ def test_create_alias_wizard_instance(self): self.assertTrue(wizard.user_has_add_permission(self.superuser)) self.assertTrue( - wizard.user_has_add_permission( - self.get_staff_user_with_alias_permissions() - ), # noqa: E501 + wizard.user_has_add_permission(self.get_staff_user_with_alias_permissions()), # noqa: E501 ) self.assertFalse( wizard.user_has_add_permission(self.get_staff_user_with_no_permissions()), # noqa: E501 @@ -116,9 +112,7 @@ def test_create_alias_category_wizard_instance(self): self.assertTrue(wizard.user_has_add_permission(self.superuser)) self.assertTrue( - wizard.user_has_add_permission( - self.get_staff_user_with_alias_permissions() - ), # noqa: E501 + wizard.user_has_add_permission(self.get_staff_user_with_alias_permissions()), # noqa: E501 ) self.assertFalse( wizard.user_has_add_permission(self.get_staff_user_with_no_permissions()), # noqa: E501