Skip to content

Commit 2bb41ee

Browse files
committed
Added reload() method for context and user
1 parent 8f73fe3 commit 2bb41ee

File tree

2 files changed

+147
-76
lines changed

2 files changed

+147
-76
lines changed

djangojs/static/js/djangojs/django.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
*/
2020
initialize: function() {
2121
this.urls = window.DJANGO_JS_URLS;
22-
this.context = window.DJANGO_JS_CONTEXT;
23-
this.user = window.DJANGO_JS_CONTEXT.user;
22+
this.set_context(window.DJANGO_JS_CONTEXT);
23+
},
24+
25+
set_context: function(context) {
26+
this.context = context;
27+
this.user = context.user;
2428
if (this.user) {
2529
/**
2630
* Equivalent to ``User.has_perm`` function.
@@ -31,6 +35,16 @@
3135
}
3236
},
3337

38+
/**
39+
* Reload context and user
40+
*/
41+
reload: function(callback) {
42+
$.get(this.url('django_js_context'), function(context) {
43+
Django.set_context(context);
44+
callback();
45+
});
46+
},
47+
3448
/**
3549
* Equivalent to ``reverse`` function and ``url`` template tag.
3650
*/

0 commit comments

Comments
 (0)