Skip to content

Commit

Permalink
Fix the Locale create/edit/delete success messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ACK1D committed Jan 6, 2024
1 parent fc8fcb3 commit 61fa8eb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions wagtail_localize/locales/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def get_context_data(self):

class CreateView(generic.CreateView):
page_title = gettext_lazy("Add locale")
success_message = gettext_lazy("Locale '{0}' created.")
template_name = "wagtaillocales/create.html"

def get_components(self):
Expand All @@ -112,6 +111,10 @@ def post(self, request, *args, **kwargs):
else:
return self.form_invalid(form)

@property
def success_message(self):
return gettext_lazy("Locale '{0}' created.").format(str(self.object))

@transaction.atomic
def form_valid(self, form):
response = super().form_valid(form)
Expand All @@ -125,7 +128,6 @@ def get_context_data(self, **kwargs):


class EditView(generic.EditView):
success_message = gettext_lazy("Locale '{0}' updated.")
error_message = gettext_lazy("The locale could not be saved due to errors.")
delete_item_label = gettext_lazy("Delete locale")
context_object_name = "locale"
Expand All @@ -152,6 +154,10 @@ def post(self, request, *args, **kwargs):
else:
return self.form_invalid(form)

@property
def success_message(self):
return gettext_lazy("Locale '{0}' updated.").format(str(self.object))

@transaction.atomic
def form_valid(self, form):
response = super().form_valid(form)
Expand All @@ -165,7 +171,6 @@ def get_context_data(self, **kwargs):


class DeleteView(generic.DeleteView):
success_message = gettext_lazy("Locale '{0}' deleted.")
cannot_delete_message = gettext_lazy(
"This locale cannot be deleted because there are pages and/or other objects using it."
)
Expand All @@ -189,6 +194,10 @@ def form_valid(self, form):
messages.error(self.request, self.cannot_delete_message)
return super().get(self.request)

@property
def success_message(self):
return gettext_lazy("Locale '{0}' deleted.").format(str(self.object))


class LocaleViewSet(ModelViewSet):
icon = "site"
Expand Down

0 comments on commit 61fa8eb

Please sign in to comment.