From c27a895d59bd1c577f9130fdf5deaabeae9e4959 Mon Sep 17 00:00:00 2001 From: Alexis Koralewski Date: Wed, 13 Oct 2021 15:14:46 +0200 Subject: [PATCH] add display of raw config file for devices, generic_devices and components on the device_detail page --- src/core/pyros_django/obsconfig/templates/obsconfig/device_details.html | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------- src/core/pyros_django/obsconfig/urls.py | 5 ++++- src/core/pyros_django/obsconfig/views.py | 40 +++++++++++++++++++++++++++++++++++++--- src/core/pyros_django/pyros/settings.py | 2 +- 4 files changed, 177 insertions(+), 81 deletions(-) diff --git a/src/core/pyros_django/obsconfig/templates/obsconfig/device_details.html b/src/core/pyros_django/obsconfig/templates/obsconfig/device_details.html index 8659100..71e1516 100644 --- a/src/core/pyros_django/obsconfig/templates/obsconfig/device_details.html +++ b/src/core/pyros_django/obsconfig/templates/obsconfig/device_details.html @@ -15,8 +15,10 @@ th,td{ {% with device_detail|get_item:"name" as device_name %} {% for key,value in device_detail.items %}
- - {% if key == "device_config" %} + {% if key == "file" %} +

{{ key }} : {{ value }}

+ + {% elif key == "device_config" %} {% with device_detail|get_item:key as device_config %} {% for key,value in device_config.items %} @@ -27,11 +29,13 @@ th,td{ {% with element|get_item:"file" as attached_device_file %} - {% with file_name_to_device_name|get_item:attached_device_file as attached_device %} -

{{ attached_device }} is attached to this device

- {% endwith %} + {% with file_name_to_device_name|get_item:attached_device_file as attached_device %} +

{{ attached_device }} is attached to this device

+ {% endwith %} {% endwith %} {% endfor %} + {% elif key == "generic" %} +

{{ key }} : {{ value }}

{% else %}

{{ key }} : {{ value }}

{% endif %} @@ -65,94 +69,149 @@ th,td{ {% endif %} {% if capabilities %} - Capabilities : +

Capabilities :

{% endfor %} {% endif %} {% endwith %} + +{# modal for displaying raw yaml files #} + + + + {% endblock %} \ No newline at end of file diff --git a/src/core/pyros_django/obsconfig/urls.py b/src/core/pyros_django/obsconfig/urls.py index 57b240e..4335d8a 100644 --- a/src/core/pyros_django/obsconfig/urls.py +++ b/src/core/pyros_django/obsconfig/urls.py @@ -11,5 +11,8 @@ urlpatterns = [ path('device_details/', views.device_details, name='device_details'), path('edit_config',views.edit_config,name="edit_config"), path('verify_config',views.verify_config,name="verify_config"), - path('save_config',views.save_config,name="save_config") + path('save_config',views.save_config,name="save_config"), + path("view_raw_component_config_file",views.view_raw_component_config_file,name="view_raw_component_config_file"), + path("view_raw_device_config_file",views.view_raw_device_config_file,name="view_raw_device_config_file"), + path("view_raw_generic_device_config_file",views.view_raw_generic_device_config_file,name="view_raw_generic_device_config_file"), ] \ No newline at end of file diff --git a/src/core/pyros_django/obsconfig/views.py b/src/core/pyros_django/obsconfig/views.py index 541230e..2404bfb 100644 --- a/src/core/pyros_django/obsconfig/views.py +++ b/src/core/pyros_django/obsconfig/views.py @@ -6,6 +6,7 @@ from src.core.pyros_django.dashboard.decorator import level_required from django.contrib.auth.decorators import login_required from django.http import HttpResponse from datetime import datetime +from django.views.decorators.csrf import csrf_exempt import re, yaml,tempfile,json,os def get_nested_dictionaries_as_list(dic,result=[]): @@ -98,7 +99,7 @@ def computer_details(request,computer_name): @login_required -@level_required("Admin","Unit-PI","Operator","Observer") +@level_required("Admin","Unit-PI","Unit-board","Operator","Observer") def device_details(request,device_name): config = ConfigPyros(os.environ["PATH_TO_OBSCONF_FILE"]) # We're removing "_" at the beginning of each key : @@ -117,7 +118,6 @@ def device_details(request,device_name): device_detail = { re.sub("^_","",key):value for key,value in config.get_devices()[device_name].items()} - #test_device= get_nested_dictionaries_as_list(device_detail,[]) if config.get_device_power(device_name) is not None: @@ -282,4 +282,38 @@ def save_config(request): obs_config_file.write(request.POST.get("config")) - return HttpResponse("Ok !") \ No newline at end of file + return HttpResponse("Ok !") + +@login_required +@level_required("Admin","Unit-PI","Unit-board","Operator","Observer") +@csrf_exempt +def view_raw_component_config_file(request): + COMPONENT_PATH = os.path.join(os.environ["DJANGO_PATH"],"../../../config/components/") + + if request.POST: + try: + yaml_file = open(COMPONENT_PATH+request.POST["yaml_file"]) + content = yaml_file.readlines() + except: + content = "Component defined within the device configuration file" + return HttpResponse(content) + +@login_required +@level_required("Admin","Unit-PI","Unit-board","Operator","Observer") +@csrf_exempt +def view_raw_generic_device_config_file(request): + GENERIC_DEVICES_PATH = os.path.join(os.environ["DJANGO_PATH"],"../../../config/devices/") + if request.POST: + yaml_file = open(GENERIC_DEVICES_PATH+request.POST["yaml_file"]) + content = yaml_file.readlines() + return HttpResponse(content) + +@login_required +@level_required("Admin","Unit-PI","Unit-board","Operator","Observer") +@csrf_exempt +def view_raw_device_config_file(request): + obs_folder = os.environ["PATH_TO_OBSCONF_FOLDER"] + if request.POST: + yaml_file = open(obs_folder+request.POST["yaml_file"]) + content = yaml_file.readlines() + return HttpResponse(content) \ No newline at end of file diff --git a/src/core/pyros_django/pyros/settings.py b/src/core/pyros_django/pyros/settings.py index 76fe117..e4c43fc 100644 --- a/src/core/pyros_django/pyros/settings.py +++ b/src/core/pyros_django/pyros/settings.py @@ -401,5 +401,5 @@ python_version = subprocess.run( "python --version | cut -d ' ' -f 2 | cut -d '. python_version = python_version.stdout today = datetime.utcnow().date() django_version_major,django_version_minor = django.VERSION[:2][0],django.VERSION[:2][1] -pyros_version = "0.2.6.0" +pyros_version = "0.2.7.0" VERSION_NUMBER = f"{pyros_version}_{django_version_major}.{django_version_minor}_{python_version}_{today}" \ No newline at end of file -- libgit2 0.21.2