From a1aebfa54d00a50ba2df06f32f27dc1a84cf960a Mon Sep 17 00:00:00 2001 From: jebus Date: Thu, 31 Jul 2025 07:00:54 +1200 Subject: [PATCH] Model Building UI Flag (#39) Fixes #8 Flag only disables UI Elements Co-authored-by: Tim Lorsbach Reviewed-on: https://git.envipath.com/enviPath/enviPy/pulls/39 --- envipath/settings.py | 11 +++++++++++ epdb/views.py | 11 +++++++---- templates/actions/collections/model.html | 2 +- templates/modals/collections/new_model_modal.html | 6 +++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/envipath/settings.py b/envipath/settings.py index d891bb07..29fcca60 100644 --- a/envipath/settings.py +++ b/envipath/settings.py @@ -260,6 +260,8 @@ CELERY_RESULT_BACKEND = 'redis://localhost:6379/1' CELERY_ACCEPT_CONTENT = ['json'] CELERY_TASK_SERIALIZER = 'json' +MODEL_BUILDING_ENABLED = os.environ.get('MODEL_BUILDING_ENABLED', 'False') == 'True' + DEFAULT_RF_MODEL_PARAMS = { 'base_clf': RandomForestClassifier( n_estimators=100, @@ -312,3 +314,12 @@ if SENTRY_ENABLED: # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info send_default_pii=True, ) + +# compile into digestible flags +FLAGS = { + 'MODEL_BUILDING': MODEL_BUILDING_ENABLED, + 'CELERY': FLAG_CELERY_PRESENT, + 'PLUGINS': PLUGINS_ENABLED, + 'SENTRY': SENTRY_ENABLED, + 'ENVIFORMER': ENVIFORMER_PRESENT, +} diff --git a/epdb/views.py b/epdb/views.py index e635fad6..1477b762 100644 --- a/epdb/views.py +++ b/epdb/views.py @@ -158,7 +158,7 @@ def get_base_context(request, for_user=None) -> Dict[str, Any]: 'writeable_packages': PackageManager.get_all_writeable_packages(current_user), 'available_groups': GroupManager.get_groups(current_user), 'available_settings': SettingManager.get_all_settings(current_user), - 'enabled_features': [], + 'enabled_features': s.FLAGS, 'debug': s.DEBUG, }, } @@ -572,11 +572,14 @@ def package_models(request, package_uuid): context['model_types'] = { 'ML Relative Reasoning': 'ml-relative-reasoning', 'Rule Based Relative Reasoning': 'rule-based-relative-reasoning', - 'EnviFormer': 'enviformer', } - for k, v in s.CLASSIFIER_PLUGINS.items(): - context['model_types'][v.display()] = k + if s.FLAGS.get('ENVIFORMER', False): + context['model_types']['EnviFormer'] = 'enviformer' + + if s.FLAGS.get('PLUGINS', False): + for k, v in s.CLASSIFIER_PLUGINS.items(): + context['model_types'][v.display()] = k return render(request, 'collections/objects_list.html', context) diff --git a/templates/actions/collections/model.html b/templates/actions/collections/model.html index a384080b..94d1a952 100644 --- a/templates/actions/collections/model.html +++ b/templates/actions/collections/model.html @@ -1,4 +1,4 @@ -{% if meta.can_edit %} +{% if meta.can_edit and meta.enabled_features.MODEL_BUILDING %}
  • New Model diff --git a/templates/modals/collections/new_model_modal.html b/templates/modals/collections/new_model_modal.html index 628a6b0c..1d23d58e 100644 --- a/templates/modals/collections/new_model_modal.html +++ b/templates/modals/collections/new_model_modal.html @@ -77,7 +77,7 @@ class="form-control"> - {% if 'plugins' in meta.enabled_features %} + {% if meta.enabled_features.PLUGINS %} @@ -122,7 +122,7 @@ name="enviformer-threshold" class="form-control"> - {% if 'applicability_domain' in enabled_features %} + {% if meta.enabled_features.APPLICABILITY_DOMAIN %}