diff --git a/dockerize/Makefile b/dockerize/Makefile index c5436bf7..8a34cac3 100644 --- a/dockerize/Makefile +++ b/dockerize/Makefile @@ -236,4 +236,12 @@ dbseed: @echo "------------------------------------------------------------------" @echo "Seed db with JSON data from /fixtures/*.json" @echo "------------------------------------------------------------------" - @docker compose -p $(PROJECT_ID) exec devweb bash -c 'python manage.py loaddata fixtures/*.json' \ No newline at end of file + @docker compose -p $(PROJECT_ID) exec devweb bash -c 'python manage.py loaddata fixtures/*.json' + +loadmenu: + @echo + @echo "------------------------------------------------------------------" + @echo "Delete all simplemenu entries and load from fixtures/simplemenu.json" + @echo "------------------------------------------------------------------" + @docker compose -p $(PROJECT_ID) devweb python manage.py clear_simplemenu + @docker compose -p $(PROJECT_ID) devweb python manage.py loaddata fixtures/simplemenu.json \ No newline at end of file diff --git a/dockerize/README.md b/dockerize/README.md index aa59cea4..050bfa26 100644 --- a/dockerize/README.md +++ b/dockerize/README.md @@ -179,3 +179,7 @@ make devweb-runserver make dbseed ``` +- **loadmenu:** Clear all menu entries and load menu from JSON file at `fixtures/simplemenu.json`. +```sh +make loadmenu +``` \ No newline at end of file diff --git a/qgis-app/plugins/management/commands/clear_simplemenu.py b/qgis-app/plugins/management/commands/clear_simplemenu.py new file mode 100644 index 00000000..d95a632d --- /dev/null +++ b/qgis-app/plugins/management/commands/clear_simplemenu.py @@ -0,0 +1,18 @@ +from django.core.management.base import BaseCommand +from django.apps import apps + +class Command(BaseCommand): + help = 'Delete all objects from all models in the simplemenu app' + + def handle(self, *args, **kwargs): + # Get all models in the 'simplemenu' app + app_models = apps.get_app_config('simplemenu').get_models() + + for model in app_models: + # Delete all objects in the model + model_name = model.__name__ + try: + deleted_count, _ = model.objects.all().delete() + self.stdout.write(f'Successfully deleted {deleted_count} objects from {model_name}.') + except Exception as e: + self.stderr.write(f'Failed to delete objects from {model_name}: {str(e)}') \ No newline at end of file diff --git a/qgis-app/plugins/templates/plugins/plugin_base.html b/qgis-app/plugins/templates/plugins/plugin_base.html index aff6c458..184178d0 100644 --- a/qgis-app/plugins/templates/plugins/plugin_base.html +++ b/qgis-app/plugins/templates/plugins/plugin_base.html @@ -11,111 +11,7 @@