Ignore:
Timestamp:
Feb 26, 2009, 11:09:28 PM (16 years ago)
Author:
price
Message:

small fixes to Record

Location:
trunk/packages/invirt-database/python/database
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-database/python/database/owner.py

    r2187 r2191  
    1616    _identity_field = 'owner_id'
    1717
    18     def getMemoryQuotas(owner):
    19         owner_info = Owner.query().filter_by(owner_id=owner).first()
     18    @classmethod
     19    def getMemoryQuotas(cls, owner):
     20        owner_info = cls.query().filter_by(owner_id=owner).first()
    2021        if owner_info == None:
    21             owner_info = Owner(owner_id=owner)
     22            owner_info = cls(owner_id=owner)
    2223        return (owner_info.get('ram_quota_total'), owner_info.get('ram_quota_single'))
    23     getMemoryQuotas = staticmethod(getMemoryQuotas)
    2424
    25     def getDiskQuotas(owner):
    26         owner_info = Owner.query().filter_by(owner_id=owner).first()
     25    @classmethod
     26    def getDiskQuotas(cls, owner):
     27        owner_info = cls.query().filter_by(owner_id=owner).first()
    2728        if owner_info == None:
    28             owner_info = Owner(owner_id=owner)
     29            owner_info = cls(owner_id=owner)
    2930        return (owner_info.get('disk_quota_total'), owner_info.get('disk_quota_single'))
    30     getDiskQuotas = staticmethod(getDiskQuotas)
    3131
    32     def getVMQuotas(owner):
    33         owner_info = Owner.query().filter_by(owner_id=owner).first()
     32    @classmethod
     33    def getVMQuotas(cls, owner):
     34        owner_info = cls.query().filter_by(owner_id=owner).first()
    3435        if owner_info == None:
    35             owner_info = Owner(owner_id=owner)
     36            owner_info = cls(owner_id=owner)
    3637        return (owner_info.get('vms_quota_total'), owner_info.get('vms_quota_active'))
    37     getVMQuotas = staticmethod(getVMQuotas)
    38 
    39     def _ignore(self):
    40         return super(Owner, self)._ignore() + ['getMemoryQuotas', 'getDiskQuotas', 'getVMQuotas']
  • trunk/packages/invirt-database/python/database/record.py

    r2187 r2191  
    11class Record(object):
    22    _identity_field = None
     3
    34    def get(self, field):
    45        try:
     
    67        except:
    78            return None
     9
    810    def _formatField(self, field):
    911        v = self.get(field)
     
    1719        else:
    1820            return repr(v)
     21
     22    @classmethod
     23    def _ignore(cls):
     24        return [cls._identity_field]
     25
    1926    def _fields(self):
    2027        ignore = self._ignore()
    21         keys = sorted(self.__class__.__dict__.keys())
    22         return [(k,self._formatField(k)) for k in keys if k[0]!="_" and k not in ignore]
     28        keys = sorted(self.c.keys())
     29        return [(k,self._formatField(k)) for k in keys if k not in ignore]
     30
    2331    def __repr__(self):
    2432        classname = self.__class__.__name__
     
    3543
    3644        return "<%s%s%s>" % (classname, identity, payload)
    37     def _ignore(self):
    38         return [self._identity_field, 'c', 'query', 'get']
    3945
    4046class FormattableRecord(Record):
Note: See TracChangeset for help on using the changeset viewer.