Resolved an issue related to adding menus dynamically using the jinja2
templates. The variable scope for the jinja2 template variable is not consitent across all the for loop (loop withing loop), it was behaving inconsistently, a value set in a loop was not properly accessible in inner loop properly. In order to resolve the issue - setting/using the variable only in inner loop, and call add_menus function multiple times, which we were trying to avoid, but - we can live with that.pull/3/head
parent
b85f9e6d1a
commit
f8a45799b6
|
@ -509,8 +509,8 @@ function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) {
|
|||
// First - register the menus from the other
|
||||
// modules/extensions.
|
||||
if (counter.total == counter.loaded) {
|
||||
{% set hasMenus = None %}
|
||||
obj.add_menus([{% for key in ('File', 'Edit', 'Object' 'Tools', 'Management', 'Help') %}{% for item in current_app.menu_items['%s_items' % key.lower()] %}{% if hasMenus is not none %}, {% endif %} {
|
||||
{% for key in ('File', 'Edit', 'Object' 'Tools', 'Management', 'Help') %}{% set menu_items = current_app.menu_items['%s_items' % key.lower()] %}{% if menu_items|length > 0 %}{% set hasMenus = False %}
|
||||
obj.add_menus([{% for item in menu_items %}{% if hasMenus %},{% endif %}{
|
||||
name: "{{ item.name }}",
|
||||
{% if item.module %}module: {{ item.module }},
|
||||
{% endif %}{% if item.url %}url: "{{ item.url }}",
|
||||
|
@ -521,7 +521,8 @@ function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) {
|
|||
{% endif %}label: '{{ item.label }}', applies: ['{{ key.lower() }}'],
|
||||
priority: {{ item.priority }},
|
||||
enable: '{{ item.enable }}'
|
||||
}{% set hasMenus = True %}{% endfor %}{% endfor %}]);
|
||||
}{% set hasMenus = True %}{% endfor %}]);
|
||||
{% endif %}{% endfor %}
|
||||
obj.create_menus();
|
||||
} else {
|
||||
// recall after some time
|
||||
|
|
Loading…
Reference in New Issue