Fixed count & added new vars to service pools name

This commit is contained in:
Adolfo Gómez García 2021-01-28 13:56:57 +01:00
parent 80bd2c2f9c
commit 04d0acb17e
2 changed files with 7 additions and 5 deletions

View File

@ -450,8 +450,8 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
state=states.servicePool.ACTIVE, state=states.servicePool.ACTIVE,
visible=True visible=True
) )
.annotate(pubs_active=models.Count('publications', filter=models.Q(publications__state=states.publication.USABLE))) .annotate(pubs_active=models.Count('publications', filter=models.Q(publications__state=states.publication.USABLE), distinct=True))
.annotate(usage_count=models.Count('userServices', filter=models.Q(userServices__state__in=states.userService.VALID_STATES, userServices__cache_level=0))) .annotate(usage_count=models.Count('userServices', filter=models.Q(userServices__state__in=states.userService.VALID_STATES, userServices__cache_level=0), distinct=True))
.prefetch_related( .prefetch_related(
'transports', 'transports',
'transports__networks', 'transports__networks',

View File

@ -151,7 +151,9 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: #
if svr.is_meta: if svr.is_meta:
continue continue
use = str(svr.usage(svr.usage_count)) + '%' use_percent = str(svr.usage(svr.usage_count)) + '%'
use_count = str(svr.usage_count)
left_count = str(svr.max_srvs - svr.usage_count)
trans = [] trans = []
for t in sorted(svr.transports.all(), key=lambda x: x.priority): # In memory sort, allows reuse prefetched and not too big array for t in sorted(svr.transports.all(), key=lambda x: x.priority): # In memory sort, allows reuse prefetched and not too big array
@ -200,12 +202,12 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: #
else: else:
toBeReplacedTxt = '' toBeReplacedTxt = ''
datator = lambda x: x.replace('{use}', use).replace('{total}', str(svr.max_srvs)) datator = lambda x: x.replace('{use}', use_percent).replace('{total}', str(svr.max_srvs)).replace('{usec}', use_count).replace('{left}', left_count)
services.append({ services.append({
'id': 'F' + svr.uuid, 'id': 'F' + svr.uuid,
'name': datator(svr.name), 'name': datator(svr.name),
'visual_name': datator(svr.visual_name.replace('{use}', use).replace('{total}', str(svr.max_srvs))), 'visual_name': datator(svr.visual_name.replace('{use}', use_percent).replace('{total}', str(svr.max_srvs))),
'description': svr.comments, 'description': svr.comments,
'group': group, 'group': group,
'transports': trans, 'transports': trans,