endi.views.files package

Submodules

endi.views.files.rest_api module

Rest api for file management

GET /api/v1/nodes/:node_id/files

Returns a list of files attached to the given node

HTTP/1.1 200 OK
Content-Type: application/json

[
    {
        "id": 123,
        "label": "My file",
        "name": "My file",
        "size": 1024,
        "human_size": "1ko",
        "mimetype": "application/octet-stream",
        "description": "My file is very important",
        "created_at": "12/05/2023",
        "updated_at": "18/05/2023",
        "file_type_id": 12,
        "parent_id": 12,
    },
    ...
]
POST /api/v1/nodes/:node_id/files

Add a file to the given node (or switch it to another regarding the parameters)

  • In case an indicator_id is given we will try to attach the file to the given

indicator and to its node - In case a file_type_id is given we will try to find an indicator to attach the file to (going also on upper levels)

Paramètres de la forme:
  • name – name of the file

  • description – description of the file

  • upload – File object

  • file_type_id – the FileType’s id

  • indicator_id – Optional Indicator’s id

POST /api/v1/files/

Add a file

Paramètres de la forme:
  • parent_id – the parent’s id

  • name – name of the file

  • description – description of the file

  • upload – File object

  • file_type_id – the FileType’s id

  • indicator_id – Optional Indicator’s id

GET /api/v1/files/:id

Return a specific file

HTTP/1.1 200 OK
Content-Type: application/json

{
    "id": 123,
    "label": "My file",
    "name": "My file",
    "size": 1024,
    "human_size": "1ko",
    "mimetype": "application/octet-stream",
    "description": "My file is very important",
    "created_at": "12/05/2023",
    "updated_at": "18/05/2023",
    "file_type_id": 12,
    "parent_id": 12,
}
PUT /api/v1/files/:id

Allows to edit a specific file

Paramètres de la forme:
  • parent_id – the parent’s id

  • name – name of the file

  • description – description of the file

  • upload – File object

  • file_type_id – the FileType’s id

  • indicator_id – Optional Indicator’s id

class endi.views.files.rest_api.FileRestView(context, request=None)

Bases : BaseRestView

Base rest view for accessing files

dbsession: DBSESSION
delete()

HTTP DELETE api endpoint

get_schema(submitted: dict)

Build the colander schema to be used

Paramètres:

submitted – Data submitted to the api endpoint

Renvoie:

A form schema used to validate the submitted data

move_view()

Get the node id from the request json body, retrieve the Node instance and check if the user has permission to add a file to the node then move the file to this node

query()
request: Request
session: ISession
class endi.views.files.rest_api.NodeFileRestView(context, request=None)

Bases : FileRestView

Common Rest entry point for all node parents

collection_get()
dbsession: DBSESSION
request: Request
session: ISession
endi.views.files.rest_api.includeme(config)

endi.views.files.routes module

endi.views.files.routes.includeme(config)

Add module’s related routes

endi.views.files.views module

class endi.views.files.views.BaseZipFileView(context, request=None)

Bases : BaseView

Base Zip File View, allows to produce an archive with multiple files

E.g :

collect_files() List[File]

Collect the File objects to include in the archive

filename() str
produce_archive(files: List[File]) BytesIO
class endi.views.files.views.FileDeleteView(context, request=None)

Bases : DeleteView, FileViewRedirectMixin

a class:endi.events.files.FileDeleted is fired on file deletion

dbsession: DBSESSION
delete()
delete_msg = None
redirect()
request: Request
session: ISession
class endi.views.files.views.FileEditView(context, request=None)

Bases : FileUploadView

View for file object modification

Current context is the file itself

a class:endi.events.files.FileUpdated is fired on file modification

before(form)

Performs some processing on the form prior to rendering.

By default, this method does nothing. Override this method in your dervived class to modify the form. Your function will be executed immediately after instansiating the form instance in __call__() (thus before obtaining widget resources, considering buttons, or rendering).

dbsession: DBSESSION
edit = True
request: Request
session: ISession
property title

The form title

valid_msg = 'Le fichier a bien été enregistré'
class endi.views.files.views.FileUploadView(context, request=None)

Bases : BaseFormView

Form view for file upload

Current context for this view is the document the file should be attached to (Invoice, Estimation…)

By getting the referrer url from the request object, we provide the redirection to the original page when the file is added

a class:endi.events.files.FileAdded is fired on file modification

before(form)

Performs some processing on the form prior to rendering.

By default, this method does nothing. Override this method in your dervived class to modify the form. Your function will be executed immediately after instansiating the form instance in __call__() (thus before obtaining widget resources, considering buttons, or rendering).

dbsession: DBSESSION
edit = False
factory

alias de File

redirect(come_from)

Build the redirection url

Can be overriden to specify a redirection

request: Request
schema = <endi.forms.files.FileUploadSchema object at 140624326164624 (named )>

Colander schema instance to be used to create the form instance. Provide your schema in your derived class.

session: ISession
submit_success(appstruct)

Insert data in the database

title = 'Téléverser un fichier'
class endi.views.files.views.FileView(context, request=None)

Bases : BaseView, FileViewRedirectMixin

A base file view allowing to tune the way datas is shown

delete_url()
download_url()
edit_url()
get_file_path(action)
populate_actionmenu()
class endi.views.files.views.FileViewRedirectMixin

Bases : PopupMixin

Mixin providing tools to handle redirection from within a File related view

NODE_TYPE_LABEL = {'activity': 'au rendez-vous', 'business': l'affaire", 'cancelinvoice': l'avoir", 'estimation': 'au devis', 'expensesheet': la note de dépenses', 'internalcancelinvoice': l'avoir interne", 'internalestimation': 'au devis interne', 'internalinvoice': la facture interne', 'internalsupplier_invoice': la facture fournisseur interne', 'internalsupplier_order': la commande fournisseur interne', 'invoice': la facture', 'project': 'au dossier', 'supplier_invoice': la facture fournisseur', 'supplier_order': la commande fournisseur', 'userdata': la fiche de gestion sociale', 'workshop': l'atelier"}
NODE_TYPE_ROUTES = {'activity': 'activity', 'business': '/businesses/{id}/files', 'cancelinvoice': '/cancelinvoices/{id}', 'estimation': '/estimations/{id}', 'expensesheet': '/expenses/{id}', 'internalcancelinvoice': '/cancelinvoices/{id}', 'internalestimation': '/estimations/{id}', 'internalinvoice': '/invoices/{id}', 'internalsupplier_invoice': '/supplier_invoices/{id}', 'internalsupplier_order': '/supplier_orders/{id}', 'invoice': '/invoices/{id}', 'project': '/projects/{id}/files', 'supplier_invoice': '/supplier_invoices/{id}', 'supplier_order': '/supplier_orders/{id}', 'trainerdata': '/trainerdatas/{id}/filelist', 'userdata': '/users/{id}/userdatas/filelist', 'workshop': 'workshop'}
back_url()
get_label()
get_redirect_item()
endi.views.files.views.file_dl_view(context, request)

download view for a given file

endi.views.files.views.file_stream_view(context, request)

download view for a given file

Add a button for file attachment

endi.views.files.views.includeme(config)

Configure views

Module contents

endi.views.files.includeme(config)