forked from shaba/openuds
refactoring for name improvements - cache, calendar, calendar_access, calendar_rule models
This commit is contained in:
parent
efbca0bf92
commit
fb32c8b86a
@ -37,7 +37,7 @@ from django.utils.translation import ugettext as _
|
||||
from django.db import IntegrityError
|
||||
|
||||
|
||||
from uds.models.CalendarRule import freqs, CalendarRule
|
||||
from uds.models.calendar_rule import freqs, CalendarRule
|
||||
from uds.models.Util import getSqlDatetime
|
||||
|
||||
from uds.core.util import permissions
|
||||
|
@ -36,7 +36,7 @@ import logging
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from uds.models import CalendarAction, Calendar
|
||||
from uds.models.CalendarAction import CALENDAR_ACTION_DICT
|
||||
from uds.models.calendar_action import CALENDAR_ACTION_DICT
|
||||
from uds.core.util import log, permissions
|
||||
from uds.core.util.model import processUuid
|
||||
|
||||
|
@ -34,7 +34,7 @@ import logging
|
||||
|
||||
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||
from uds.models import DeployedService, OSManager, Service, Image, ServicesPoolGroup, Account
|
||||
from uds.models.CalendarAction import (
|
||||
from uds.models.calendar_action import (
|
||||
CALENDAR_ACTION_INITIAL,
|
||||
CALENDAR_ACTION_MAX,
|
||||
CALENDAR_ACTION_CACHE_L1,
|
||||
|
@ -37,7 +37,7 @@ from datetime import datetime, timedelta
|
||||
import typing
|
||||
|
||||
from django.db import transaction
|
||||
import uds.models.Cache
|
||||
import uds.models.cache
|
||||
from uds.models.Util import getSqlDatetime
|
||||
from uds.core.util import encoders
|
||||
|
||||
@ -71,7 +71,7 @@ class Cache:
|
||||
try:
|
||||
key = self.__getKey(skey)
|
||||
logger.debug('Key: %s', key)
|
||||
c: uds.models.Cache = uds.models.Cache.objects.get(pk=key) # @UndefinedVariable
|
||||
c: uds.models.cache = uds.models.cache.objects.get(pk=key) # @UndefinedVariable
|
||||
# If expired
|
||||
if now > c.created + timedelta(seconds=c.validity):
|
||||
return defValue
|
||||
@ -86,7 +86,7 @@ class Cache:
|
||||
|
||||
Cache.hits += 1
|
||||
return val
|
||||
except uds.models.Cache.DoesNotExist: # @UndefinedVariable
|
||||
except uds.models.cache.DoesNotExist: # @UndefinedVariable
|
||||
Cache.misses += 1
|
||||
logger.debug('key not found: %s', skey)
|
||||
return defValue
|
||||
@ -103,9 +103,9 @@ class Cache:
|
||||
# logger.debug('Removing key "%s" for uService "%s"' % (skey, self._owner))
|
||||
try:
|
||||
key = self.__getKey(skey)
|
||||
uds.models.Cache.objects.get(pk=key).delete() # @UndefinedVariable
|
||||
uds.models.cache.objects.get(pk=key).delete() # @UndefinedVariable
|
||||
return True
|
||||
except uds.models.Cache.DoesNotExist: # @UndefinedVariable
|
||||
except uds.models.cache.DoesNotExist: # @UndefinedVariable
|
||||
logger.debug('key not found')
|
||||
return False
|
||||
|
||||
@ -120,11 +120,11 @@ class Cache:
|
||||
value = typing.cast(str, encoders.encode(pickle.dumps(value), 'base64', asText=True))
|
||||
now: datetime = typing.cast(datetime, getSqlDatetime())
|
||||
try:
|
||||
uds.models.Cache.objects.create(owner=self._owner, key=key, value=value, created=now, validity=validity) # @UndefinedVariable
|
||||
uds.models.cache.objects.create(owner=self._owner, key=key, value=value, created=now, validity=validity) # @UndefinedVariable
|
||||
except Exception:
|
||||
try:
|
||||
# Already exists, modify it
|
||||
c: uds.models.Cache = uds.models.Cache.objects.get(pk=key) # @UndefinedVariable
|
||||
c: uds.models.cache = uds.models.cache.objects.get(pk=key) # @UndefinedVariable
|
||||
c.owner = self._owner
|
||||
c.key = key
|
||||
c.value = value
|
||||
@ -138,26 +138,26 @@ class Cache:
|
||||
# logger.debug('Refreshing key "%s" for cache "%s"' % (skey, self._owner,))
|
||||
try:
|
||||
key = self.__getKey(skey)
|
||||
c = uds.models.Cache.objects.get(pk=key) # @UndefinedVariable
|
||||
c = uds.models.cache.objects.get(pk=key) # @UndefinedVariable
|
||||
c.created = getSqlDatetime()
|
||||
c.save()
|
||||
except uds.models.Cache.DoesNotExist: # @UndefinedVariable
|
||||
except uds.models.cache.DoesNotExist: # @UndefinedVariable
|
||||
logger.debug('Can\'t refresh cache key %s because it doesn\'t exists', skey)
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def purge() -> None:
|
||||
uds.models.Cache.objects.all().delete() # @UndefinedVariable
|
||||
uds.models.cache.objects.all().delete() # @UndefinedVariable
|
||||
|
||||
@staticmethod
|
||||
def cleanUp() -> None:
|
||||
uds.models.Cache.cleanUp() # @UndefinedVariable
|
||||
uds.models.cache.cleanUp() # @UndefinedVariable
|
||||
|
||||
@staticmethod
|
||||
def delete(owner: typing.Optional[str] = None) -> None:
|
||||
# logger.info("Deleting cache items")
|
||||
if owner is None:
|
||||
objects = uds.models.Cache.objects.all() # @UndefinedVariable
|
||||
objects = uds.models.cache.objects.all() # @UndefinedVariable
|
||||
else:
|
||||
objects = uds.models.Cache.objects.filter(owner=owner) # @UndefinedVariable
|
||||
objects = uds.models.cache.objects.filter(owner=owner) # @UndefinedVariable
|
||||
objects.delete()
|
||||
|
@ -39,7 +39,7 @@ import bitarray
|
||||
from uds.models.Util import NEVER
|
||||
from uds.models.Util import getSqlDatetime
|
||||
|
||||
from uds.models.Calendar import Calendar
|
||||
from uds.models.calendar import Calendar
|
||||
|
||||
from uds.core.util.Cache import Cache
|
||||
|
||||
|
@ -48,7 +48,7 @@ from uds.models.Image import Image
|
||||
from uds.models.ServicesPoolGroup import ServicesPoolGroup
|
||||
from uds.models.ServicesPool import ServicePool
|
||||
from uds.models.Group import Group
|
||||
from uds.models.Calendar import Calendar
|
||||
from uds.models.calendar import Calendar
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
import datetime
|
||||
|
@ -51,7 +51,7 @@ from uds.models.Transport import Transport
|
||||
from uds.models.Group import Group
|
||||
from uds.models.Image import Image
|
||||
from uds.models.ServicesPoolGroup import ServicesPoolGroup
|
||||
from uds.models.Calendar import Calendar
|
||||
from uds.models.calendar import Calendar
|
||||
from uds.models.account import Account
|
||||
|
||||
from uds.models.Util import NEVER
|
||||
|
@ -75,7 +75,7 @@ from .StatsEvents import StatsEvents
|
||||
|
||||
# General utility models, such as a database cache (for caching remote content of slow connections to external services providers for example)
|
||||
# We could use django cache (and maybe we do it in a near future), but we need to clean up things when objecs owning them are deleted
|
||||
from .Cache import Cache
|
||||
from .cache import Cache
|
||||
from .Config import Config
|
||||
from .Storage import Storage
|
||||
from .UniqueId import UniqueId
|
||||
@ -91,11 +91,11 @@ from .Image import Image
|
||||
from .TicketStore import TicketStore
|
||||
|
||||
# Calendar related
|
||||
from .Calendar import Calendar
|
||||
from .CalendarRule import CalendarRule
|
||||
from .calendar import Calendar
|
||||
from .calendar_rule import CalendarRule
|
||||
|
||||
from .CalendarAccess import CalendarAccess, CalendarAccessMeta
|
||||
from .CalendarAction import CalendarAction
|
||||
from .calendar_access import CalendarAccess, CalendarAccessMeta
|
||||
from .calendar_action import CalendarAction
|
||||
|
||||
# Accounting
|
||||
from .account import Account
|
||||
|
@ -1,7 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Model based on https://github.com/llazzaro/django-scheduler
|
||||
#
|
||||
# Copyright (c) 2016-2019 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
@ -41,7 +39,7 @@ from uds.models.Tag import TaggingMixin
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Calendar(UUIDModel, TaggingMixin): # type: ignore
|
||||
class Calendar(UUIDModel, TaggingMixin):
|
||||
|
||||
name = models.CharField(max_length=128, default='')
|
||||
comments = models.CharField(max_length=256, default='')
|
@ -34,11 +34,13 @@
|
||||
import logging
|
||||
|
||||
from django.db import models
|
||||
|
||||
from uds.core.util import states
|
||||
from uds.models.UUIDModel import UUIDModel
|
||||
from uds.models.Calendar import Calendar
|
||||
from uds.models.ServicesPool import ServicePool
|
||||
from uds.models.MetaPool import MetaPool
|
||||
|
||||
from .UUIDModel import UUIDModel
|
||||
from .calendar import Calendar
|
||||
from .ServicesPool import ServicePool
|
||||
from .MetaPool import MetaPool
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
@ -39,13 +39,15 @@ import typing
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.db import models
|
||||
from uds.models.Calendar import Calendar
|
||||
from uds.models.UUIDModel import UUIDModel
|
||||
from uds.models.Util import getSqlDatetime
|
||||
|
||||
from uds.core.util import (calendar, log)
|
||||
from uds.models.ServicesPool import ServicePool
|
||||
from uds.models.Transport import Transport
|
||||
from uds.models.authenticator import Authenticator
|
||||
|
||||
from .calendar import Calendar
|
||||
from .UUIDModel import UUIDModel
|
||||
from .Util import getSqlDatetime
|
||||
from .ServicesPool import ServicePool
|
||||
from .Transport import Transport
|
||||
from .authenticator import Authenticator
|
||||
# from django.utils.translation import ugettext_lazy as _, ugettext
|
||||
|
||||
|
@ -40,7 +40,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from dateutil import rrule as rules
|
||||
|
||||
from .UUIDModel import UUIDModel
|
||||
from .Calendar import Calendar
|
||||
from .calendar import Calendar
|
||||
from .Util import getSqlDatetime
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user