Jul 7 - Implement QR codes for facility

This commit is contained in:
2026-07-07 21:05:07 -04:00
parent 8b5a4758e5
commit faab9fd008
12 changed files with 684 additions and 7 deletions
+11
View File
@@ -16,10 +16,21 @@ class Facility(db.Model):
project_id = db.Column(db.Integer, db.ForeignKey('projects.id', ondelete='SET NULL'),
nullable=True, index=True)
# phase38: unguessable token behind the public QR scan page (/f/<token>).
# NULL until first requested — ensure_qr_token() generates it lazily.
qr_token = db.Column(db.String(64), unique=True, nullable=True)
# Relationships
areas = db.relationship('Area', backref='facility', lazy='dynamic')
inspections = db.relationship('Inspection', backref='facility', lazy='dynamic')
def ensure_qr_token(self):
"""Generate the QR token on first use. Caller commits."""
if not self.qr_token:
import secrets
self.qr_token = secrets.token_urlsafe(32)
return self.qr_token
def __repr__(self):
return f'<Facility {self.name}>'