Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to allow disabling of automatic messages for create and update views #187

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions smartmin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ def get_queryset(self):

def derive_success_message(self):
# First check whether a default message has been set
if self.success_message is None:
if self.success_message is None and getattr(settings, "SMARTMIN_DEFAULT_MESSAGES", True):
return "Your %s has been updated." % self.model._meta.verbose_name
else:
return self.success_message
Expand Down Expand Up @@ -1273,7 +1273,7 @@ def pre_save(self, obj):

def derive_success_message(self):
# First check whether a default message has been set
if self.success_message is None:
if self.success_message is None and getattr(settings, "SMARTMIN_DEFAULT_MESSAGES", True):
return _("Your new %s has been created.") % self.model._meta.verbose_name
else:
return self.success_message
Expand Down
22 changes: 18 additions & 4 deletions test_runner/blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,27 @@ def test_messaging(self):
post = list(Post.objects.all())[-1]

self.assertEqual(200, response.status_code)
self.assertContains(response, "Your new post has been created.")
self.assertContains(response, "Your new post has been created.") # created from model name

post_data = dict(title="New Post", body="Updated post content", order=1, tags="post")
response = self.client.post(reverse("blog.post_update", args=[post.id]), post_data, follow=True)
response = self.client.post(
reverse("blog.post_update", args=[post.id]),
{"title": "New Post", "body": "Updated post content", "order": 1, "tags": "post"},
follow=True,
)

self.assertEqual(200, response.status_code)
self.assertContains(response, "Your blog post has been updated.")
self.assertContains(response, "Your blog post has been updated.") # set explicitly on view

# can disable auto-creating success messages from model names
with self.settings(SMARTMIN_DEFAULT_MESSAGES=False):
response = self.client.post(
reverse("blog.post_create"),
{"title": "Post 2", "body": "Hi Again", "order": 1, "tags": "post"},
follow=True,
)

self.assertEquals(200, response.status_code)
self.assertNotContains(response, "Your new post has been created.") # disabled

def test_message_tags(self):
self.client.login(username="author", password="author")
Expand Down