Skip to content

Commit f3b0d14

Browse files
committed
feat(template): add template ux metadata v1
1 parent 4442809 commit f3b0d14

28 files changed

Lines changed: 773 additions & 14 deletions

README-pypi.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,23 @@ class Importer(BaseModel):
6969
email: Annotated[
7070
Email,
7171
Field(min_length=10),
72-
ExcelMeta(label='Email', order=1, hint='Use your work email'),
72+
ExcelMeta(
73+
label='Email',
74+
order=1,
75+
hint='Use your work email',
76+
example_value='alice@company.com',
77+
),
7378
]
7479

7580

7681
alchemy = ExcelAlchemy(ImporterConfig(Importer, locale='en'))
7782
template = alchemy.download_template_artifact(filename='people-template.xlsx')
7883
```
7984

85+
This template metadata is additive: it leaves the worksheet layout alone and
86+
improves the generated header comment with both guidance text and a concrete
87+
example value.
88+
8089
## Example Outputs
8190

8291
These fixed outputs are generated from the repository examples by

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,23 @@ class Importer(BaseModel):
7171
email: Annotated[
7272
Email,
7373
Field(min_length=10),
74-
ExcelMeta(label='Email', order=1, hint='Use your work email'),
74+
ExcelMeta(
75+
label='Email',
76+
order=1,
77+
hint='Use your work email',
78+
example_value='alice@company.com',
79+
),
7580
]
7681

7782

7883
alchemy = ExcelAlchemy(ImporterConfig(Importer, locale='en'))
7984
template = alchemy.download_template_artifact(filename='people-template.xlsx')
8085
```
8186

87+
This template metadata is additive: it keeps the worksheet layout unchanged and
88+
adds clearer header comments for spreadsheet users, such as a free-form hint
89+
and a concrete example value.
90+
8291
For browser downloads, prefer `template.as_bytes()` with a `Blob`, or return the bytes from your backend with
8392
`Content-Disposition: attachment`. A top-level navigation to a long `data:` URL is less reliable in modern browsers.
8493

docs/getting-started.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ class EmployeeImporter(BaseModel):
7575
age: Annotated[Number, Field(ge=18), ExcelMeta(label='Age', order=2)]
7676
```
7777

78+
If you want generated templates to give users a more concrete example before
79+
upload, you can add template UX metadata such as `hint` and `example_value`:
80+
81+
```python
82+
class EmployeeImporter(BaseModel):
83+
work_email: Annotated[
84+
String,
85+
Field(min_length=8),
86+
ExcelMeta(
87+
label='Work email',
88+
order=3,
89+
hint='Use your company email address',
90+
example_value='alice@company.com',
91+
),
92+
]
93+
```
94+
95+
This is additive. It does not change import behavior or worksheet layout. It
96+
only adds a more helpful header comment in the generated template, for example:
97+
98+
- `Hint: Use your company email address`
99+
- `Example: alice@company.com`
100+
78101
## 4. Pick The Workflow You Need
79102

80103
Import-only create flow:

docs/public-api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ These modules are the recommended import paths for application code:
3030
- `excelalchemy.metadata`
3131
Public metadata entry points such as `FieldMeta(...)`, `ExcelMeta(...)`, and
3232
`PatchFieldMeta`.
33+
Template guidance metadata such as `hint=` and `example_value=` is part of
34+
this additive public surface.
3335
- `excelalchemy.results`
3436
Structured import result models such as `ImportResult`,
3537
`ValidateResult`, and `ValidateHeaderResult`.

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Use them to understand how the library is intended to be used from application c
3232

3333
- `examples/annotated_schema.py`
3434
- Demonstrates the modern `Annotated[..., Field(...), ExcelMeta(...)]` declaration style.
35+
- Shows additive template UX metadata such as `hint=` and `example_value=`.
3536
- Type: demo of the recommended declaration style.
3637

3738
- `examples/employee_import_workflow.py`

examples/annotated_schema.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ class EmployeeImporter(BaseModel):
1111
full_name: Annotated[
1212
String,
1313
Field(min_length=2),
14-
ExcelMeta(label='Full name', order=1, hint='Use the legal name'),
14+
ExcelMeta(label='Full name', order=1, hint='Use the legal name', example_value='Alice Chen'),
1515
]
1616
age: Annotated[Number, Field(ge=18), ExcelMeta(label='Age', order=2)]
1717
work_email: Annotated[
1818
Email,
1919
Field(min_length=8),
20-
ExcelMeta(label='Work email', order=3, hint='Use your company email address'),
20+
ExcelMeta(
21+
label='Work email',
22+
order=3,
23+
hint='Use your company email address',
24+
example_value='alice.chen@company.com',
25+
),
2126
]
2227

2328

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Generated template: employee-template.xlsx (6803 bytes)
1+
Generated template: employee-template.xlsx (6853 bytes)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
memory://employees.xlsx
2-
Uploaded bytes: 6813
2+
Uploaded bytes: 6836
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Generated template: compensation-template.xlsx (6862 bytes)
1+
Generated template: compensation-template.xlsx (6882 bytes)
22
Fields: Start date, Probation window, Salary band, Signing bonus
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Export workflow completed
22
Artifact filename: employees-export.xlsx
3-
Artifact bytes: 6893
3+
Artifact bytes: 6909
44
Upload URL: memory://employees-export-upload.xlsx
55
Uploaded objects: ['employees-export-upload.xlsx']

0 commit comments

Comments
 (0)