1 """Exceptions for the web interface."""
4 from invirt import database
5 from invirt.database import Machine, MachineAccess
9 def cachedproperty(func):
10 name = '__cache_' + func.__name__ + '_' + str(id(func))
13 return getattr(self, name)
14 except AttributeError:
16 setattr(self, name, value)
18 return property(getter)
21 """State for a request"""
22 def __init__(self, user, isadmin=False):
24 self.isadmin = isadmin
26 def getMachines(self):
28 return Machine.query().all()
30 return Machine.query().join('acl').filter_by(user=self.username)
32 machines = cachedproperty(getMachines)
33 xmlist_raw = cachedproperty(lambda self: controls.getList())
34 xmlist = cachedproperty(lambda self:
35 dict((m, self.xmlist_raw[m.name])
36 for m in self.machines
37 if m.name in self.xmlist_raw))
40 """Clear the state so future accesses reload it."""
41 for attr in list(self.__dict__):
42 if attr.startswith('__cache_'):