Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
uploads : Managing uploaded files¶
The lino.modlib.uploads plugin adds functionality for managing
upload files.
We assume that you have read the end-user docs.
There is also an extension of this plugin, the lino_xl.lib.uploads
plugin, which is described in Uploads with expiration date management.
This page contains code snippets (lines starting with >>>), which are
being tested during our development workflow. The following
snippet initializes the demo project used throughout this page.
>>> from lino_book.projects.cosi1.startup import *
Upload files¶
- class lino.modlib.uploads.Upload¶
Django model representing an upload file.
- file¶
Pointer to the uploaded file itself (a Django FileField).
- file_size¶
The size of the file in bytes. Not yet implemented.
- mimetype¶
The media type of the uploaded file.
See also this thread about length of MIME type field.
- type¶
The type of this upload.
Pointer to
UploadType. The choices for this field are usually limited to those in the same upload area.
- description¶
A short description entered manually by the user.
- volume¶
A pointer to the library volume where this file is stored.
- upload_area¶
The upload area this file belongs to.
- library_file¶
The path of this file, relative the volume’s root.
- description_link¶
Almost the same as
description, but iffileis not empty, the text is clickable, and clicking on it opens the uploaded file in a new browser window.
- class lino.modlib.uploads.Uploads¶
Base class for all data tables of upload files.
- class lino.modlib.uploads.AllUploads¶
Shows all upload files on this Lino site.
Visible to the end user as .
>>> rt.show(uploads.AllUploads, language="en", display_mode=DISPLAY_MODE_GRID)
==== ===================================================== ================================= ================= ================= =====================
ID Description File Upload type Uploaded by Attached to
---- ----------------------------------------------------- --------------------------------- ----------------- ----------------- ---------------------
11 Found on 2025-03-12 by uploads.UploadsFolderChecker uploads/2025/03/foo.pdf Rolf Rompen
10 Found on 2025-03-12 by uploads.UploadsFolderChecker uploads/orphan.txt Rolf Rompen
9 uploads/2025/03/PRC_21_2025.pdf Source document Robin Rood `PRC 21/2025 <…>`__
8 uploads/2025/03/PRC_20_2025.pdf Source document Rolf Rompen `PRC 20/2025 <…>`__
7 uploads/2025/03/PRC_19_2025.pdf Source document Romain Raffault `PRC 19/2025 <…>`__
6 uploads/2025/03/PRC_18_2025.pdf Source document Robin Rood `PRC 18/2025 <…>`__
5 uploads/2025/03/PRC_17_2025.pdf Source document Rolf Rompen `PRC 17/2025 <…>`__
4 uploads/2025/03/PRC_16_2025.pdf Source document Romain Raffault `PRC 16/2025 <…>`__
3 uploads/2025/03/PRC_15_2025.pdf Source document Robin Rood `PRC 15/2025 <…>`__
2 screenshot-toolbar.png
1 Screenshot 20250124 104858.png
==== ===================================================== ================================= ================= ================= =====================
- class lino.modlib.uploads.AreaUploads¶
Mixin for tables of upload files where the upload area is known.
The summary displays the upload files as a list grouped by uploads type.
This is inherited by
UploadsByController.This also works on
lino_welfare.modlib.uploads.UploadsByProjectand their subclasses for the different _upload_area.
- class lino.modlib.uploads.MyUploads¶
Shows my uploads (i.e. those whose author is the requesting user).
>>> rt.login('robin').show(uploads.MyUploads) ([Eingangsdokument PRC_21_2025.pdf](/media/uploads/2025/03/PRC_21_2025.pdf)| [Detail](…)) ([Eingangsdokument PRC_18_2025.pdf](/media/uploads/2025/03/PRC_18_2025.pdf)| [Detail](…)) ([Eingangsdokument PRC_15_2025.pdf](/media/uploads/2025/03/PRC_15_2025.pdf)| [Detail](…))
Upload areas¶
The application developer can define upload areas. Every upload area has its list of upload types. The default has only one upload area.
>>> rt.show(uploads.UploadAreas, language="en")
======= ========= =========
value name text
------- --------- ---------
90 general Uploads
======= ========= =========
For example Lino Welfare extends this list.
Upload types¶
- class lino.modlib.uploads.UploadType¶
Django model representing an upload type.
- class lino.modlib.uploads.UploadTypes¶
The table with all existing upload types.
This usually is accessible via the Configure menu.
Upload controllers¶
An upload file is usually attached to a another database object called its controller. Upload files without a controller are considered “useless”, and the site manager should decide what to do with them.
- upload controller¶
A database object that can potentially have uploaded files associated to it.
Any database model that inherits from
UploadController.
- class lino.modlib.uploads.UploadController¶
Model mixin for database objects that can have upload files associated to them.
Turns a model into an upload controller.
- show_uploads¶
Opens a data window with the uploaded files associated to this database object.
This action is automatically shown in the toolbar as a ❏ button.
Additionally to UploadController.show_uploads, the application
developer can decide to add a slave panel UploadsByController
to the detail layout of any upload controller.
- class lino.modlib.uploads.UploadsByController¶
Shows the uploaded files associated to this database object.
This panel gives a summary of the upload files linked to this database row. This summary is influenced by the configuration of upload types.
>>> # obj = vat.VatAccountInvoice.objects.get(id=105)
>>> obj = vat.VatAccountInvoice.objects.get(number=20, fiscal_year__ref="2025")
>>> rt.show(uploads.UploadsByController, obj)
`⏏ <…>`__ | Eingangsdokument: `PRC_20_2025.pdf <…>`__ `⎙ </media/uploads/2025/03/PRC_20_2025.pdf>`__
Upload shortcuts¶
The application developer can define upload shortcuts. Every upload shortcut will create an upload shortcut field, a virtual field with a set of actions for quickly uploading or viewing uploads of a particular type for a given database object.
Usage:
Declare your Site’s upload shortcuts from within your
workflows_module. For example:from lino.modlib.uploads.choicelists import add_shortcut as add add('contacts.Person', 'uploaded_foos', _("Foos"))
Make the
uploaded_foosfield visible in some detail layout.Using the web interface, select , create an upload type named “Foo” and set its shortcut field to “Foos”.
Upload a file from your PC to the server.
Open the uploaded file in a new browser window
- class lino.modlib.uploads.Shortcuts¶
The list of available upload shortcut fields in this application.
>>> rt.show(uploads.Shortcuts, language="en")
==================================== ================= =================
value name text
------------------------------------ ----------------- -----------------
accounting.Voucher.source_document source_document Source document
==================================== ================= =================
- lino.modlib.uploads.add_shortcut(*args, **kw)¶
Declare an upload shortcut field. This is designed to be called from within a
workflows_moduleor alino.core.plugins.Plugin.before_analyze().
Previewers¶
Lino currently offers only two previewers, “full” and “small”, and these two
names are used in miscellaneous places of the source code. For example when
rendering an Upload row as a list item, Lino uses the “small”
previewer, but when rendering a detail view it uses the “full” previewer.
Data checkers¶
This plugin defines two data checkers:
- class lino.modlib.uploads.UploadChecker¶
- class lino.modlib.uploads.UploadsFolderChecker¶
Find orphaned files in uploads folder.
Walks through the uploads folder and reports files for which there is no upload entry