On Fri, Oct 16, 2009 at 2:10 PM, David Cramer <dcra...@gmail.com> wrote: > I agree, this is 30 minutes of work to change the usage in Django, and it > should be done with the inclusion of the messages patch.
I'm working on migrating auth, admin, and the create_update generic views to use messages in my bitbucket branch. I updated them all to use request.messages.add() and things work great as long as one has the middleware and context processor enabled for django.contrib.messages. This obviously won't be the case, however, when everyone initially updates to Django 1.2. There are a couple ways around this that I see: 1) raise an error stating that the MessageMiddleware and 'messages' context processor need to be installed, like the admin does for the SessionMiddleware, e.g.: assert hasattr(request, 'messages'), "The Django admin requires message middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.messages.middleware.MessageMiddleware'." 2) add a compatibility method to the messages app that looks for messages and falls back to user.message_set if the middleware hasn't been enabled, e.g.: def compat_add_message(request, level, message): """ Attempt to add a message to the request using the 'messages' app, falling back to the user's message_set if MessageMiddleware hasn't been enabled. """ if hasattr(request, 'messages'): request.messages.add(level, message) elif hasattr(request, 'user') and request.user.is_authenticated(): request.user.message_set.create(message=message) In sticking with the staged deprecation policy, my vote would be: * use compat_add_message() internally in 1.2. There is no need to document this function as request.message_set.create will continue to work. * in 1.3, remove compat_add_message and raise an error if 'messages' isn't enabled when you try to use the admin or create_update generic views, etc. I could be convinced to skip the compatibility function and go straight to raising an error, but that seems like a big jump. I updated the branch to do basically this, but nothing is set in stone. Thoughts? Tobias -- Tobias McNulty Caktus Consulting Group, LLC P.O. Box 1454 Carrboro, NC 27510 (919) 951-0052 http://www.caktusgroup.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---