Browse files

message_set to messages (django 1.4 compatibility)

  • Loading branch information...
1 parent db6e912 commit 912288c5a8c722aa86412bbf66b3cb287565108c @hpoul committed Mar 23, 2012
Showing with 10 additions and 8 deletions.
  1. +2 −1 media_tree/admin/actions/core_actions.py
  2. +8 −7 media_tree/admin/actions/maintenance_actions.py
View
3 media_tree/admin/actions/core_actions.py
@@ -4,6 +4,7 @@
from media_tree.forms import MetadataForm
from media_tree.utils.filenode import get_nested_filenode_list
from django import forms
+from django.contrib import messages
from django.utils.translation import ungettext, ugettext as _
from django.template import RequestContext
from django.core.urlresolvers import reverse
@@ -36,7 +37,7 @@ def filenode_admin_action(modeladmin, request, queryset, form_class, extra_conte
redirect_node = form.cleaned_data.get('target_node', None)
if not redirect_node:
redirect_node = get_current_node(form)
- request.user.message_set.create(message=ungettext(success_messages[0], success_messages[1], form.success_count) % {
+ messages.success(request, message=ungettext(success_messages[0], success_messages[1], form.success_count) % {
'count': form.success_count,
'verbose_name': FileNode._meta.verbose_name,
'verbose_name_plural': FileNode._meta.verbose_name_plural
View
15 media_tree/admin/actions/maintenance_actions.py
@@ -11,6 +11,7 @@
from django.contrib.admin import helpers
from django.http import HttpResponse, HttpResponseRedirect
from django.conf import settings
+from django.contrib import messages
from django.utils.safestring import mark_safe
import os
@@ -49,17 +50,17 @@ def delete_orphaned_files(modeladmin, request, queryset=None):
orphaned_files_choices.append((storage_name, link))
if not len(orphaned_files_choices) and not len(nodes_with_missing_file_links):
- request.user.message_set.create(message=_('There are no orphaned files.'))
+ messages.success(request, message=_('There are no orphaned files.'))
return HttpResponseRedirect('')
if execute:
form = DeleteOrphanedFilesForm(queryset, orphaned_files_choices, request.POST)
if form.is_valid():
form.save()
node = FileNode.get_top_node()
- request.user.message_set.create(message=ungettext('Deleted %i file from storage.', 'Deleted %i files from storage.', len(form.success_files)) % len(form.success_files))
+ messages.success(request, message=ungettext('Deleted %i file from storage.', 'Deleted %i files from storage.', len(form.success_files)) % len(form.success_files))
if form.error_files:
- request.user.message_set.create(message=_('The following files could not be deleted from storage:')+' '+repr(form.error_files))
+ messages.error(request, message=_('The following files could not be deleted from storage:')+' '+repr(form.error_files))
return HttpResponseRedirect(node.get_admin_url())
if not execute:
@@ -87,7 +88,7 @@ def rebuild_tree(modeladmin, request, queryset=None):
Rebuilds whole tree in database using `parent` link.
"""
tree = FileNode.tree.rebuild()
- request.user.message_set.create(message=_('The node tree was rebuilt.'))
+ messages.success(request, message=_('The node tree was rebuilt.'))
return HttpResponseRedirect('')
rebuild_tree.short_description = _('Repair node tree')
rebuild_tree.allow_empty_queryset = True
@@ -118,7 +119,7 @@ def clear_cache(modeladmin, request, queryset=None):
cache_files_choices.append((storage_name, link))
if not len(cache_files_choices):
- request.user.message_set.create(message=_('There are no cache files.'))
+ messages.warning(request, message=_('There are no cache files.'))
return HttpResponseRedirect('')
if execute:
@@ -129,9 +130,9 @@ def clear_cache(modeladmin, request, queryset=None):
message = ungettext('Deleted %i cache file.', 'Deleted %i cache files.', len(form.success_files)) % len(form.success_files)
if len(form.success_files) == len(cache_files_choices):
message = '%s %s' % (_('The cache was cleared.'), message)
- request.user.message_set.create(message=message)
+ messages.success(request, message=message)
if form.error_files:
- request.user.message_set.create(message=_('The following files could not be deleted:')+' '+repr(form.error_files))
+ messages.error(request, message=_('The following files could not be deleted:')+' '+repr(form.error_files))
return HttpResponseRedirect(node.get_admin_url())
if not execute:

0 comments on commit 912288c

Please sign in to comment.