Skip to content

Commit d335515

Browse files
committed
Improve error message on invalid movements
Based on commits by @psychotechnik
1 parent 95fce58 commit d335515

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Changes in version 0.8.4 (alpha release)
22
----------------------------------------
33

44
* Fix list appearance in combination with django-grapelli
5+
* Improve error messages on invalid movements
56

67

78
Changes in version 0.8.3 (alpha release)

polymorphic_tree/admin/parentadmin.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,15 @@ def api_node_moved_view(self, request):
157157
return HttpResponseNotFound(simplejson.dumps({'action': 'reload', 'error': str(e[0])}), content_type='application/json')
158158

159159
if not self.can_have_children(target) and position == 'inside':
160-
return HttpResponse(simplejson.dumps({'action': 'reject', 'error': 'Cannot move inside target, does not allow children!'}), content_type='application/json', status=409) # Conflict
160+
return HttpResponse(simplejson.dumps({
161+
'action': 'reject',
162+
'error': _(u'Cannot place \u2018{0}\u2019 below \u2018{1}\u2019; a {2} does not allow children!').format(moved, target, target._meta.verbose_name)
163+
}), content_type='application/json', status=409) # Conflict
161164
if moved.parent_id != previous_parent_id:
162-
return HttpResponse(simplejson.dumps({'action': 'reload', 'error': 'Client seems to be out-of-sync, please reload!'}), content_type='application/json', status=409)
165+
return HttpResponse(simplejson.dumps({
166+
'action': 'reload',
167+
'error': 'Client seems to be out-of-sync, please reload!'
168+
}), content_type='application/json', status=409)
163169

164170
# TODO: with granular user permissions, check if user is allowed to edit both pages.
165171

polymorphic_tree/locale/nl/LC_MESSAGES/django.po

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ msgid ""
66
msgstr ""
77
"Project-Id-Version: \n"
88
"Report-Msgid-Bugs-To: \n"
9-
"POT-Creation-Date: 2012-07-24 20:43+0200\n"
9+
"POT-Creation-Date: 2012-12-30 14:49+0100\n"
1010
"PO-Revision-Date: 2011-01-10 23:54+0100\n"
1111
"Last-Translator: Diederik van der Boor <[email protected]>\n"
1212
"Language-Team: Dutch <[email protected]>\n"
@@ -17,7 +17,7 @@ msgstr ""
1717
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
1818
"X-Generator: Lokalize 1.1\n"
1919

20-
#: models.py:37
20+
#: models.py:36
2121
msgid "The selected node cannot have child nodes."
2222
msgstr "De gekozen node kan geen subpagina's bevatten."
2323

@@ -37,6 +37,10 @@ msgstr "Acties"
3737
msgid "Add sub node"
3838
msgstr "Sub node toevoegen"
3939

40+
#: admin/parentadmin.py:162
41+
msgid "Cannot place ‘{0}’ below ‘{1}’; a {2} does not allow children!"
42+
msgstr "Kan ‘{0}’ niet onder ‘{1}’ plaatsen; een {2} element staat geen onderliggende elementen toe!"
43+
4044
#: templates/admin/polymorphic_tree/add_type_form.html:27
4145
msgid "Please correct the error below."
4246
msgid_plural "Please correct the errors below."
@@ -49,14 +53,6 @@ msgid ""
4953
"page now reloaded."
5054
msgstr ""
5155

52-
#: templates/admin/polymorphic_tree/jstree_list_results.html:103
53-
msgid ""
54-
"It is not allowed to move a node to the last position.\\nThe current page "
55-
"will now reload."
56-
msgstr ""
57-
"Het is niet toegestaan om een node te verplaatsen naar de vorige positie."
58-
"\\nDe huidige pagina zal nu herladen worden."
59-
6056
#: templates/admin/polymorphic_tree/jstree_list_results.html:107
6157
msgid ""
6258
"There was an error while moving the node, please reload the current page."

polymorphic_tree/templates/admin/polymorphic_tree/jstree_list_results.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@
9393
});
9494

9595
function onMoveError(xhr, status, exception) {
96-
response = jQuery.parseJSON(xhr.response);
96+
var response = jQuery.parseJSON(xhr.responseText);
9797
// TODO: it would be possible to stream new data from the server instead.
9898
if( response.action == 'reload' ) {
9999
alert('{% trans "Unable to move the node, the current display is out-of-date.\nThe current page now reloaded." %}');
100100
location.reload();
101101
}
102102
else if( response.action == 'reject' ) {
103-
alert('{% trans "It is not allowed to move a node to the last position.\nThe current page will now reload." %}');
103+
alert(response.error);
104104
location.reload();
105105
}
106106
else {

0 commit comments

Comments
 (0)