From 4ff5abe8f6d3972871f5c97f781341eccfbc7279 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Fri, 9 Aug 2024 13:21:01 +0200 Subject: [PATCH] musicias show_history basic --- .../templates/musician/dashboard.html | 14 ++++++++-- orchestra/contrib/musician/urls.py | 2 ++ orchestra/contrib/musician/views.py | 26 +++++++++++++++---- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/orchestra/contrib/musician/templates/musician/dashboard.html b/orchestra/contrib/musician/templates/musician/dashboard.html index e2b9cfa2..3b52ea36 100644 --- a/orchestra/contrib/musician/templates/musician/dashboard.html +++ b/orchestra/contrib/musician/templates/musician/dashboard.html @@ -38,8 +38,18 @@ diff --git a/orchestra/contrib/musician/urls.py b/orchestra/contrib/musician/urls.py index 949ac879..42fe9e18 100644 --- a/orchestra/contrib/musician/urls.py +++ b/orchestra/contrib/musician/urls.py @@ -17,6 +17,8 @@ urlpatterns = [ path('auth/login/', views.LoginView.as_view(), name='login'), path('auth/logout/', views.LogoutView.as_view(), name='logout'), path('dashboard/', views.DashboardView.as_view(), name='dashboard'), + path('dashboard/historydata//', views.HistoryDataView.as_view(), name='dashboard-historydata'), + path('dashboard/history//', views.HistoryView.as_view(), name='dashboard-history'), path('domains/', views.DomainListView.as_view(), name='domain-list'), path('domains//', views.DomainDetailView.as_view(), name='domain-detail'), diff --git a/orchestra/contrib/musician/views.py b/orchestra/contrib/musician/views.py index b25ffc27..084ea198 100644 --- a/orchestra/contrib/musician/views.py +++ b/orchestra/contrib/musician/views.py @@ -10,7 +10,7 @@ from django.db.models import Value from django.db.models.functions import Concat from django.http import (HttpResponse, HttpResponseNotFound, HttpResponseRedirect) -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, render from django.urls import reverse_lazy from django.utils import translation from django.utils.html import format_html @@ -59,6 +59,26 @@ from .lists.views import * logger = logging.getLogger(__name__) +import json +from urllib.parse import parse_qs +from orchestra.contrib.resources.helpers import get_history_data + + +class HistoryView(View): + def get(self, request, pk, *args, **kwargs): + context = { + 'ids': pk + } + return render(request, "musician/history.html", context) + + +class HistoryDataView(View): + def get(self, request, pk, *args, **kwargs): + ids = [pk] + queryset = ResourceData.objects.filter(id__in=ids) + history = get_history_data(queryset) + response = json.dumps(history, indent=4) + return HttpResponse(response, content_type="application/json") class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): @@ -76,10 +96,6 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): account = related_resources.filter(resource_id__verbose_name='account-disk').first() account_trafic = related_resources.filter(resource_id__verbose_name='account-traffic').first() - # TODO: sacar los graficos de alguna manera - # url_history_disk = reverse('admin:resources_resourcedata_show_history', args=(account.pk,)) - # url_history_traffic = reverse('admin:resources_resourcedata_show_history', args=(account_trafic.pk,)) - mailboxes = related_resources.filter(resource_id__verbose_name='mailbox-disk') lists = related_resources.filter(resource_id__verbose_name='list-traffic') databases = related_resources.filter(resource_id__verbose_name='database-disk')