Skip to content

Commit

Permalink
placeholderadmin.py: gettext only
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Apr 20, 2024
1 parent bdcb676 commit 72ae356
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions cms/admin/placeholderadmin.py
Expand Up @@ -21,7 +21,7 @@
from django.utils.decorators import method_decorator
from django.utils.encoding import force_str
from django.utils.html import conditional_escape
from django.utils.translation import get_language_from_path, gettext, gettext as _
from django.utils.translation import get_language_from_path, gettext as _
from django.views.decorators.clickjacking import xframe_options_sameorigin
from django.views.decorators.http import require_POST

Expand Down Expand Up @@ -117,13 +117,13 @@ def edit_field(self, request, object_id, language):
if not fields:
context = {
'opts': opts,
'message': gettext("Field %s not found") % raw_fields
'message': _("Field %s not found") % raw_fields
}
return render(request, 'admin/cms/page/plugin/error_form.html', context)
if not request.user.has_perm(f"{self.model._meta.app_label}.change_{self.model._meta.model_name}"):
context = {
'opts': opts,
'message': gettext("You do not have permission to edit this item")
'message': _("You do not have permission to edit this item")
}
return render(request, 'admin/cms/page/plugin/error_form.html', context)
# Dynamically creates the form class with only `field_name` field
Expand Down Expand Up @@ -361,11 +361,11 @@ def add_plugin(self, request):
plugin_type = plugin_data['plugin_type']

if not self.has_add_plugin_permission(request, placeholder, plugin_type):
message = gettext('You do not have permission to add a plugin')
message = _('You do not have permission to add a plugin')
return HttpResponseForbidden(message)

if not placeholder.check_source(request.user):
message = gettext('You do not have permission to add a plugin')
message = _('You do not have permission to add a plugin')
return HttpResponseForbidden(message)

plugin_class = plugin_pool.get_plugin(plugin_type)
Expand Down Expand Up @@ -417,7 +417,7 @@ def copy_plugins(self, request):
target_placeholder = get_object_or_404(Placeholder, pk=target_placeholder_id)

if not target_language or target_language not in get_language_list():
return HttpResponseBadRequest(gettext("Language must be set to a supported language!"))
return HttpResponseBadRequest(_("Language must be set to a supported language!"))

copy_to_clipboard = target_placeholder.pk == request.toolbar.clipboard.pk
source_plugin_id = request.POST.get('source_plugin_id', None)
Expand Down Expand Up @@ -457,11 +457,11 @@ def _copy_plugin_to_clipboard(self, request, target_placeholder):
old_plugins = [source_plugin] + list(source_plugin.get_descendants())

if not self.has_copy_plugins_permission(request, old_plugins):
message = gettext('You do not have permission to copy these plugins.')
message = _('You do not have permission to copy these plugins.')
raise PermissionDenied(message)

if not target_placeholder.check_source(request.user):
message = gettext('You do not have permission to copy these plugins.')
message = _('You do not have permission to copy these plugins.')
raise PermissionDenied(message)

# Empty the clipboard
Expand All @@ -482,11 +482,11 @@ def _copy_placeholder_to_clipboard(self, request, source_placeholder, target_pla
old_plugins = source_placeholder.get_plugins_list(language=source_language)

if not self.has_copy_plugins_permission(request, old_plugins):
message = gettext('You do not have permission to copy this placeholder.')
message = _('You do not have permission to copy this placeholder.')
raise PermissionDenied(message)

if not target_placeholder.check_source(request.user):
message = gettext('You do not have permission to copy this placeholder.')
message = _('You do not have permission to copy this placeholder.')
raise PermissionDenied(message)

# Empty the clipboard
Expand Down Expand Up @@ -528,11 +528,11 @@ def _add_plugins_from_placeholder(self, request, source_placeholder, target_plac
)

if not has_permissions:
message = gettext('You do not have permission to copy these plugins.')
message = _('You do not have permission to copy these plugins.')
raise PermissionDenied(message)

if not target_placeholder.check_source(request.user):
message = gettext('You do not have permission to copy these plugins.')
message = _('You do not have permission to copy these plugins.')
raise PermissionDenied(message)

target_tree_order = target_placeholder.get_plugin_tree_order(
Expand Down Expand Up @@ -577,18 +577,18 @@ def edit_plugin(self, request, plugin_id):
try:
plugin_id = int(plugin_id)
except ValueError:
return HttpResponseNotFound(gettext("Plugin not found"))
return HttpResponseNotFound(_("Plugin not found"))

obj = self._get_plugin_from_id(plugin_id)

# CMSPluginBase subclass instance
plugin_instance = obj.get_plugin_class_instance(admin=self.admin_site)

if not self.has_change_plugin_permission(request, obj):
return HttpResponseForbidden(gettext("You do not have permission to edit this plugin"))
return HttpResponseForbidden(_("You do not have permission to edit this plugin"))

if not obj.placeholder.check_source(request.user):
message = gettext("You do not have permission to edit this plugin")
message = _("You do not have permission to edit this plugin")
return HttpResponseForbidden(message)

response = plugin_instance.change_view(request, str(plugin_id))
Expand Down Expand Up @@ -732,11 +732,11 @@ def _paste_plugin(self, request, plugin, target_language,
plugins = [plugin] + list(plugin.get_descendants())

if not self.has_copy_from_clipboard_permission(request, target_placeholder, plugins):
message = gettext("You have no permission to paste this plugin")
message = _("You have no permission to paste this plugin")
raise PermissionDenied(message)

if not target_placeholder.check_source(request.user):
message = gettext("You have no permission to paste this plugin")
message = _("You have no permission to paste this plugin")
raise PermissionDenied(message)

if target_parent:
Expand Down Expand Up @@ -792,11 +792,11 @@ def _paste_placeholder(self, request, plugin, target_language,
plugins = plugin.placeholder_ref.get_plugins_list()

if not self.has_copy_from_clipboard_permission(request, target_placeholder, plugins):
message = gettext("You have no permission to paste this placeholder")
message = _("You have no permission to paste this placeholder")
raise PermissionDenied(message)

if not target_placeholder.check_source(request.user):
message = gettext("You have no permission to paste this placeholder")
message = _("You have no permission to paste this placeholder")
raise PermissionDenied(message)

action_token = self._send_pre_placeholder_operation(
Expand Down Expand Up @@ -849,19 +849,19 @@ def _move_plugin(self, request, plugin, target_position, target_placeholder=None
source_placeholder = plugin.placeholder

if not self.has_move_plugin_permission(request, plugin, source_placeholder):
message = gettext("You have no permission to move this plugin")
message = _("You have no permission to move this plugin")
raise PermissionDenied(message)

if target_placeholder and not self.has_move_plugin_permission(request, plugin, target_placeholder):
message = gettext("You have no permission to move this plugin")
message = _("You have no permission to move this plugin")
raise PermissionDenied(message)

if not source_placeholder.check_source(request.user):
message = gettext("You have no permission to move this plugin")
message = _("You have no permission to move this plugin")
raise PermissionDenied(message)

if target_placeholder and not target_placeholder.check_source(request.user):
message = gettext("You have no permission to move this plugin")
message = _("You have no permission to move this plugin")
raise PermissionDenied(message)

if target_parent:
Expand Down Expand Up @@ -913,11 +913,11 @@ def _cut_plugin(self, request, plugin, target_language, target_placeholder):
source_placeholder = plugin.placeholder

if not self.has_move_plugin_permission(request, plugin, source_placeholder):
message = gettext("You have no permission to cut this plugin")
message = _("You have no permission to cut this plugin")
raise PermissionDenied(message)

if not source_placeholder.check_source(request.user):
message = gettext("You have no permission to cut this plugin")
message = _("You have no permission to cut this plugin")
raise PermissionDenied(message)

action_token = self._send_pre_placeholder_operation(
Expand Down Expand Up @@ -962,11 +962,11 @@ def delete_plugin(self, request, plugin_id):
plugin = self._get_plugin_from_id(plugin_id)

if not self.has_delete_plugin_permission(request, plugin):
message = gettext("You do not have permission to delete this plugin")
message = _("You do not have permission to delete this plugin")
return HttpResponseForbidden(message)

if not plugin.placeholder.check_source(request.user):
message = gettext("You do not have permission to delete this plugin")
message = _("You do not have permission to delete this plugin")
raise PermissionDenied(message)

opts = plugin._meta
Expand Down Expand Up @@ -1044,11 +1044,11 @@ def clear_placeholder(self, request, placeholder_id):
return HttpResponseRedirect(admin_reverse('index', current_app=self.admin_site.name))

if not self.has_clear_placeholder_permission(request, placeholder, language):
message = gettext("You do not have permission to clear this placeholder")
message = _("You do not have permission to clear this placeholder")
return HttpResponseForbidden(message)

if not placeholder.check_source(request.user):
message = gettext("You do not have permission to clear this placeholder")
message = _("You do not have permission to clear this placeholder")
raise PermissionDenied(message)

opts = Placeholder._meta
Expand All @@ -1065,7 +1065,7 @@ def clear_placeholder(self, request, placeholder_id):
if request.POST:
# The user has already confirmed the deletion.
if perms_needed:
message = gettext("You do not have permission to clear this placeholder")
message = _("You do not have permission to clear this placeholder")
return HttpResponseForbidden(message)

operation_token = self._send_pre_placeholder_operation(
Expand Down

0 comments on commit 72ae356

Please sign in to comment.