From 8111ae107a4e8c4f20470f73b349b771198caf08 Mon Sep 17 00:00:00 2001 From: Bartuccio Antoine Date: Thu, 20 Dec 2018 14:15:57 +0100 Subject: [PATCH] core: move centralized custom scripts on top of base.jinja and move getCookie inside --- core/static/core/js/script.js | 19 +++++++++++++++++++ core/templates/core/base.jinja | 3 ++- core/templates/core/markdown_textarea.jinja | 19 ------------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/core/static/core/js/script.js b/core/static/core/js/script.js index 32644885..0fc49293 100644 --- a/core/static/core/js/script.js +++ b/core/static/core/js/script.js @@ -43,3 +43,22 @@ $( function() { function display_notif() { $('#header_notif').toggle().parent().toggleClass("white"); } + +// You can't get the csrf token from the template in a widget +// We get it from a cookie as a workaround, see this link +// https://docs.djangoproject.com/en/2.0/ref/csrf/#ajax +function getCookie(cname) { + var name = cname + "="; + var decodedCookie = decodeURIComponent(document.cookie); + var ca = decodedCookie.split(';'); + for(var i = 0; i + + {% endblock %} @@ -257,7 +259,6 @@ -