From 27dff192f2a208658c6a51de8b9504b39549ebec Mon Sep 17 00:00:00 2001 From: pierre geeraert Date: Tue, 31 Mar 2026 00:25:56 +0100 Subject: [PATCH] now the template adapt depending of the data and tries ajax button without success --- django_code/cloudmanager/apps.py | 9 +- django_code/cloudmanager/templates/index.html | 110 ++++++++---------- django_code/cloudmanager/views.py | 9 ++ django_code/django_code/urls.py | 5 +- 4 files changed, 66 insertions(+), 67 deletions(-) create mode 100644 django_code/cloudmanager/views.py diff --git a/django_code/cloudmanager/apps.py b/django_code/cloudmanager/apps.py index 34324fd..91df9ae 100644 --- a/django_code/cloudmanager/apps.py +++ b/django_code/cloudmanager/apps.py @@ -6,8 +6,13 @@ import psycopg2 from cloudmanager.db_interaction import DB_generation,Check_server_supposed_XXX,Give_current_weekday,Give_current_hour def hello(request): - return render(request, 'index.html', {}) + list_schedule = ['schedule1','schedule2'] + list_servers_up = [['wiki', 'wikijs', 2], ['book', 'bookstack-db', 1]] + return render(request, 'index.html', {'list_schedule':list_schedule,'list_servers_up':list_servers_up}) +def print(request): + print("Im here") + return 0 def redirect(request): db_host = os.environ.get('DB_HOST') db_port = os.environ.get('DB_PORT') @@ -20,6 +25,6 @@ def redirect(request): ## Server(s) supposed to be UP list_servers_up = Check_server_supposed_XXX(generated_db, "up", Give_current_hour(),Give_current_weekday()) - + print(list_servers_up) return render(request, 'cmm_blank_page.html', {'list_servers_up':list_servers_up}) diff --git a/django_code/cloudmanager/templates/index.html b/django_code/cloudmanager/templates/index.html index 3e6fd92..0edb4a8 100644 --- a/django_code/cloudmanager/templates/index.html +++ b/django_code/cloudmanager/templates/index.html @@ -218,78 +218,60 @@
- -
-
-

Starter

-
- -
- $19/m -
    -
  • Up to 3 Users
  • -
  • Max 30 items
  • -
  • Unlimited QueriesFull
  • -
  • Statistics
  • -
  • Great Support
  • -
- Get This Plan -
-
+ {% block contentX %} + {% for server in list_servers_up %}
-

Medium

+

{{ server.1 }}

- -
- $69/m + +
+ {{ server.2 }}
    -
  • Up to 5 Users
  • -
  • Max 50 items
  • -
  • Unlimited QueriesFull
  • -
  • Statistics
  • -
  • Great Support
  • -
- Get This Plan -
-
- -
- -
- -
-
-

Professional

-
- -
- $120/m -
    -
  • Up to 100 Users
  • -
  • Max 500 items
  • -
  • Unlimited QueriesFull
  • -
  • Statistics
  • -
  • Great Support
  • -
+
  • Up to 5 Users
  • +
  • Max 50 items
  • +
  • Unlimited QueriesFull
  • +
  • Statistics
  • +
  • Great Support
  • + Get This Plan + + + + + + +
    +
    +
    + {% endfor %} + {% endblock %} + +
    diff --git a/django_code/cloudmanager/views.py b/django_code/cloudmanager/views.py new file mode 100644 index 0000000..616e7e0 --- /dev/null +++ b/django_code/cloudmanager/views.py @@ -0,0 +1,9 @@ +from django.http import HttpResponse + +def trigger_my_action(request): + # 1. Run your Django module/function + result = "1" + print('here') + # 2. Return ONLY the HTML fragment you want to show on the page + # This will replace the content inside the "hx-target" div + return HttpResponse("Done!") \ No newline at end of file diff --git a/django_code/django_code/urls.py b/django_code/django_code/urls.py index 6fb762c..b847d70 100644 --- a/django_code/django_code/urls.py +++ b/django_code/django_code/urls.py @@ -17,7 +17,8 @@ Including another URLconf from django.contrib import admin from django.urls import path from cloudmanager import (credentials,db_interaction) -from cloudmanager import apps as cloudmanager_apps +from cloudmanager import apps as cloudmanager_apps +from cloudmanager import views as cloudmanager_views from random_simpsons import apps as random_simpsons from paperless_django import apps as paperless_django from onenote import apps as onenote @@ -92,6 +93,8 @@ urlpatterns = [ ################### cloudmanager ################### path('cmm/', cloudmanager_apps.redirect), path('cmm/hello', cloudmanager_apps.hello), + path('cmm/print', cloudmanager_apps.print), + path('cmm/run-action/', cloudmanager_views.trigger_my_action, name='run_my_action_url'), path('cmm/main/', db_interaction.main), ]