This script processes a solution.json
file and combines the menus
key from multiple module JSON files to build a complete menu structure (TO-DO: generation of openimis.json and merging roles to apply them in migration). The resulting menu is sorted by position
at both the menu and submenu levels. The script outputs a new file named generated-menu.json
containing the combined and sorted menu structure. This file can be pasted as a part of fe-core
configuration. It can be changed either on database level or in django administration panel as superuser.
How It Works
Input File:
The script reads
solution.json
from the current working directory.The
solution.json
file should have amodules
key containing a list of module file names (e.g.,client-management.json
,user-management.json
, etc.).
Module Files:
Each module file listed under the
modules
key should be present in the same directory assolution.json
.Each module file should contain a
menus
key, which defines its menu structure.
Combining Menus:
The script reads all the module files, extracts their
menus
, and combines them.Both menus and their submenus are sorted by the
position
field.
Missing Files:
If any module file is missing, the script will print a warning but will continue processing the rest.
Output File:
The script generates a
generated-solution.json
file in the same directory as the input files. This file contains the combined and sorted menu structure.
How to Use
Prerequisites
Python 3.x installed on your system.
Steps
Prepare
solution.json
:Create a file named
solution.json
in the directory where you will run the script.Add a
modules
key listing all the module files you want to include. Example:Code Block { "modules": [ "client-management.json", "user-management.json", "grievance.json", "social-protection.json", "core.json" ] }
Prepare Module Files:
Place all the module files listed in
solution.json
in the same directory. Each file should have a structure similar to the example below:Code Block { "menus": [ { "position": 1, "id": "MainMenu", "name": "Main", "icon": "main-icon", "description": "Main menu", "submenus": [ { "position": 1, "id": "submenu1" }, { "position": 2, "id": "submenu2" } ] } ] }
Run the Script:
Save the script as
menu_builder.py
in the same directory assolution.json
and the module files.Open a terminal or command prompt and navigate to the directory.
Run the script using the command:
Code Block python menu_builder.py
View the Output:
After the script completes, a new file named
generated-solution.json
will be created in the same directory.This file contains the combined and sorted menu structure.
Example Directory Structure
Code Block |
---|
/solution |-- solution.json |-- client-management.json |-- user-management.json |-- grievance.json |-- social-protection.json |-- core.json |-- menu_builder.py |
Notes
Ensure all files are properly formatted JSON.
Missing or malformed files will result in warnings but will not stop the script.
Customize the
solution.json
file to include or exclude specific modules based on your requirements.Repository: https://github.com/openimis/solution-builder
Script: https://github.com/openimis/solution-builder/blob/feature/OSB-18/solution/build_solution.py
...