Hi all - 

I'm working with an open source package - virtual storage manager - VSM 
(https://github.com/01org/virtual-storage-manager) - that's based on Django 
and Openstack Horizon framework. Horizon is based on Django, and VSM chose 
to use Horizon rather than straight Django for Horizon's datatables 
(afaik). In any case, I'm having a problem that I hope someone in the 
Django community can clarify for me. Unfortunately, the problem is at the 
intersection of Horizon and Django, so I've not been able to find anyone in 
either community who knows enough about the other side to recognize what 
might be going on.

Horizon provides a confirmation dialog and their own version of an i18n 
javascript file - accessible by including a line like this in your html 
template:

<script src="{% url 'horizon:jsi18n' 'horizon' %}"></script>


This line, of course, includes the Django javascript translation catalog 
(eventually), and when I do this, Horizon DeleteAction based operations 
(e.g., a "Delete Pool" button) which have an inherent confirmation modal 
dialog (almost) properly display the confirmation dialog. The 
horizon.datatables.confirm function doesn't crash in the middle when it 
tries to call interpolate() and gettext(). As you know, these methods are 
part of the Django translation catalog and without it, any javascript code 
that tries to use them will crash. So I *almost* get a confirmation dialog 
(what's missing is another topic - the dialog is there, it's just hidden 
and I have to perform some additional machinations to get it to show up). 
Suffice it to say that with the translation catalog in place, the 
javascript doesn't throw, and the popup (mostly) works.

Unfortunately, when those methods are available at the global scope, the 
buttons based on Horizon's LinkAction - those that actually transfer the 
user to a different page - cause other Horizon javascript functions to fail 
and those pages fail to work correctly. Instead of the browser being 
redirected to the new page (the link in the LinkAction) the new template 
simply gets appended to the current page, and the entire page goes dark - 
like a modal is sitting there waiting for user response but no modal is 
displayed. 

My final solution was to add code like this to the bottom of my index.html 
template:

var __origHDTC = horizon.datatables.confirm;
horizon.datatables.confirm = function(action) {
    var args = [].slice.call(arguments, 0);
    interpolate = function (fmt, obj) { return fmt.replace(/%s/g, 
function(match){return String(obj.shift())}); };
    gettext = function (msgid) { return msgid; };
    var rv = __origHDTC.apply(this, args);
    interpolate = gettext = undefined;
    return rv;
}


What I'm doing is replacing the original function with a wrapper that 
defines the methods, calls the original code, and then undefines the 
methods. *This actually works, believe it or not.*

Either Django is being bastardized by Horizon, or Horizon is being 
bastardized by VSM - I don't really know enough about the entire system in 
either case to understand what's going on from a 10,000 foot view. Hoping 
someone out there has dealt with Django and Horizon enough to be able to 
clue me in.

Thanks in advance,
John Calcote

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/467ea441-c7e8-4bf0-a349-43d674276d2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to