{
    "training": {

        "id": "{{ training.id }}",
        "name": "{{ training.name|escapejs }}",
        "purpose": "{{ training.description|escapejs }}",
        "image": "{{ training.image.get_filename }}",
        "last_update": "{{ training.version }}-{{ trainer.id }}",
        "session_id": "{{ current_session.id }}",
        "items": {

            "document": [

                {% for document in doc %}
                    {% if not document.hidden %}
                        {
                            "id": "{{ document.id }}",
                            "url": "{{ document.doc_file.orig_file.url }}",
                            "hash": "{{ document.doc_file.hash }}",
                            "type": {% if document.doc_file.doc_type == 'vid' %} "video" {% else %} "{{ document.doc_file.doc_type }}" {% endif %},
                            "title": " {{ document.name|escapejs }}",
                            "preview": {% if document.doc_file.doc_type == 'vid' %} "video-preview.png" {% else %} "{{ document.doc_file.preview.url }}" {% endif %},
                            "file_name": " {{ document.doc_file.get_filename }}",
                            "module": "document",
                            "groups": [
                                {% for group in document.mgroups.all %}
                                    "{{group.name}}",
                                {% endfor %}
                            ],
                            "cached": {% if docment.doc_file.doc_type == 'vid' %} false {% else %} true {% endif %},
                            "order": {{ document.order }}
                        },

                        {% if document.doc_file_comment.orig_file %}
                        {
                            "id": "{{ document.doc_file_comment.id }}",
                            "url": "{{ document.doc_file_comment.orig_file.url }}",
                            "hash": "{{ document.doc_file_comment.hash }}",
                            "type": "download",
                            "title": "{{ document.name }}",
                            "file_name": "{{ document.doc_file.hash }}-annoted.{{ document.doc_file.doc_type }}",
                            "module": "document",
                            "groups": [
                            {% for group in document.mgroups.all %}
                                "{{group.name}}",
                            {% endfor %}
                            ],
                            "cached": true,
                            "order": {{ document.order }}
                        },
                        {% endif %}
                    {% endif %}
                {% endfor %}

                {% for download in downloads %}
                {
                    "id": "{{ download.id }}",

                    {% if download.img %}
                        "url": "{{ download.img.url }}",
                    {% else %}
                        "url": "",
                    {% endif %}

                    "hash": "{{ download.hash }}",
                    "type": "download",
                    "file_name": "{{ download.get_filename }}",
                    "title": "{{ download.get_filename }}",
                    "module": "document",
                    "cached": true,
                    "order": {{download.order}}
                },
                {% endfor %}
            ],

            "workshop": [
                {% for workshop in workshops %}
                    {{ workshop.get_serialize_json|safe }},
                {% endfor %}
            ],

            "meta_plan": [
                {
                    "id": "nil",
                    "title": "New Meta Plan v2",
                    "preview": "metaplan-preview.png",
                    "module": "meta_plan",
                    "groups": [
                        "trainer"
                    ],
                    "order":1,
                    "template_id": "",
                    "templates": [
                        {% for theme in themes %}
                        {
                            "id": "{{ theme.id }}",
                            "title": "{{ theme.title }}",
                            "preview": "{{ theme.preview }}",
                            "image": "{{ theme.image }}"
                        },
                        {% endfor %}
                    ],
                },

                {% for metaplan in metaplans %}
                    {
                        "id": "{{ metaplan.id }}",
                        "metaplan_template_id": "{{ metaplan.metaplan_template.id }}",
                        "title": "{{ metaplan.metaplan_template.title }}",
                        "preview": "metaplan-preview.png",
                        "module": "plan_meta",
                        "groups": [
                            "trainer"
                        ],
                        "order": {{ forloop.counter }},
                        "template_id": "{{ metaplan.metaplan_template.theme.id }}",
                        "templates": [
                            {% for theme in themes %}
                            {
                                "id": "{{ theme.id }}",
                                "title": "{{ theme.title }}",
                                "preview": "{{ theme.preview }}",
                                "image": "{{ theme.image }}"
                            },
                            {% endfor %}
                        ],
                        "proposals": [
                            {% for proposition in metaplan.get_propositions %}
                            {
                                "id": {{ proposition.id }},
                                "msg": "{{ proposition.text }}",
                                "user_id": "{{ proposition.user.id }}",
                                "proposal_group_id": {{ proposition.group.id }}
                            },
                            {% endfor %}
                        ],
                        "proposal_groups" : [
                            {% for group in metaplan.metaplanpropositiongroup_set.all %}
                            {
                                "id": "{{ group.id }}",
                                "title": "{{ group.name }}",
                                "color": "{{ group.color }}",
                                "x": {{ group.position_x }},
                                "y": {{ group.position_y }},
                                "order": {{ forloop.counter }}
                            }
                            {% endfor %}
                        ]
                    },
                {% endfor %}
            ],

            "background_execution": [
                {% for bg_task in bg_tasks %}
                    {
                        "id": "{{ bg_task.id }}",
                        "authorization": {{ bg_task.mgroups.all }},
                        "begin_date": {{ bg_task.get_begin_date }},
                        "end_date": {{ bg_task.get_end_date }},
                        "execution": {
                            "action": "{{ bg_task.get_action }}",
                            "params": {{ bg_task.get_param|escapejs }}
                        }
                    },
                {% endfor %}
            ],

            "buzzer": [
                {
                    "id": "2cc",
                    "title": "New Buzzer",
                    "module": "buzzer",
                    "groups": [
                        "trainer"
                    ],
                    "preview": "buzzer-preview.png",
                    "order": 101
                }
            ],

            "who_is_who": [
                {
                    "id": "2cc",
                    "title": "Show Who's who",
                    "module": "who_is_who",
                    "groups": [
                        "trainer",
                        "trainee"
                    ],
                    "preview": "whoswho-preview.png",
                    "order": 0
                }
            ],

            "photo_story": [
                {
                    "id": "7gg",
                    "title": "Photo Story",
                    "module": "photo_story",
                    "groups": [
                        "trainer",
                        "trainee"
                    ],
                    "preview": "photostory-preview.png",
                    "order": 0
                }
            ],

            "action": [
                {% for action in actions %}
                    {
                        "id": "{{ action.id }}",
                        "groups": [
                            {% for group in action.mgroups.all %}
                                "{{ group.name }}",
                            {% endfor %}
                        ],
                        "action": "{{ action.action }}",
                        "params": {
                            "id": "{{ action.module_id }}",
                            "module": "{{ action.module }}"
                        },
                        "external_id": "{{ action.external_id }}"
                    },
                {% endfor %}
            ],

            "spider_graph" : [
                {% for evaluation in evaluations %}
                    {
                        "id": "{{ evaluation.evaluation_type.id }}",
                        "title": "{{ evaluation.name|escapejs }}",
                        "preview": "spidergraph-preview.png",
                        "module": "spider_graph",
                        "order": {{ evaluation.order }},
                        "groups": [
                            "trainer",
                            "trainee"
                        ],
                        "permissions": {
                            "candidate": "{{ evaluation.evaluation_type.candidate.name }}",
                            "moderator": "{{ evaluation.evaluation_type.moderators.name }}",
                            "evaluator": "{{ evaluation.evaluation_type.evaluators.name }}",
                            "auto_evaluator": "{{ evaluation.evaluation_type.auto_evaluators.name }}",
                            "observer": "{{ evaluation.evaluation_type.observers.name }}",
                            "auto_observer": "{{ evaluation.evaluation_type.auto_observers.name }}",
                        },
                        "module_settings": [
                            {
                                "id": "view1",
                                "key": "home",
                                "broadcastable":true,
                                "info": {
                                    "exercices": [
                                        {% for exercice in evaluation.evaluation_type.evaluationexercice_set.all %}
                                            {
                                                "id": "{{ exercice.id }}",
                                                "label": "{{ exercice.label|escapejs }}",
                                                "url": "{%if exercice.preview %}{{ exercice.preview.url }}{% endif %}",
                                                "default_image": "default-exercice-preview.png"
                                            },
                                        {% endfor %}
                                    ]
                                }
                            },
                            {
                                "id": "view2",
                                "key": "evaluation",
                                "broadcastable": true,
                                "info": {
                                    "exercices": [
                                        {% for exercice in evaluation.evaluation_type.evaluationexercice_set.all %}
                                            {
                                                "id": "{{ exercice.id }}",
                                                "title": "{{ exercice.label|escapejs }}",
                                                "form": [

                                                    {% for eval_num in exercice.evaluationcriterianumeric_set.all %}
                                                        {% if not eval_num.is_deleted %}
                                                            {
                                                                "id": "{{ eval_num.id }}",
                                                                "type": "numeric",
                                                                "label": "{{ eval_num.description|escapejs }}",
                                                                "default_value": {{ exercice.end_range }},
                                                                "max_value": {{ exercice.end_range }},
                                                                "min_value": {{ exercice.start_range }}
                                                            },
                                                        {% endif %}
                                                    {% endfor %}

                                                    {% for eval_ver in exercice.evaluationcriteriaverbatim_set.all %}
                                                        {% if not eval_ver.is_deleted %}
                                                            {
                                                                "id": "{{ eval_ver.id }}",
                                                                "type": "text",
                                                                "label": "{{ eval_ver.description|escapejs }}"
                                                                },
                                                            {% endif %}
                                                    {% endfor %}

                                                ]
                                            },
                                        {% endfor %}
                                    ]
                                }
                            },
                            {
                                "id": "view3",
                                "key": "result",
                                "broadcastable": true
                            }
                        ]
                    },
                {% endfor %}
            ]
        }
    }
}
