With custom widget, a live view of A4 printing

Hello,

Being very bad in code, I tried to make something not too bad that could suit me.

In the project, I absolutely had to have a board that was easy to understand, to use with as few errors as possible and visually dynamic.

The structure consists of two lists, commerce and distributor. The aim of the board is to click on a distributor, to see his personal information and also to see the companies assigned to him.
After that, it was essential to have a dynamic view and a concise, precise print layout.
Here’s the github link for inspiration if you’re so inclined, and below is the structure of the table that goes with it (which is very simple). GitHub - sebschopf/grist-print-widget: widget for print view in A4 format paper

It’s nothing revolutionary, but maybe people will have ideas for adapting a constructible print widget, who knows?

If you want to react, do so. I don’t know much about the code, so I’m not really going to be able to optimize it or do anything spectacular with it. Fork the project, adapt it! Make it better! I can’t go any further, it’s really made for my structure. I can’t make it dynamic with column and field options to add and modify.
Perhaps a WYSYWYNG version? I don’t know.

Enjoy.

import grist
from functions import *       # global uppercase functions
import datetime, math, re     # modules commonly needed in formulas


@grist.UserTable
class Distributeurs_2025:
  Forme_politesse = grist.Text()
  NOM = grist.Text()
  Prenom = grist.Text()
  Code_Postal = grist.Text()
  Localite = grist.Text()
  Tel_fixe = grist.Text()
  Tel_portable = grist.Text()
  Adresse_electronique = grist.Text()
  Adresse_electronique_2 = grist.Text()
  Remarques = grist.Text()
  statut = grist.Choice()
  Activite = grist.ChoiceList()
  Numero = grist.Text()
  Rue = grist.Text()

  @grist.formulaType(grist.Text())
  def Adresse_complete(rec, table):
    rue = rec.Rue if rec.Rue else ""
    numero = rec.Numero if rec.Numero else ""
    code_postal = str(rec.Code_Postal) if rec.Code_Postal else ""
    localite = rec.Localite if rec.Localite else ""

    return f"{rue} {numero}, {code_postal} {localite}".strip()

  @grist.formulaType(grist.Text())
  def Nom_complet(rec, table):
    return f"{rec.NOM} {rec.Prenom}"

  @grist.formulaType(grist.Numeric())
  def Totale_Tirelires(rec, table):
    total_tirelires = 0.0
    for commercant in T2024_commercants.lookupRecords():
        if rec in commercant.Distributeur:
            total_tirelires += commercant.Tirelires
    return total_tirelires

  def T2024_commercants_Distributeur(rec, table):
    return T2024_commercants.lookupRecords(Distributeur=CONTAINS(rec.id)).Distributeur


@grist.UserTable
class T2024_commercants:
  NOM = grist.Text()
  Rue = grist.Text()
  Numero = grist.Text()
  Commune = grist.Text()
  Code_Postal = grist.Text()
  Distributeur = grist.ReferenceList('Distributeurs_2025')
  Tirelires = grist.Numeric()
1 Like

This looks useful, thanks for sharing! Unfortunately, we can’t copy/paste the schema to test it out easily. Would you be able to share an example document? That should make it possible for others to more easily test/modify.