Send a message to the user. The default implementation posts a message using the django.contrib.messages backend. Exposes almost the same API as messages.add_message(), but accepts the positional arguments in a different order to maintain backwards compatibi
(
self, request, message, level=messages.INFO, extra_tags="", fail_silently=False
)
| 1410 | return construct_change_message(form, formsets, add) |
| 1411 | |
| 1412 | def message_user( |
| 1413 | self, request, message, level=messages.INFO, extra_tags="", fail_silently=False |
| 1414 | ): |
| 1415 | """ |
| 1416 | Send a message to the user. The default implementation |
| 1417 | posts a message using the django.contrib.messages backend. |
| 1418 | |
| 1419 | Exposes almost the same API as messages.add_message(), but accepts the |
| 1420 | positional arguments in a different order to maintain backwards |
| 1421 | compatibility. For convenience, it accepts the `level` argument as |
| 1422 | a string rather than the usual level number. |
| 1423 | """ |
| 1424 | if not isinstance(level, int): |
| 1425 | # attempt to get the level if passed a string |
| 1426 | try: |
| 1427 | level = getattr(messages.constants, level.upper()) |
| 1428 | except AttributeError: |
| 1429 | levels = messages.constants.DEFAULT_TAGS.values() |
| 1430 | levels_repr = ", ".join("`%s`" % level for level in levels) |
| 1431 | raise ValueError( |
| 1432 | "Bad message level string: `%s`. Possible values are: %s" |
| 1433 | % (level, levels_repr) |
| 1434 | ) |
| 1435 | |
| 1436 | messages.add_message( |
| 1437 | request, level, message, extra_tags=extra_tags, fail_silently=fail_silently |
| 1438 | ) |
| 1439 | |
| 1440 | def save_form(self, request, form, change): |
| 1441 | """ |
no test coverage detected