musicias show_history basic

This commit is contained in:
Jorge Pastor 2024-08-09 13:21:01 +02:00
parent 081b094a3d
commit 4ff5abe8f6
3 changed files with 35 additions and 7 deletions

View file

@ -38,8 +38,18 @@
<ul class="list-group">
{% for name, obj_data in account.objects.items %}
<li class="list-group-item d-flex justify-content-between align-items-center">
{{ name }}
<span class="badge badge-primary badge-pill">{{ obj_data.ac.used }} {{ obj_data.ac.unit }}</span>
<div class="row w-100 justify-content-between">
<div class="col-4">
{{ name }}
</div>
<div class="col-4 text-center">
<a href="{% url 'musician:dashboard-history' obj_data.ac.id %}" target="_blank">Show history <i class="fas fa-clock"></i></a>
</div>
<div class="col-3"></div>
<div class="col-1">
<span class="badge badge-primary badge-pill">{{ obj_data.ac.used }} {{ obj_data.ac.unit }}</span>
</div>
</div>
</li>
{% endfor %}
</ul>

View file

@ -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/<int:pk>/', views.HistoryDataView.as_view(), name='dashboard-historydata'),
path('dashboard/history/<int:pk>/', views.HistoryView.as_view(), name='dashboard-history'),
path('domains/', views.DomainListView.as_view(), name='domain-list'),
path('domains/<int:pk>/', views.DomainDetailView.as_view(), name='domain-detail'),

View file

@ -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')