climate_ref.baseline_report.upload
#
Push a rendered report into the report store.
The store is a plain object store with no directory semantics, so every file is uploaded under an explicit key. The content type has to be set per object, or a browser will download the page instead of rendering it.
CONTENT_TYPES = {'.html': 'text/html; charset=utf-8', '.css': 'text/css; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.png': 'image/png', '.svg': 'image/svg+xml'}
module-attribute
#
Content types for the file kinds a report is made of.
A deliberate allowlist rather than :mod:mimetypes, whose answers vary with the host's registry,
and which would not add the charset a browser needs on the text types.
DEFAULT_CONTENT_TYPE = 'application/octet-stream'
module-attribute
#
Served for anything else, which a browser will offer as a download.
content_type_for(path)
#
Return the content type a report file should be served with.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The file, which is classified by its extension. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The MIME type, or :data: |
Source code in packages/climate-ref/src/climate_ref/baseline_report/upload.py
upload_site(out_dir, store, prefix)
#
Upload every file under out_dir as prefix/<relative path>.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_dir
|
Path
|
The rendered site. |
required |
store
|
ReportStore
|
The store to upload into. |
required |
prefix
|
str
|
The key prefix the report is published under, for example |
required |
Returns:
| Type | Description |
|---|---|
str
|
The URL of the report's index page, whether or not that page exists. |