Print a guide light, whatever the screen theme is

Printing a dark-mode page lays a full page of toner down for the background and
knocks the text out of it in white. On a shopfloor printer that is a cartridge
for a handful of guides, and the result is harder to read than the plain
version. Somebody would have found this the expensive way.

The theme tokens are redefined for print only, in an unscoped block because
overriding them has to reach :root. Every guide element already renders through
those variables rather than literal colours, so this is a dozen lines instead of
a rewrite - the same discipline that made dark mode work without dark-mode code.

Backgrounds are dropped rather than printed grey: a callout is identified by its
rule and its heading, which cost nothing. Checkboxes print EMPTY even where they
are ticked on screen, because a printed guide is a worksheet somebody carries to
the bay, and one person's progress is not part of the procedure. The footer
gains the print date beside the version, so a stale copy pinned to a noticeboard
can be spotted.

Also corrects the model and migration found by running this against a real
database rather than SQLite: BaseModel contributes createddate, modifieddate and
isactive to every table and the migration never created them, so the first read
failed on unknown columns; the model had also declared duplicate timestamps on
top, now removed with the API field names kept stable. And the slug is 191
characters, not 300 - it is UNIQUE-indexed, MySQL caps an index key at 767
bytes, and utf8mb4 is 4 bytes per character.
This commit is contained in:
cproudlock
2026-08-26 11:07:06 -04:00
parent 38d1e367fc
commit cc1f8ff9fd
6 changed files with 103 additions and 21 deletions

View File

@@ -74,7 +74,12 @@ class Guide(BaseModel):
# derived on read so an edited title cannot silently break a link somebody
# pasted into a work order.
title = db.Column(db.String(300), nullable=False)
slug = db.Column(db.String(300), nullable=False, unique=True, index=True)
# 191, not 300: this column is UNIQUE-indexed, and MySQL caps an index key
# at 767 bytes. utf8mb4 stores up to 4 bytes per character, so 191 * 4 =
# 764 is the longest indexable string - 300 produces
# "Specified key was too long" the moment the migration runs on a real
# database, having passed every SQLite test.
slug = db.Column(db.String(191), nullable=False, unique=True, index=True)
# One line, shown in the list and in search results.
summary = db.Column(db.String(1000))
@@ -114,11 +119,12 @@ class Guide(BaseModel):
use_alter=True,
name='fk_guides_publishedrevision'))
# createddate / modifieddate / isactive come from BaseModel - no second set
# of timestamps on top of them, or the next person has to work out which
# pair is authoritative. publishedat is ours because "when did readers start
# seeing this" is a different fact from "when was the row last touched".
createdby = db.Column(db.Integer, db.ForeignKey('users.userid'))
updatedby = db.Column(db.Integer, db.ForeignKey('users.userid'))
createdat = db.Column(db.DateTime, nullable=False, default=_utcnow)
updatedat = db.Column(db.DateTime, nullable=False, default=_utcnow,
onupdate=_utcnow)
publishedat = db.Column(db.DateTime)
# The working copy's version number. Bumped only when a save actually
@@ -161,8 +167,10 @@ class Guide(BaseModel):
'tags': self.taglist(),
'status': self.status,
'revision': self.revision,
'createdat': self.createdat.isoformat() + 'Z' if self.createdat else None,
'updatedat': self.updatedat.isoformat() + 'Z' if self.updatedat else None,
# API names stay createdat/updatedat: the column names are a
# storage detail, and renaming a payload field breaks callers.
'createdat': self.createddate.isoformat() + 'Z' if self.createddate else None,
'updatedat': self.modifieddate.isoformat() + 'Z' if self.modifieddate else None,
'publishedat': (self.publishedat.isoformat() + 'Z'
if self.publishedat else None),
}
@@ -212,7 +220,6 @@ class GuideRevision(BaseModel):
note = db.Column(db.String(500))
createdby = db.Column(db.Integer, db.ForeignKey('users.userid'))
createdat = db.Column(db.DateTime, nullable=False, default=_utcnow)
@property
def blocks(self):
@@ -234,7 +241,7 @@ class GuideRevision(BaseModel):
'tags': [t.strip() for t in (self.tags or '').split(',') if t.strip()],
'note': self.note,
'createdby': self.createdby,
'createdat': self.createdat.isoformat() + 'Z' if self.createdat else None,
'createdat': self.createddate.isoformat() + 'Z' if self.createddate else None,
'shorthash': (self.contenthash or '')[:12],
}
if includeblocks:
@@ -268,7 +275,6 @@ class GuideImage(BaseModel):
data = db.Column(db.LargeBinary(length=(2 ** 24) - 1), nullable=False)
uploadedby = db.Column(db.Integer, db.ForeignKey('users.userid'))
createdat = db.Column(db.DateTime, nullable=False, default=_utcnow)
def to_dict(self):
return {
@@ -278,5 +284,5 @@ class GuideImage(BaseModel):
'mimetype': self.mimetype,
'bytesize': self.bytesize,
'url': '/api/guides/images/{}'.format(self.guideimageid),
'createdat': self.createdat.isoformat() + 'Z' if self.createdat else None,
'createdat': self.createddate.isoformat() + 'Z' if self.createddate else None,
}