05/04 Update code to replace Area related to Facility
This commit is contained in:
+15
-1
@@ -47,7 +47,8 @@ class Issue(db.Model):
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
inspection_id = db.Column(db.Integer, db.ForeignKey('inspections.id'))
|
||||
area_id = db.Column(db.Integer, db.ForeignKey('areas.id'), nullable=False)
|
||||
area_id = db.Column(db.Integer, db.ForeignKey('areas.id'), nullable=True)
|
||||
facility_id = db.Column(db.Integer, db.ForeignKey('facilities.id'), nullable=True)
|
||||
severity = db.Column(db.Enum('low', 'medium', 'high', 'critical'), nullable=False)
|
||||
description = db.Column(db.Text, nullable=False)
|
||||
photo_path = db.Column(db.String(255))
|
||||
@@ -69,6 +70,7 @@ class Issue(db.Model):
|
||||
mobile_local_id = db.Column(db.String(64), nullable=True, index=True) # idempotency key for mobile submissions
|
||||
|
||||
# Relationships
|
||||
facility = db.relationship('Facility', foreign_keys=[facility_id], backref='direct_issues')
|
||||
assigned_user = db.relationship('User', foreign_keys=[assigned_to], backref='assigned_issues')
|
||||
verifier = db.relationship('User', foreign_keys=[verified_by], backref='verified_issues')
|
||||
comments = db.relationship('IssueComment', backref='issue', lazy='dynamic',
|
||||
@@ -81,5 +83,17 @@ class Issue(db.Model):
|
||||
"""Return True if the given user is currently following this issue."""
|
||||
return self.followers.filter_by(user_id=user.id).first() is not None
|
||||
|
||||
@property
|
||||
def resolved_facility(self):
|
||||
"""Returns the Facility for this issue regardless of which path was used to create it.
|
||||
Issues created via the standalone form have facility_id set directly.
|
||||
Issues created via flag_issue (from an inspection) have area_id set.
|
||||
"""
|
||||
if self.facility:
|
||||
return self.facility
|
||||
if self.area:
|
||||
return self.area.facility
|
||||
return None
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Issue {self.id} - {self.severity}>'
|
||||
Reference in New Issue
Block a user