html: add a summary that repeats the most important fields

This commit is contained in:
Lephenixnoir 2021-04-28 14:35:55 +02:00
parent d78b40f74c
commit 4cb35354a4
Signed by untrusted user: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 19 additions and 5 deletions

View File

@ -4,6 +4,7 @@ constants:
yes: "Yes"
categories:
summary: "Essential summary"
general: "General information"
teaching: "Teaching"
packaging: "Packaging and power"

View File

@ -4,6 +4,7 @@ constants:
yes: "Oui"
categories:
summary: "Les essentiels"
general: "Informations générales"
teaching: "Enseignement"
packaging: "Caractéristiques physiques"

View File

@ -9,6 +9,12 @@ import calcdb
db = calcdb.CalcDB(".")
md = markdown.Markdown()
# Fields for the summary
summary = [
"teaching.exam_mode",
"devices.transfer_tutorial",
]
# Parse arguments
def usage():
@ -118,24 +124,30 @@ for (name, calc) in db.all_calcs():
print(f"<td class='borderless {cssname}{active}'><b>{value}</b></td>")
print("</tr>")
for category in db.all_categories():
# First category, the "summary"
for category in ["summary"] + db.all_categories():
r = lang.category(category)
print(f"<tr class='category'>")
print(f" <th class='category'>{r}</th>")
print(f" <td colspan={len(db.calcs)}></td>")
print(f"</tr>")
for field in db.all_fields(category):
if category == "summary":
fields = (name.split(".", 1) for name in summary)
else:
fields = ((category, field) for field in db.all_fields(category))
for (cat, field) in fields:
if category == "general" and field == "full_name":
continue
r = lang.field(category, field)
r = lang.field(cat, field)
print(f"<tr><th class='field'>{r}</th>")
for (name, calc) in db.all_calcs():
value = calc.get(category,{}).get(field)
value = calc.get(cat,{}).get(field)
r, styles = calcdb.render(db, lang, category, field, value)
r, styles = calcdb.render(db, lang, cat, field, value)
r = lang.filter(r)
r = md.convert(r)