Skip to content

Loading…

django 1.4 compatibilty (message_set vs. contrib messages) #6

Merged
merged 2 commits into from

2 participants

@hpoul

hi,
i needed to change all accesses to message_set to use the messages contrib app.. maybe you could consider using that (it's available since django 1.2 afaik)
there was also an 'import django' missing in change_list

as for swfupload: it seems i never actually used swfupload, i reverted my add-commit, and i can still upload everything :) works good enough (i obviously get 404 errors because swfupload is still referenced, but not there)

@samluescher samluescher merged commit 4dd1f82 into samluescher:master
@samluescher
Owner

Good call, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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,7 +50,7 @@ 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:
@@ -57,9 +58,9 @@ def delete_orphaned_files(modeladmin, request, queryset=None):
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:
View
1 media_tree/admin/change_list.py
@@ -1,3 +1,4 @@
+import django
from media_tree.models import FileNode
from media_tree.admin.utils import get_current_request, is_search_request, \
get_request_attr
Something went wrong with that request. Please try again.