Jul 10 - Update facility's area with QR code

This commit is contained in:
2026-07-10 14:05:54 -04:00
parent 008dd94962
commit 512a80837a
8 changed files with 635 additions and 6 deletions
+17
View File
@@ -50,9 +50,26 @@ class Area(db.Model):
name = db.Column(db.String(255), nullable=False)
area_type = db.Column(db.String(50))
# Phase 39: unguessable token encoded in the area's public QR code.
# The QR points at /f/area/<public_token>, a login-free occupant summary
# page scoped to this area. Backfilled for existing rows by phase39.
public_token = db.Column(db.String(48), nullable=True, unique=True, index=True)
# Relationships
inspections = db.relationship('Inspection', backref='area', lazy='dynamic')
issues = db.relationship('Issue', backref='area', lazy='dynamic')
@staticmethod
def generate_public_token() -> str:
"""Return a fresh URL-safe token for the public QR link."""
return secrets.token_urlsafe(24)
def ensure_public_token(self) -> str:
"""Return this area's public_token, generating & persisting one if it
is missing. The caller is responsible for db.session.commit()."""
if not self.public_token:
self.public_token = self.generate_public_token()
return self.public_token
def __repr__(self):
return f'<Area {self.name}>'