Jul 7 - Implement QR codes for facility
This commit is contained in:
@@ -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}>'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user