forked from shaba/openuds
More improvements on getServices
This commit is contained in:
parent
fcea278d2f
commit
e0a512eefb
@ -304,7 +304,6 @@ class UserServiceManager:
|
||||
return None
|
||||
|
||||
def getAssignationForUser(self, servicePool: ServicePool, user: User) -> typing.Optional[UserService]: # pylint: disable=too-many-branches
|
||||
|
||||
if servicePool.service.getInstance().spawnsNew is False:
|
||||
assignedUserService = self.getExistingAssignationForUser(servicePool, user)
|
||||
else:
|
||||
|
@ -30,13 +30,11 @@
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from . import action
|
||||
from . import common
|
||||
from . import group
|
||||
from . import process
|
||||
from . import publication
|
||||
from . import userService
|
||||
from . import servicePool
|
||||
from . import user_service as userService
|
||||
from . import service_pool as servicePool
|
||||
from . import task
|
||||
|
@ -32,5 +32,5 @@
|
||||
"""
|
||||
|
||||
# pylint: disable=unused-import
|
||||
from .common import ACTIVE, REMOVABLE, REMOVING, REMOVED, INFO_STATES, VALID_STATES # @UnusedImport
|
||||
from .common import ACTIVE, REMOVABLE, REMOVING, REMOVED # @UnusedImport
|
||||
|
@ -32,4 +32,4 @@
|
||||
"""
|
||||
|
||||
# pylint: disable=unused-import
|
||||
from .common import ERROR, USABLE, PREPARING, REMOVABLE, REMOVING, REMOVED # @UnusedImport
|
||||
from .common import ERROR, USABLE, PREPARING, REMOVABLE, REMOVING, REMOVED, INFO_STATES, VALID_STATES # @UnusedImport
|
@ -169,11 +169,12 @@ class MetaPool(UUIDModel, TaggingMixin): # type: ignore
|
||||
)
|
||||
if user:
|
||||
meta = meta.annotate(
|
||||
number_assignations=models.Count(
|
||||
number_in_use=models.Count(
|
||||
'pools__userServices',
|
||||
filter=models.Q(
|
||||
pools__userServices__user=user,
|
||||
pools__userServices__in_use=True
|
||||
pools__userServices__in_use=True,
|
||||
pools__userServices__state__in=states.userService.USABLE
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -490,16 +490,20 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
|
||||
)
|
||||
if user: # Optimize loading if there is some assgned service..
|
||||
list1 = list1.annotate(
|
||||
number_assignations=models.Count(
|
||||
number_in_use=models.Count(
|
||||
'userServices', filter=models.Q(
|
||||
userServices__user=user, userServices__in_use=True
|
||||
userServices__user=user,
|
||||
userServices__in_use=True,
|
||||
userServices__state__in=states.userService.USABLE
|
||||
)
|
||||
)
|
||||
)
|
||||
list2 = list2.annotate(
|
||||
number_assignations=models.Count(
|
||||
number_in_use=models.Count(
|
||||
'userServices', filter=models.Q(
|
||||
userServices__user=user, userServices__in_use=True
|
||||
userServices__user=user,
|
||||
userServices__in_use=True,
|
||||
userServices__state__in=states.userService.USABLE
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -97,7 +97,7 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: #
|
||||
for meta in availMetaPools:
|
||||
# Check that we have access to at least one transport on some of its children
|
||||
hasUsablePools = False
|
||||
in_use = False
|
||||
in_use = meta.number_in_use > 0 # False
|
||||
for pool in meta.pools.all():
|
||||
# if pool.isInMaintenance():
|
||||
# continue
|
||||
@ -107,10 +107,10 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: #
|
||||
hasUsablePools = True
|
||||
break
|
||||
|
||||
if not in_use and meta.number_assignations: # Only look for assignation on possible used
|
||||
assignedUserService = userServiceManager().getExistingAssignationForUser(pool, request.user)
|
||||
if assignedUserService:
|
||||
in_use = assignedUserService.in_use
|
||||
# if not in_use and meta.number_in_use: # Only look for assignation on possible used
|
||||
# assignedUserService = userServiceManager().getExistingAssignationForUser(pool, request.user)
|
||||
# if assignedUserService:
|
||||
# in_use = assignedUserService.in_use
|
||||
|
||||
# Stop when 1 usable pool is found
|
||||
if hasUsablePools:
|
||||
@ -180,20 +180,21 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: #
|
||||
imageId = 'x'
|
||||
|
||||
# Locate if user service has any already assigned user service for this. Use "pre cached" number of assignations in this pool to optimize
|
||||
in_use = False
|
||||
if svr.number_assignations: # Anotated value got from getDeployedServicesForGroups(...). If 0, no assignation for this user
|
||||
ads = userServiceManager().getExistingAssignationForUser(svr, request.user)
|
||||
if ads:
|
||||
in_use = ads.in_use
|
||||
in_use = svr.number_in_use > 0
|
||||
# if svr.number_in_use: # Anotated value got from getDeployedServicesForGroups(...). If 0, no assignation for this user
|
||||
# ads = userServiceManager().getExistingAssignationForUser(svr, request.user)
|
||||
# if ads:
|
||||
# in_use = ads.in_use
|
||||
|
||||
group = svr.servicesPoolGroup.as_dict if svr.servicesPoolGroup else ServicePoolGroup.default().as_dict
|
||||
|
||||
tbr = svr.toBeReplaced(request.user)
|
||||
if tbr:
|
||||
tbr = formats.date_format(tbr, "SHORT_DATETIME_FORMAT")
|
||||
tbrt = ugettext('This service is about to be replaced by a new version. Please, close the session before {} and save all your work to avoid loosing it.').format(tbr)
|
||||
toBeReplaced = svr.toBeReplaced(request.user)
|
||||
# tbr = False
|
||||
if toBeReplaced:
|
||||
toBeReplaced = formats.date_format(toBeReplaced, "SHORT_DATETIME_FORMAT")
|
||||
toBeReplacedTxt = ugettext('This service is about to be replaced by a new version. Please, close the session before {} and save all your work to avoid loosing it.').format(toBeReplaced)
|
||||
else:
|
||||
tbrt = ''
|
||||
toBeReplacedTxt = ''
|
||||
|
||||
services.append({
|
||||
'id': 'F' + svr.uuid,
|
||||
@ -209,8 +210,8 @@ def getServicesData(request: 'HttpRequest') -> typing.Dict[str, typing.Any]: #
|
||||
'maintenance': svr.isInMaintenance(),
|
||||
'not_accesible': not svr.isAccessAllowed(now),
|
||||
'in_use': in_use,
|
||||
'to_be_replaced': tbr,
|
||||
'to_be_replaced_text': tbrt,
|
||||
'to_be_replaced': toBeReplaced,
|
||||
'to_be_replaced_text': toBeReplacedTxt,
|
||||
'custom_calendar_text': svr.calendar_message,
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user