UserManager.py 867 Bytes
from common.models import *
from utils.Logger import *
from decimal import *

class UserManager(Logger):
    REJECTED = "Insufficient quota"

    def __init__(self, user: PyrosUser):
        super().__init__("UserManager", "UserManager")
        self.user = user

    @classmethod
    def determineQuota(cls, sequence: Sequence) -> float:
        return sequence.request.pyros_user.quota

    @classmethod
    def isSufficient(cls, quota: float, sequence: Sequence) -> bool:
        #print("seq is", sequence.duration)
        #print("quota is", quota)
        if quota < sequence.duration:
            return False
        return True

    @classmethod
    def determinePriority(cls, sequence: Sequence) -> float:
        return 0

    def decreaseQuota(self, value: Decimal) -> int:
        self.user.quota -= float(value)
        self.user.save()
        return 0