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 = """