musicias show_history
This commit is contained in:
parent
14ff506a0d
commit
20bcb83c83
Binary file not shown.
|
@ -318,6 +318,10 @@ msgstr "És el primer cop que accedeixes, et donem la benvinguda!"
|
||||||
msgid " The disk space of resources is updated weekly "
|
msgid " The disk space of resources is updated weekly "
|
||||||
msgstr "L'espai en disc dels recursos es va actualitzant setmanalment."
|
msgstr "L'espai en disc dels recursos es va actualitzant setmanalment."
|
||||||
|
|
||||||
|
#: templates/musician/dashboard.html:47
|
||||||
|
msgid "Show history"
|
||||||
|
msgstr "Mostrar historial"
|
||||||
|
|
||||||
#: templates/musician/database_list.html:21
|
#: templates/musician/database_list.html:21
|
||||||
#: templates/musician/mailbox_list.html:30 templates/musician/saas_list.html:19
|
#: templates/musician/mailbox_list.html:30 templates/musician/saas_list.html:19
|
||||||
#: templates/musician/webapps/webapp_list.html:25
|
#: templates/musician/webapps/webapp_list.html:25
|
||||||
|
|
Binary file not shown.
|
@ -320,6 +320,10 @@ msgstr "Es la primera vez que accedes: ¡te damos la bienvenida!"
|
||||||
msgid " The disk space of resources is updated weekly "
|
msgid " The disk space of resources is updated weekly "
|
||||||
msgstr "El espacio en disco de los recursos se actualiza semanalmente"
|
msgstr "El espacio en disco de los recursos se actualiza semanalmente"
|
||||||
|
|
||||||
|
#: templates/musician/dashboard.html:47
|
||||||
|
msgid "Show history"
|
||||||
|
msgstr "Mostrar historial"
|
||||||
|
|
||||||
#: templates/musician/database_list.html:21
|
#: templates/musician/database_list.html:21
|
||||||
#: templates/musician/mailbox_list.html:30 templates/musician/saas_list.html:19
|
#: templates/musician/mailbox_list.html:30 templates/musician/saas_list.html:19
|
||||||
#: templates/musician/webapps/webapp_list.html:25
|
#: templates/musician/webapps/webapp_list.html:25
|
||||||
|
|
|
@ -37,20 +37,22 @@
|
||||||
</div>
|
</div>
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{% for name, obj_data in account.objects.items %}
|
{% for name, obj_data in account.objects.items %}
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
{% if obj_data.ac != None %}
|
||||||
<div class="row w-100 justify-content-between">
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
<div class="col-4">
|
<div class="row w-100 justify-content-between">
|
||||||
{{ name }}
|
<div class="col-4">
|
||||||
|
{{ name }}
|
||||||
|
</div>
|
||||||
|
<div class="col-4 text-center">
|
||||||
|
<a href="{% url 'musician:dashboard-history' obj_data.ac.id %}" target="_blank">{% trans "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>
|
</div>
|
||||||
<div class="col-4 text-center">
|
</li>
|
||||||
<a href="{% url 'musician:dashboard-history' obj_data.ac.id %}" target="_blank">Show history <i class="fas fa-clock"></i></a>
|
{% endif %}
|
||||||
</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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -62,17 +62,48 @@ logger = logging.getLogger(__name__)
|
||||||
import json
|
import json
|
||||||
from urllib.parse import parse_qs
|
from urllib.parse import parse_qs
|
||||||
from orchestra.contrib.resources.helpers import get_history_data
|
from orchestra.contrib.resources.helpers import get_history_data
|
||||||
|
from django.http import HttpResponseNotFound, Http404
|
||||||
|
|
||||||
|
class HistoryView(CustomContextMixin, UserTokenRequiredMixin, View):
|
||||||
|
|
||||||
|
def get_object(self, pk):
|
||||||
|
related_resources = self.get_all_resources()
|
||||||
|
|
||||||
|
account = related_resources.filter(resource_id__verbose_name='account-disk').first()
|
||||||
|
account_trafic = related_resources.filter(resource_id__verbose_name='account-traffic').first()
|
||||||
|
account = getattr(account, "id", False) == pk
|
||||||
|
account_trafic = getattr(account_trafic, "id", False) == pk
|
||||||
|
if account == False and account_trafic == False:
|
||||||
|
raise Http404(f"Resource with id {pk} does not exist")
|
||||||
|
|
||||||
|
|
||||||
class HistoryView(View):
|
|
||||||
def get(self, request, pk, *args, **kwargs):
|
def get(self, request, pk, *args, **kwargs):
|
||||||
context = {
|
context = {
|
||||||
'ids': pk
|
'ids': pk
|
||||||
}
|
}
|
||||||
|
self.get_object(pk)
|
||||||
return render(request, "musician/history.html", context)
|
return render(request, "musician/history.html", context)
|
||||||
|
|
||||||
|
# TODO: funcion de dashborad, mirar como no repetir esta funcion
|
||||||
|
def get_all_resources(self):
|
||||||
|
user = self.request.user
|
||||||
|
resources = Resource.objects.select_related('content_type')
|
||||||
|
resource_models = {r.content_type.model_class(): r.content_type_id for r in resources}
|
||||||
|
ct_id = resource_models[user._meta.model]
|
||||||
|
qset = Q(content_type_id=ct_id, object_id=user.id, resource__is_active=True)
|
||||||
|
for field, rel in user._meta.fields_map.items():
|
||||||
|
try:
|
||||||
|
ct_id = resource_models[rel.related_model]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
manager = getattr(user, field)
|
||||||
|
ids = manager.values_list('id', flat=True)
|
||||||
|
qset = Q(qset) | Q(content_type_id=ct_id, object_id__in=ids, resource__is_active=True)
|
||||||
|
return ResourceData.objects.filter(qset)
|
||||||
|
|
||||||
class HistoryDataView(View):
|
|
||||||
|
class HistoryDataView(CustomContextMixin, UserTokenRequiredMixin, View):
|
||||||
def get(self, request, pk, *args, **kwargs):
|
def get(self, request, pk, *args, **kwargs):
|
||||||
ids = [pk]
|
ids = [pk]
|
||||||
queryset = ResourceData.objects.filter(id__in=ids)
|
queryset = ResourceData.objects.filter(id__in=ids)
|
||||||
|
@ -111,7 +142,6 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
|
||||||
|
|
||||||
# TODO(@slamora) update when backend provides resource usage data
|
# TODO(@slamora) update when backend provides resource usage data
|
||||||
resource_usage = {
|
resource_usage = {
|
||||||
# 'account': self.get_account_usage(profile_type, account),
|
|
||||||
'mailbox': self.get_resource_usage(profile_type, mailboxes, 'mailbox'),
|
'mailbox': self.get_resource_usage(profile_type, mailboxes, 'mailbox'),
|
||||||
'database': self.get_resource_usage(profile_type, databases, 'database'),
|
'database': self.get_resource_usage(profile_type, databases, 'database'),
|
||||||
'nextcloud': self.get_resource_usage(profile_type, nextcloud, 'nextcloud'),
|
'nextcloud': self.get_resource_usage(profile_type, nextcloud, 'nextcloud'),
|
||||||
|
@ -184,15 +214,19 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_account_usage(self, profile_type, account, account_trafic):
|
def get_account_usage(self, profile_type, account, account_trafic):
|
||||||
|
total_size = 0
|
||||||
|
if account != None and getattr(account, "used") != None:
|
||||||
|
total_size = account.used
|
||||||
|
|
||||||
allowed_size = ALLOWED_RESOURCES[profile_type]['account']
|
allowed_size = ALLOWED_RESOURCES[profile_type]['account']
|
||||||
total_size = account.used
|
|
||||||
size_left = allowed_size - total_size
|
size_left = allowed_size - total_size
|
||||||
|
unit = account.unit if account != None else "GiB"
|
||||||
|
|
||||||
alert = ''
|
alert = ''
|
||||||
if size_left < 0:
|
if size_left < 0:
|
||||||
alert = format_html(f"<span class='text-danger'>{size_left * -1} {account.unit} extra</span>")
|
alert = format_html(f"<span class='text-danger'>{size_left * -1} {unit} extra</span>")
|
||||||
elif size_left <= 1:
|
elif size_left <= 1:
|
||||||
alert = format_html(f"<span class='text-warning'>{size_left} {account.unit} available</span>")
|
alert = format_html(f"<span class='text-warning'>{size_left} {unit} available</span>")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'verbose_name': _('Account'),
|
'verbose_name': _('Account'),
|
||||||
|
|
Loading…
Reference in a new issue