#37070: Add .clear_messages() method to django.contrib.messages
----------------------------------+--------------------------------------
     Reporter:  benjaoming        |                    Owner:  (none)
         Type:  New feature       |                   Status:  new
    Component:  contrib.messages  |                  Version:  dev
     Severity:  Normal            |               Resolution:
     Keywords:                    |             Triage Stage:  Unreviewed
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+--------------------------------------
Changes (by Sarah Boyce):

 * version:   => dev


Old description:

> Disclaimer: This is really a minor issue 😊
>
> We can do:
>
> ```
> from django.contrib.messages import get_messages
> ```
>
> And then we can call `get_messages()` - and if we iterate over them, they
> will be cleared.
>
> But we can't explicitly clear them because this method doesn't exist:
>
> ```
> from django.contrib.messages import clear_messages
> ```
>
> For me, the use-case was test-related: Writing an e2e test case that
> calls some views and at each step verified messages, then cleared them.
>
> Not sure if adding the method would make people use the messages
> framework wrongly, but I think it makes sense to note that ADDING
> `clear_messages` to the mix might make some people think you need to call
> it... which in most cases, you don't, and therefore the documentation
> needs to be ''clear'' (pun intended).
>
> Forum discussion: https://forum.djangoproject.com/t/why-isnt-it-easier-
> to-clear-messages/5727/7

New description:

 Disclaimer: This is really a minor issue 😊

 We can do:

 {{{
 from django.contrib.messages import get_messages
 }}}

 And then we can call `get_messages()` - and if we iterate over them, they
 will be cleared.

 But we can't explicitly clear them because this method doesn't exist:

 {{{
 from django.contrib.messages import clear_messages
 }}}

 For me, the use-case was test-related: Writing an e2e test case that calls
 some views and at each step verified messages, then cleared them.

 Not sure if adding the method would make people use the messages framework
 wrongly, but I think it makes sense to note that ADDING `clear_messages`
 to the mix might make some people think you need to call it... which in
 most cases, you don't, and therefore the documentation needs to be
 ''clear'' (pun intended).

 Forum discussion: https://forum.djangoproject.com/t/why-isnt-it-easier-to-
 clear-messages/5727/7

--
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37070#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019dcec7bcb2-a5daf2df-5e31-4d98-8f34-1bf9e377f7f0-000000%40eu-central-1.amazonses.com.

Reply via email to