class park_asset(db.Model): __bind_key__ = 'paaf' id = db.Column(db.Integer, primary_key=True) park_id = db.Column(db.Integer, db.ForeignKey('asset.id')) asset_id = db.Column(db.Integer, db.ForeignKey('asset.id')) description = db.Column(db.Text) def __init__(self,park_id=None, asset_id=None,desc=""): self.park_id=park_id self.asset_id=asset_id self.description=desc
class value_domain(db.Model): __bind_key__='paaf' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) description = db.Column(db.Text) parent_id = db.Column(db.Integer, db.ForeignKey('value_domain.id')) def __init__(self,name="",description="",parent_id=None): self.name=name if not parent_id ==None: self.parent_id=parent_id self.description = description def __repr__(self): return self.name def kids(self): return value_domain.query.filter_by(parent_id=self.id).all() def parent(self): return value_domain.query.get_or_404(id=self.parent_id)
class asset_value_domain_attributes(db.Model): __bind_key__ = 'paaf' id = db.Column(db.Integer, primary_key=True) park_id = db.Column(db.Integer, db.ForeignKey('park.id')) asset_id = db.Column(db.Integer, db.ForeignKey('asset.id')) value_domain_id = db.Column(db.Integer, db.ForeignKey('value_domain.id')) inputter_id = db.Column(db.Integer, nullable=False)#ID of whoever entered the survey (randomised) description = db.Column(db.String(70), nullable=True) asset_quality = db.Column(db.Integer, default=0) value_generating_status = db.Column(db.Integer, default=0) location_descriptor = db.Column(db.String(70), nullable=True) governance_competency = db.Column(db.Integer, default=0) def __init__(self, asset_id=None, value_domain_id=None,inputter_id=None,description="",asset_quality=0,value_generating_status=0,location_descriptor="",governance_competency=0): self.asset_id = asset_id self.value_domain_id = value_domain_id self.description=description self.asset_quality=asset_quality self.value_generating_status=value_generating_status self.location_descriptor=location_descriptor self.governance_competency = governance_competency self.inputter_id=inputter_id
class park(db.Model): __bind_key__='paaf' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) description = db.Column(db.Text) def all_ratings(self): return asset_value_domain_attributes.query.filter_by(asset_id=self.id).all() def ratings_collected_by_inputter(self): return asset_value_domain_attributes.query.filter_by(asset_id=self.id).all() def has_asset(self,asset_id): d="" ass=asset.query.get_or_404(asset_id) pa = park_asset.query.filter_by(asset_id=ass.id,park_id=self.id).all() if pa.__len__()>0: return True r= False for c in ass.kids(): r = self.has_asset(c.id) if r: return True return False def has_vgp(self,asset_id): d="" ass=value_generating_practice.query.get_or_404(asset_id) pa = park_vgps.query.filter_by(asset_vgp_id=ass.id,park_id=self.id).all() if pa.__len__()>0: return True r= False for c in ass.kids(): r = self.has_vgp(c.id) if r: return True return False def has_domains_of_value(self,asset_id): d="" ass=value_domain.query.get_or_404(asset_id) pa = park_domains_of_value.query.filter_by(asset_value_domain_id=ass.id,park_id=self.id).all() if pa.__len__()>0: return True r= False for c in ass.kids(): r = self.has_domains_of_value(c.id) if r: return True return False def asset_desc(self,asset_id): d="" pa = park_asset.query.filter_by(asset_id=asset_id,park_id=self.id).all() if pa.__len__()>0: d=pa[0].description return d def vgp_desc(self,asset_id): d="" pa = park_vgps.query.filter_by(asset_vgp_id=asset_id,park_id=self.id).all() if pa.__len__()>0: d=pa[0].description return d def value_desc(self,asset_id): d="" pa = park_domains_of_value.query.filter_by(asset_value_domain_id=asset_id,park_id=self.id).all() if pa.__len__()>0: d=pa[0].description return d def __init__(self,name="",desc=""): self.name=name self.description=desc def __repr__(self): return self.name def survey(self): pas = park_asset.query.filter_by(park_id=self.id).all() return pas