Upgrading for new django 4.0

This commit is contained in:
Adolfo Gómez García 2021-12-10 15:12:32 +01:00
parent 44f219402e
commit 49975ab5d2
41 changed files with 114 additions and 100 deletions

View File

@ -17,5 +17,4 @@ requests
WeasyPrint
webencodings
xml-marshaller
pycrypto>=2.6.1
cryptography

View File

@ -240,7 +240,7 @@ class Dispatcher(View):
# Dinamycally import children of this package.
package = 'methods'
pkgpath = os.path.join(os.path.dirname(sys.modules[__name__].__file__), package)
pkgpath = os.path.join(os.path.dirname(typing.cast(str, sys.modules[__name__].__file__)), package)
for _, name, _ in pkgutil.iter_modules([pkgpath]):
# __import__(__name__ + '.' + package + '.' + name, globals(), locals(), [], 0)
importlib.import_module(

View File

@ -155,7 +155,9 @@ class MetaAssignedService(DetailHandler):
uuid=processUuid(userServiceId),
cache_level=0,
deployed_service__meta=metaPool,
)[0]
)[
0 # type: ignore # Slicing is not supported by pylance right now
]
except Exception:
pass
raise self.invalidItemException()

View File

@ -223,7 +223,6 @@ class BaseModelHandler(Handler):
'type': 'choice',
'order': 100, # At end
'tab': uiGui.ADVANCED_TAB,
},
)
self.addField(
@ -242,13 +241,9 @@ class BaseModelHandler(Handler):
'type': 'multichoice',
'order': 101,
'tab': uiGui.ADVANCED_TAB,
},
)
return gui
def ensureAccess(
@ -859,7 +854,7 @@ class ModelHandler(BaseModelHandler):
'Processing detail %s for with params %s', self._path, self._params
)
try:
item: models.Model = self.model.objects.filter(uuid=self._args[0])[0]
item: models.Model = self.model.objects.filter(uuid=self._args[0])[0] # type: ignore # Slicing is not supported by pylance right now
# If we do not have access to parent to, at least, read...
if self._operation in ('put', 'post', 'delete'):

View File

@ -114,10 +114,10 @@ class DelayedTaskRunner:
try:
with transaction.atomic(): # Encloses
# Throws exception if no delayed task is avilable
task = (
task: DBDelayedTask = (
DBDelayedTask.objects.select_for_update()
.filter(filt)
.order_by('execution_time')[0]
.order_by('execution_time')[0] # type: ignore # Slicing is not supported by pylance right now
) # @UndefinedVariable
if task.insert_date > now + timedelta(seconds=30):
logger.warning(

View File

@ -156,7 +156,7 @@ class Scheduler:
job: DBScheduler = (
DBScheduler.objects.select_for_update()
.filter(fltr)
.order_by('next_execution')[0]
.order_by('next_execution')[0]# type: ignore # Slicing is not supported by pylance right now
)
if job.last_execution > now:
logger.warning(

View File

@ -103,16 +103,18 @@ class LogManager(metaclass=singleton.Singleton):
qs = models.Log.objects.filter(owner_id=owner_id, owner_type=owner_type)
# First, ensure we do not have more than requested logs, and we can put one more log item
if qs.count() >= GlobalConfig.MAX_LOGS_PER_ELEMENT.getInt():
for i in qs.order_by(
'-created',
)[GlobalConfig.MAX_LOGS_PER_ELEMENT.getInt() - 1 :]:
for i in qs.order_by('-created',)[
GlobalConfig.MAX_LOGS_PER_ELEMENT.getInt() - 1 : # type: ignore # Slicing is not supported by pylance right now
]:
i.delete()
if avoidDuplicates:
try:
lg = models.Log.objects.filter(
lg: models.Log = models.Log.objects.filter(
owner_id=owner_id, owner_type=owner_type
).order_by('-id')[0]
).order_by('-id')[
0 # type: ignore # Slicing is not supported by pylance right now
]
if lg.data == message:
# Do not log again, already logged
return
@ -142,7 +144,7 @@ class LogManager(metaclass=singleton.Singleton):
qs = models.Log.objects.filter(owner_id=owner_id, owner_type=owner_type)
return [
{'date': x.created, 'level': x.level, 'source': x.source, 'message': x.data}
for x in reversed(qs.order_by('-created', '-id')[:limit])
for x in reversed(qs.order_by('-created', '-id')[:limit]) # type: ignore # Slicing is not supported by pylance right now
]
def __clearLogs(self, owner_type: int, owner_id: int):

View File

@ -265,12 +265,17 @@ class StatsManager(metaclass=singleton.Singleton):
"""
return StatsEvents.get_stats(ownerType, eventType, **kwargs)
def tailEvents(self, *, fromId: typing.Optional[str] = None, number: typing.Optional[int] = None) -> 'models.QuerySet[StatsEvents]':
def tailEvents(
self,
*,
fromId: typing.Optional[str] = None,
number: typing.Optional[int] = None
) -> 'models.QuerySet[StatsEvents]':
# If number is not specified, we return five last events
number = number or 5
if fromId:
return StatsEvents.objects.filter(id__gt=fromId).order_by('-id')[:number]
return StatsEvents.objects.order_by('-id')[:number]
return StatsEvents.objects.filter(id__gt=fromId).order_by('-id')[:number] # type: ignore # Slicing is not supported by pylance right now
return StatsEvents.objects.order_by('-id')[:number] # type: ignore # Slicing is not supported by pylance right now
def cleanupEvents(self):
"""

View File

@ -74,7 +74,9 @@ class UserServiceManager(metaclass=singleton.Singleton):
@staticmethod
def manager() -> 'UserServiceManager':
return UserServiceManager() # Singleton pattern will return always the same instance
return (
UserServiceManager()
) # Singleton pattern will return always the same instance
@staticmethod
def getCacheStateFilter(level: int) -> Q:
@ -404,7 +406,9 @@ class UserServiceManager(metaclass=singleton.Singleton):
cache_level=services.UserDeployment.L1_CACHE,
state=State.USABLE,
os_state=State.USABLE,
)[:1],
)[
:1 # type: ignore # Slicing is not supported by pylance right now
],
)
if caches:
cache = caches[0]
@ -429,7 +433,9 @@ class UserServiceManager(metaclass=singleton.Singleton):
.select_for_update()
.filter(
cache_level=services.UserDeployment.L1_CACHE, state=State.USABLE
)[:1],
)[
:1 # type: ignore # Slicing is not supported by pylance right now
],
)
if cache:
cache = caches[0]
@ -475,10 +481,12 @@ class UserServiceManager(metaclass=singleton.Singleton):
.select_for_update()
.filter(
cache_level=services.UserDeployment.L1_CACHE, state=State.PREPARING
)[:1]
)[
:1 # type: ignore # Slicing is not supported by pylance right now
]
)
if caches:
cache = caches[0]
cache = caches[0] # type: ignore # Slicing is not supported by pylance right now
if (
servicePool.cachedUserServices()
.select_for_update()
@ -942,14 +950,10 @@ class UserServiceManager(metaclass=singleton.Singleton):
# Remove "full" pools (100%) from result and pools in maintenance mode, not ready pools, etc...
sortedPools = sorted(sortPools, key=lambda x: x[0])
pools: typing.List[ServicePool] = [
p[1]
for p in sortedPools
if p[1].usage() < 100 and p[1].isUsable()
p[1] for p in sortedPools if p[1].usage() < 100 and p[1].isUsable()
]
poolsFull: typing.List[ServicePool] = [
p[1]
for p in sortedPools
if p[1].usage() == 100 and p[1].isUsable()
p[1] for p in sortedPools if p[1].usage() == 100 and p[1].isUsable()
]
logger.debug('Pools: %s/%s', pools, poolsFull)
@ -983,11 +987,13 @@ class UserServiceManager(metaclass=singleton.Singleton):
try:
# Already assigned should look for in all usable pools, not only "non-full" ones
alreadyAssigned: UserService = UserService.objects.filter(
deployed_service__in=pools+poolsFull,
deployed_service__in=pools + poolsFull,
state__in=State.VALID_STATES,
user=user,
cache_level=0,
).order_by('deployed_service__name')[0]
).order_by('deployed_service__name')[
0 # type: ignore # Slicing is not supported by pylance right now
]
logger.debug('Already assigned %s', alreadyAssigned)
# Ensure transport is available for the OS, and store it

View File

@ -181,7 +181,7 @@ class Module(UserInterface, Environmentable, Serializable):
'iconFile' class attribute
"""
file_ = open(
os.path.dirname(sys.modules[cls.__module__].__file__) + '/' + cls.iconFile,
os.path.dirname(typing.cast(str, sys.modules[cls.__module__].__file__)) + '/' + cls.iconFile,
'rb',
)
data = file_.read()

View File

@ -34,7 +34,6 @@
NONE = ''
RDP = 'rdp'
RDS = 'rds' # In fact, RDS (Remote Desktop Services) is RDP, but have "more info" for connection that RDP
RGS = 'rgs'
SPICE = 'spice'
VNC = 'vnc'
PCOIP = 'pcoip'
@ -47,4 +46,4 @@ X2GO = 'x2go' # Based on NX
NICEDCV = 'nicedcv'
OTHER = 'other'
GENERIC = (RDP, RGS, VNC, NX, X11, X2GO, PCOIP, NICEDCV, OTHER)
GENERIC = (RDP, VNC, NX, X11, X2GO, PCOIP, NICEDCV, OTHER)

View File

@ -261,9 +261,9 @@ class Config:
def update(section, key, value, checkType=False) -> bool:
# If cfg value does not exists, simply ignore request
try:
cfg = DBConfig.objects.filter(section=section, key=key)[
0
] # @UndefinedVariable
cfg: DBConfig = DBConfig.objects.filter(section=section, key=key)[
0 # type: ignore # Slicing is not supported by pylance right now
]
if checkType and cfg.field_type in (Config.READ_FIELD, Config.HIDDEN_FIELD):
return False # Skip non writable elements

View File

@ -28,7 +28,6 @@
"""
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
"""
import re
import datetime
import logging
import typing

View File

@ -31,10 +31,6 @@
import logging
from django.urls import reverse
from django.http import HttpResponseRedirect
from uds.core.util.config import GlobalConfig
logger = logging.getLogger(__name__)

View File

@ -52,7 +52,7 @@ def loadModulesUrls() -> typing.List[typing.Any]:
logger.debug('Looking for patterns')
try:
modName = 'uds.dispatchers'
pkgpath = os.path.dirname(sys.modules[modName].__file__)
pkgpath = os.path.dirname(typing.cast(str, sys.modules[modName].__file__))
for _, name, _ in pkgutil.iter_modules([pkgpath]):
fullModName = '{}.{}.urls'.format(modName, name)
try:

View File

@ -62,7 +62,7 @@ ACCOUNT_TYPE = 16
ACTOR_TOKEN_TYPE = 17
TUNNEL_TOKEN_TYPE = 18
objTypeDict: typing.Dict[typing.Type, int] = {
objTypeDict: typing.Dict[typing.Type['Model'], int] = {
models.Provider: PROVIDER_TYPE,
models.Service: SERVICE_TYPE,
models.OSManager: OSMANAGER_TYPE,

View File

@ -29,11 +29,6 @@
"""
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
"""
import asyncio
import contextvars
import random
import datetime
import threading
import datetime
import weakref
import logging

View File

@ -129,7 +129,7 @@ def packageRelativeFile(moduleName: str, fileName: str) -> str:
Helper to get image path from relative to a module.
This allows to keep images alongside report
"""
pkgpath = os.path.dirname(sys.modules[moduleName].__file__)
pkgpath = os.path.dirname(typing.cast(str, sys.modules[moduleName].__file__))
return os.path.join(pkgpath, fileName)

View File

@ -91,8 +91,10 @@ class UniqueIDGenerator:
# logger.debug('Creating new seq in range {}-{}'.format(rangeStart, rangeEnd))
with transaction.atomic():
flt = self.__filter(rangeStart, rangeEnd, forUpdate=True)
item: typing.Optional[UniqueId] = None
try:
item = flt.filter(assigned=False).order_by('seq')[0]
item = flt.filter(assigned=False).order_by('seq')[0] # type: ignore # Slicing is not supported by pylance right now
if item:
item.owner = self._owner
item.assigned = True
item.stamp = stamp
@ -107,8 +109,8 @@ class UniqueIDGenerator:
if not item:
# logger.debug('No free found, creating new one')
try:
last = flt.filter(assigned=True)[
0
last: UniqueId = flt.filter(assigned=True)[
0 # type: ignore # Slicing is not supported by pylance right now
] # DB Returns correct order so the 0 item is the last
seq = last.seq + 1
except IndexError: # If there is no assigned at database
@ -162,7 +164,7 @@ class UniqueIDGenerator:
def __purge(self) -> None:
logger.debug('Purging UniqueID database')
try:
last = self.__filter(0, forUpdate=False).filter(assigned=True)[0]
last: UniqueId = self.__filter(0, forUpdate=False).filter(assigned=True)[0] # type: ignore # Slicing is not supported by pylance right now
logger.debug('Last: %s', last)
seq = last.seq + 1
except Exception:

View File

@ -34,6 +34,7 @@ import sys
import os.path
import pkgutil
import importlib
import typing
import logging
logger = logging.getLogger(__name__)
@ -48,7 +49,7 @@ def initialize() -> None:
from uds.core.managers import taskManager
# Dinamycally import children of this package.
pkgpath = os.path.dirname(sys.modules[__name__].__file__)
pkgpath = os.path.dirname(typing.cast(str, sys.modules[__name__].__file__))
for _, name, _ in pkgutil.iter_modules([pkgpath]):
logger.debug('Importing worker %s', name)
# __import__(name, globals(), locals(), [], 1)

View File

@ -147,7 +147,9 @@ class DeployedServiceRemover(Job):
# First check if there is someone in "removable" estate
removableServicePools: typing.Iterable[
ServicePool
] = ServicePool.objects.filter(state=State.REMOVABLE)[:10]
] = ServicePool.objects.filter(state=State.REMOVABLE)[
:10 # type: ignore # Slicing is not supported by pylance right now
]
for servicePool in removableServicePools:
try:
# Skips checking deployed services in maintenance mode
@ -162,7 +164,9 @@ class DeployedServiceRemover(Job):
removingServicePools: typing.Iterable[ServicePool] = ServicePool.objects.filter(
state=State.REMOVING
)[:10]
)[
:10 # type: ignore # Slicing is not supported by pylance right now
]
for servicePool in removingServicePools:
try:
# Skips checking deployed services in maintenance mode

View File

@ -357,7 +357,7 @@ class ServiceCacheUpdater(Job):
.order_by('creation_date')
)
# TODO: Look first for non finished cache items and cancel them?
cache = cacheItems[0]
cache: UserService = cacheItems[0] # type: ignore # Slicing is not supported by pylance right now
cache.removeOrCancel()
def run(self):

View File

@ -89,7 +89,7 @@ class UserServiceRemover(Job):
state_date__lt=removeFrom,
deployed_service__service__provider__maintenance_mode=False,
)[
0:removeAtOnce
0:removeAtOnce # type: ignore # Slicing is not supported by pylance right now
].iterator()
manager = managers.userServiceManager()

View File

@ -120,7 +120,7 @@ class EventFS(types.UDSFSInterface):
)
events = EventFS.get_events(year, month, day, skip)
# Compose lines, adjsting each line length to LINELEN
theLines = [pretty_print(x).encode('utf-8') for x in events[:lines]]
theLines = [pretty_print(x).encode('utf-8') for x in events[:lines]] # type: ignore # Slicing is not supported by pylance right now
# Adjust each line length to LINELEN (after encoding from utf8)
theLines = [x + b' ' * (LINELEN - len(x) - 1) + b'\n' for x in theLines]
# Return lines
@ -152,4 +152,6 @@ class EventFS(types.UDSFSInterface):
)
return StatsEvents.objects.filter(stamp__gte=start, stamp__lte=end).order_by(
'stamp'
)[skip:]
)[
skip: # type: ignore # Slicing is not supported by pylance right now
]

View File

@ -248,11 +248,11 @@ class Authenticator(ManagedObjectModel, TaggingMixin):
authsList = Authenticator.objects.filter(small_name=tag).order_by(
'priority', 'name'
)
if not authsList:
if not authsList.exists():
authsList = Authenticator.objects.all().order_by('priority', 'name')
# If disallow global login (use all auths), get just the first by priority/name
if GlobalConfig.DISALLOW_GLOBAL_LOGIN.getBool(False) is True:
authsList = authsList[0:1]
authsList = authsList[:1] # type: ignore # Slicing is not supported by pylance right now
logger.debug(authsList)
else:
authsList = Authenticator.objects.all().order_by('priority', 'name')

View File

@ -124,9 +124,11 @@ class Permissions(UUIDModel):
q = Q(group=group)
try:
existing = Permissions.objects.filter(
existing: Permissions = Permissions.objects.filter(
q, object_type=object_type, object_id=object_id
)[0]
)[
0 # type: ignore # Slicing is not supported by pylance right now
]
existing.permission = permission
existing.save()
return existing
@ -167,11 +169,13 @@ class Permissions(UUIDModel):
q = Q(user=user) | Q(group__in=groups)
try:
perm = Permissions.objects.filter(
perm: Permissions = Permissions.objects.filter(
Q(object_type=object_type),
Q(object_id=None) | Q(object_id=object_id),
q,
).order_by('-permission')[0]
).order_by('-permission')[
0 # type: ignore # Slicing is not supported by pylance right now
]
logger.debug('Got permission %s', perm)
return perm.permission
except Exception: # DoesNotExists

View File

@ -186,7 +186,7 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
None if there is no valid publication for this deployed service.
"""
try:
return self.publications.filter(state=states.publication.USABLE)[0]
return self.publications.filter(state=states.publication.USABLE)[0] # type: ignore # Slicing is not supported by pylance right now
except Exception:
return None
@ -315,7 +315,7 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
'UserService',
self.assignedUserServices().filter(
user=forUser, state__in=states.userService.VALID_STATES
)[0],
)[0], # type: ignore # Slicing is not supported by pylance right now
)
if activePub and found.publication and activePub.id != found.publication.id:
ret = self.recoverValue('toBeReplacedIn')

View File

@ -132,8 +132,8 @@ class StatsCounters(models.Model):
q = q.filter(owner_type=owner_type)
if q.count() > max_intervals:
first = q.order_by('stamp')[0].stamp
last = q.order_by('stamp').reverse()[0].stamp
first = q.order_by('stamp')[0].stamp # type: ignore # Slicing is not supported by pylance right now
last = q.order_by('stamp').reverse()[0].stamp # type: ignore # Slicing is not supported by pylance right now
interval = int((last - first) / (max_intervals - 1))
stampValue = '{ceil}(stamp/{interval})'.format(

View File

@ -31,6 +31,7 @@
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
import os.path
import typing
import sys
from django.utils.translation import gettext_noop as _
@ -49,7 +50,7 @@ downloadsManager().registerDownloadable(
_(
'UDS Actor for Debian, Ubuntu, ... Linux machines <b>(Requires python >= 3.6)</b>'
),
os.path.dirname(sys.modules[__package__].__file__)
os.path.dirname(typing.cast(str, sys.modules[__package__].__file__))
+ '/files/udsactor_{version}_all.deb'.format(version=VERSION),
'application/x-debian-package',
)
@ -59,7 +60,7 @@ downloadsManager().registerDownloadable(
_(
'UDS Actor for Centos, Fedora, RH, Suse, ... Linux machines <b>(Requires python >= 3.6)</b>'
),
os.path.dirname(sys.modules[__package__].__file__)
os.path.dirname(typing.cast(str, sys.modules[__package__].__file__))
+ '/files/udsactor-{version}-1.noarch.rpm'.format(version=VERSION),
'application/x-redhat-package-manager',
)
@ -69,7 +70,7 @@ downloadsManager().registerDownloadable(
_(
'UDS Actor for Debian based Linux machines. Used ONLY for static machines. <b>(Requires python >= 3.6)</b>'
),
os.path.dirname(sys.modules[__package__].__file__)
os.path.dirname(typing.cast(str, sys.modules[__package__].__file__))
+ '/files/udsactor-unmanaged_{version}_all.deb'.format(version=VERSION),
'application/x-debian-package',
)
@ -79,7 +80,7 @@ downloadsManager().registerDownloadable(
_(
'<b>Legacy</b> UDS Actor for Debian, Ubuntu, ... Linux machines <b>(Requires python 2.7)</b>'
),
os.path.dirname(sys.modules[__package__].__file__)
os.path.dirname(typing.cast(str, sys.modules[__package__].__file__))
+ '/files/udsactor_2.2.0_legacy.deb',
'application/x-debian-package',
)
@ -89,7 +90,7 @@ downloadsManager().registerDownloadable(
_(
'<b>Legacy</b> UDS Actor for Centos, Fedora, RH, ... Linux machines <b>(Requires python 2.7)</b>'
),
os.path.dirname(sys.modules[__package__].__file__)
os.path.dirname(typing.cast(str, sys.modules[__package__].__file__))
+ '/files/udsactor-legacy-2.2.1-1.noarch.rpm',
'application/x-redhat-package-manager',
)
@ -99,7 +100,7 @@ downloadsManager().registerDownloadable(
_(
'<b>Legacy</b> UDS Actor for OpenSUSE, ... Linux machines <b>(Requires python 2.7)</b>'
),
os.path.dirname(sys.modules[__package__].__file__)
os.path.dirname(typing.cast(str, sys.modules[__package__].__file__))
+ '/files/udsactor-opensuse-legacy-2.2.1-1.noarch.rpm',
'application/x-redhat-package-manager',
)

View File

@ -32,6 +32,7 @@
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
import os.path
import typing
import sys
from django.utils.translation import gettext_noop as _
@ -50,7 +51,7 @@ osmanagers.factory().insert(WinRandomPassManager)
managers.downloadsManager().registerDownloadable(
'UDSActorSetup-{version}.exe'.format(version=VERSION),
_('UDS Actor for windows machines'),
os.path.dirname(sys.modules[__package__].__file__)
os.path.dirname(typing.cast(str, sys.modules[__package__].__file__))
+ '/files/UDSActorSetup-{version}.exe'.format(version=VERSION),
'application/x-msdos-program',
)
@ -58,7 +59,7 @@ managers.downloadsManager().registerDownloadable(
managers.downloadsManager().registerDownloadable(
'UDSActorUnmanagedSetup-{version}.exe'.format(version=VERSION),
_('UDS Actor for Unmanaged windows machines. Used ONLY for static machines.'),
os.path.dirname(sys.modules[__package__].__file__)
os.path.dirname(typing.cast(str, sys.modules[__package__].__file__))
+ '/files/UDSActorUnmanagedSetup-{version}.exe'.format(version=VERSION),
'application/x-msdos-program',
)

View File

@ -44,6 +44,7 @@ import os.path
import pkgutil
import sys
import importlib
import typing
def __init__():
@ -54,7 +55,7 @@ def __init__():
from uds.core import osmanagers
# Dinamycally import children of this package.
pkgpath = os.path.dirname(sys.modules[__name__].__file__)
pkgpath = os.path.dirname(typing.cast(str, sys.modules[__name__].__file__))
for _, name, _ in pkgutil.iter_modules([pkgpath]):
# __import__(name, globals(), locals(), [], 1)

View File

@ -32,6 +32,7 @@ import pkgutil
import sys
import importlib
import logging
import typing
logger = logging.getLogger(__name__)
@ -44,7 +45,7 @@ def loadPlugins():
logger.debug('Initializing plugins...')
# Dinamycally import children of this package. The __init__.py files must import classes
pkgpath = os.path.dirname(sys.modules[__name__].__file__)
pkgpath = os.path.dirname(typing.cast(str, sys.modules[__name__].__file__))
for _, name, _ in pkgutil.iter_modules([pkgpath]):
# __import__(name, globals(), locals(), [], 1)
importlib.import_module('.' + name, __name__) # Local import

View File

@ -77,7 +77,7 @@ def __init__() -> None:
recursiveAdd(subReport)
# Dinamycally import children of this package. The __init__.py files must import classes
pkgpath = os.path.dirname(sys.modules[__name__].__file__)
pkgpath = os.path.dirname(typing.cast(str, sys.modules[__name__].__file__))
for _, name, _ in pkgutil.iter_modules([pkgpath]):
# __import__(name, globals(), locals(), [], 1)
importlib.import_module('.' + name, __name__) # Local import

View File

@ -31,7 +31,6 @@
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
"""
import logging
import datetime
import typing
from django.utils.translation import gettext, gettext_noop as _

View File

@ -32,7 +32,6 @@
"""
import io
import csv
import zipfile
import logging
# import openpyxl

View File

@ -22,7 +22,7 @@ def convertFromDict(
k: conversors.get(type.__annotations__.get(k, str), lambda x: x)(
dictionary.get(k, None)
)
for k in type._fields
for k in typing.cast(typing.NamedTuple, type)._fields
}
)

View File

@ -47,6 +47,7 @@ import pkgutil
import sys
import importlib
import logging
import typing
logger = logging.getLogger(__name__)
@ -59,7 +60,7 @@ def __init__():
from uds.core import services
# Dinamycally import children of this package.
pkgpath = os.path.dirname(sys.modules[__name__].__file__)
pkgpath = os.path.dirname(typing.cast(str, sys.modules[__name__].__file__))
for _, name, _ in pkgutil.iter_modules([pkgpath]):
# __import__('uds.services.' + name, globals(), locals(), [])
importlib.import_module('.' + name, __name__) # import module

View File

@ -30,7 +30,6 @@
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
import datetime
import re
import logging
import typing

View File

@ -34,7 +34,6 @@ import logging
import typing
from django.utils.translation import gettext_noop as _
from django.urls import reverse
from django.http import HttpResponseRedirect
from uds.core.ui import gui

View File

@ -69,7 +69,7 @@ def checkLogin( # pylint: disable=too-many-branches, too-many-statements
tag = host
except Exception:
try:
tag = Authenticator.objects.order_by('priority')[0].small_name
tag = Authenticator.objects.order_by('priority')[0].small_name # type: ignore # Slicing is not supported by pylance right now
except Exception: # There is no authenticators yet, simply allow global login to nowhere.. :-)
tag = None

View File

@ -100,7 +100,9 @@ def transportIcon(request: 'ExtendedHttpRequest', idTrans: str) -> HttpResponse:
# Get First label
transport = Transport.objects.filter(label=idTrans[6:]).order_by(
'priority'
)[0]
)[
0 # type: ignore # Slicing is not supported by pylance right now
]
else:
transport = Transport.objects.get(uuid=processUuid(idTrans))
return HttpResponse(transport.getInstance().icon(), content_type='image/png')