diff --git a/README.md b/README.md index 2124681..1fc8ee2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/iambrandontaylor/django-admin-sortable.svg?branch=master)](https://travis-ci.org/iambrandontaylor/django-admin-sortable) -Current version: 2.0.10 +Current version: 2.0.11 This project makes it easy to add drag-and-drop ordering to any model in Django admin. Inlines for a sortable model may also be made sortable, @@ -457,8 +457,8 @@ ordering on top of that just seemed a little much in my opinion. django-admin-sortable is currently used in production. -### What's new in 2.0.10? -- Bugfix for accessing custom `order` property of model. Thanks [@theithec](https://github.com/theithec) for reporting the issue. +### What's new in 2.0.11? +- Custom [CSRF_COOKIE_NAME](https://docs.djangoproject.com/en/1.9/ref/settings/#csrf-cookie-name) is now supported. Thanks [@BUHARDI](https://github.com/BUHARDI) for reporting the issue. ### Future diff --git a/README.rst b/README.rst index 95c7ea4..dad7dbb 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ Django Admin Sortable |Build Status| -Current version: 2.0.10 +Current version: 2.0.11 This project makes it easy to add drag-and-drop ordering to any model in Django admin. Inlines for a sortable model may also be made sortable, @@ -596,11 +596,13 @@ Status django-admin-sortable is currently used in production. -What's new in 2.0.10? +What's new in 2.0.11? ~~~~~~~~~~~~~~~~~~~~~ -- Bugfix for accessing custom ``order`` property of model. Thanks - [@theithec](https://github.com/theithec) for reporting the issue. +- Custom + `CSRF\_COOKIE\_NAME `__ + is now supported. Thanks [@BUHARDI](https://github.com/BUHARDI) for + reporting the issue. Future ~~~~~~ diff --git a/adminsortable/__init__.py b/adminsortable/__init__.py index 25cbabc..25c829a 100644 --- a/adminsortable/__init__.py +++ b/adminsortable/__init__.py @@ -1,4 +1,4 @@ -VERSION = (2, 0, 10) +VERSION = (2, 0, 11) DEV_N = None diff --git a/adminsortable/admin.py b/adminsortable/admin.py index 0a6b21c..72ae0a9 100755 --- a/adminsortable/admin.py +++ b/adminsortable/admin.py @@ -215,7 +215,8 @@ class SortableAdmin(SortableAdminBase, ModelAdmin): 'sortable_by_class': sortable_by_class, 'sortable_by_class_is_sortable': sortable_by_class_is_sortable, 'sortable_by_class_display_name': sortable_by_class_display_name, - 'jquery_lib_path': jquery_lib_path + 'jquery_lib_path': jquery_lib_path, + 'csrf_cookie_name': getattr(settings, 'CSRF_COOKIE_NAME', 'csrftoken') } return render(request, self.sortable_change_list_template, context) diff --git a/adminsortable/static/adminsortable/js/jquery.django-csrf.js b/adminsortable/static/adminsortable/js/jquery.django-csrf.js deleted file mode 100644 index 280f398..0000000 --- a/adminsortable/static/adminsortable/js/jquery.django-csrf.js +++ /dev/null @@ -1,32 +0,0 @@ -// using jQuery -function getCookie(name) { - var cookieValue = null; - if (document.cookie && document.cookie !== '') { - var cookies = document.cookie.split(';'); - for (var i = 0; i < cookies.length; i++) { - var cookie = django.jQuery.trim(cookies[i]); - // Does this cookie string begin with the name we want? - if (cookie.substring(0, name.length + 1) === (name + '=')) { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - break; - } - } - } - return cookieValue; -} - -var csrftoken = getCookie('csrftoken'); - -function csrfSafeMethod(method) { - // these HTTP methods do not require CSRF protection - return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); -} - -django.jQuery.ajaxSetup({ - crossDomain: false, // obviates need for sameOrigin test - beforeSend: function(xhr, settings) { - if (!csrfSafeMethod(settings.type)) { - xhr.setRequestHeader("X-CSRFToken", csrftoken); - } - } -}); diff --git a/adminsortable/templates/adminsortable/change_form.html b/adminsortable/templates/adminsortable/change_form.html index 0f3fd76..406d4c4 100644 --- a/adminsortable/templates/adminsortable/change_form.html +++ b/adminsortable/templates/adminsortable/change_form.html @@ -8,7 +8,7 @@ {% if has_sortable_tabular_inlines or has_sortable_stacked_inlines %} - + {% include 'adminsortable/csrf/jquery.django-csrf.html' with csrf_cookie_name=csrf_cookie_name %} {% endif %} {% if has_sortable_tabular_inlines %} diff --git a/adminsortable/templates/adminsortable/change_list.html b/adminsortable/templates/adminsortable/change_list.html index 7b6e83e..013a9bd 100644 --- a/adminsortable/templates/adminsortable/change_list.html +++ b/adminsortable/templates/adminsortable/change_list.html @@ -13,7 +13,7 @@ - + {% include 'adminsortable/csrf/jquery.django-csrf.html' with csrf_cookie_name=csrf_cookie_name %} {% endblock %} diff --git a/adminsortable/templates/adminsortable/csrf/jquery.django-csrf.html b/adminsortable/templates/adminsortable/csrf/jquery.django-csrf.html new file mode 100644 index 0000000..24fb6c3 --- /dev/null +++ b/adminsortable/templates/adminsortable/csrf/jquery.django-csrf.html @@ -0,0 +1,34 @@ +