Skip to content

Commit

Permalink
Fix the Locale create/edit/delete success messages (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
ACK1D committed Jan 6, 2024
1 parent fc8fcb3 commit bb04c76
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,9 +91,12 @@ 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"

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

def get_components(self):
return ComponentManager.from_request(self.request)

Expand Down Expand Up @@ -125,13 +128,16 @@ 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"
template_name = "wagtaillocales/edit.html"
queryset = Locale.all_objects.all()

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

def get_components(self):
return ComponentManager.from_request(
self.request, source_object_instance=self.object
Expand Down Expand Up @@ -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 @@ -174,6 +179,10 @@ class DeleteView(generic.DeleteView):
template_name = "wagtaillocales/confirm_delete.html"
queryset = Locale.all_objects.all()

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

def can_delete(self, locale):
return get_locale_usage(locale) == (0, 0)

Expand Down

0 comments on commit bb04c76

Please sign in to comment.