project

Module Contents

Functions

show_projects(db: db.mongodb.AsyncIOMotorClient = Depends(get_database), page_size: Optional[int] = 10, page_number: Optional[int] = 1)

Get all projects paginated (using skip & limit)

show_projects(db: db.mongodb.AsyncIOMotorClient = Depends(get_database), page_size: Optional[int] = 10, page_number: Optional[int] = 1)

Get all projects paginated (using skip & limit)

add_new_project(project: models.iemap.newProject, db: db.mongodb.AsyncIOMotorClient = Depends(get_database)) → dict

Add new project (metadata)

create_project_file(file_name: str, project_id: models.iemap.ObjectIdStr, file: fastapi.UploadFile = File(...), db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

Add a new file to an existing project

create_property_file(project_id: models.iemap.ObjectIdStr, property_name: str, property_type: str, file: fastapi.UploadFile = File(...), db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

Add a new property file to an existing project

get_list_process_properties_by_proj_name_and_affiliation(affiliation: str, projectName: str, request: fastapi.Request, db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

GET list process properties associated to a project filtered by affiliation and project name

form_add_property_and_file(project_id: models.iemap.ObjectIdStr, form_data: models.iemap.PropertyForm = Depends(PropertyForm.as_form), fileupload: Optional[fastapi.UploadFile] = File(None), db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

Add a new property and file to an existing project

form_add_project_file(project_id: models.iemap.ObjectIdStr, form_data: models.iemap.ProjectFileForm = Depends(ProjectFileForm.as_form), fileupload: fastapi.UploadFile = File(...), db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

Add file to project using Multi-Part Form data

Attributes

upload_dir

logger

router

upload_dir

project.upload_dir
project.logger
project.router
project.upload_dir
async project.show_projects(db: db.mongodb.AsyncIOMotorClient = Depends(get_database), page_size: Optional[int] = 10, page_number: Optional[int] = 1)

Get all projects paginated (using skip & limit)

Parameters
  • db (AsyncIOMotorClient) – Motor client connection to MongoDB. Defaults to Depends(get_database).

  • page_size (Optional[int], optional) – size paginated results. Defaults to 10.

  • page_number (Optional[int], optional) – actual page number returned. Defaults to 1.

Returns

{“skip” (int): number of docs to skip,

”page_size” (int): number of results to return in a single page, “page_number” (int): actual page number returned, “page_tot” (int): total number of pages available, “number_docs” (int): total number of documents in collection, “data” list[ProjetModel]: list of all projects saved in database}

Return type

dict

async project.show_projects(db: db.mongodb.AsyncIOMotorClient = Depends(get_database), next_key: str = None, page_size: Optional[int] = 10, page_number: Optional[int] = 1)
async project.add_new_project(project: models.iemap.newProject, db: db.mongodb.AsyncIOMotorClient = Depends(get_database)) dict

Add new project (metadata)

Parameters
  • db (AsyncIOMotorClient, optional) – Motor client connection to MongoDB. Defaults to Depends(get_database).

  • project (NewProjectModel) – project metadata to store on DB. Defaults to None.

Returns

{“inserted_id”: ObjectID} where ObjectID is the document ID inserted in DB

(use this ID as path parameter to add files to project)

Return type

dict

async project.create_project_file(file_name: str, project_id: models.iemap.ObjectIdStr, file: fastapi.UploadFile = File(...), db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

Add a new file to an existing project

Note

project_id, file_name and file extention (retrieved by backend) are used to find the project to which add the file, if these details does not match that already on server, the file is not added to the project, and a HTTP_500_INTERNAL_SERVER_ERROR is returned.

Parameters
  • file_name (str) – name of file to add

  • project_id (ObjectIdStr) – the project ID as saved on DB (returned by {URI}/api/v1/project/add)

  • file (UploadFile) – the file to add to the project (saved on filesystem using its hash)

  • db (AsyncIOMotorClient) – Motor client connection to MongoDB.

Raises
  • HTTPException – HTTP 400 if the file to add to project is not a PDF,CSV, TXT, CIF or DOC

  • HTTPException – HTTP 500 INTERNAL_SERVER_ERROR if it fails to update document in DB

Returns

{“file_name”: name of file, “file_hash”: hash of file as saved on file system, “file_size”: file size in human readable form}

Return type

dict

async project.create_property_file(project_id: models.iemap.ObjectIdStr, property_name: str, property_type: str, file: fastapi.UploadFile = File(...), db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

Add a new property file to an existing project

Parameters
  • project_id (ObjectIdStr) – id of project to add property file to

  • property_name (str) – name of property to which add the file

  • property_type (str) – name of property type to which add the file

  • file (UploadFile) – file to upload. Defaults to File(…).

  • db (AsyncIOMotorClient, optional) – Motor client connection to MongoDB. Defaults to Depends(get_database).

Raises
  • HTTPException – HTTP Error 400 is returned if a file not allowed is uploaded

  • HTTPException – HTTP Error 400 is returned no file is provided

  • HTTPException – HTTP Error 500 is returned if it was not possible to add the file to the project

Returns

{

“file_name”: name of file added to property, “file_hash”: hash of file as saved on file system, “file_size”: file size in human readable form

}

Return type

dict

async project.get_list_process_properties_by_proj_name_and_affiliation(affiliation: str, projectName: str, request: fastapi.Request, db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

GET list process properties associated to a project filtered by affiliation and project name

Parameters
  • affiliation (str) – affiliation of project’s user (TODO:retrieved from JWT)

  • projectName (str) – name of project

  • request (Request) – _description_

  • db (AsyncIOMotorClient, optional) – Motor client connection to MongoDB. Defaults to Depends(get_database).

Returns

list of properties files associated to a project

(if one or more file associated exists an additional “url” field is added within the field “file”)

Return type

dict

async project.form_add_property_and_file(project_id: models.iemap.ObjectIdStr, form_data: models.iemap.PropertyForm = Depends(PropertyForm.as_form), fileupload: Optional[fastapi.UploadFile] = File(None), db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

Add a new property and file to an existing project

Parameters
  • project_id (ObjectIdStr) – id of project to add property file to

  • form_data (PropertyForm, optional) – project property

  • fileupload (Optional[UploadFile], optional) – File associated to property to upload. Defaults to File(None).

  • db (AsyncIOMotorClient, optional) – Motor client connection to MongoDB. Defaults to Depends(get_database).

Raises
  • HTTPException – HTTP Error 500 if it was not possible to add the property to the project

  • HTTPException – HTTP Error 500 if it was not possible save the file to project

Returns

{
“modified_count” (int): modified_count,

”hash_file” (str , Optional): hash file saved on disk, “file_size” (str, Optional): file size in human readable form, “file_ext”(str, Optional): file extension,

}

Return type

dict

async project.form_add_project_file(project_id: models.iemap.ObjectIdStr, form_data: models.iemap.ProjectFileForm = Depends(ProjectFileForm.as_form), fileupload: fastapi.UploadFile = File(...), db: db.mongodb.AsyncIOMotorClient = Depends(get_database))

Add file to project using Multi-Part Form data

Parameters
  • project_id (ObjectIdStr) – document id to add file to

  • form_data (ProjectFileForm) – form data fields. Defaults to Depends(ProjectFileForm.as_form).

  • fileupload (UploadFile) – file to upload (as form key use ‘fileupload’).

  • db (AsyncIOMotorClient) – Motor client connection to MongoDb. Defaults to Depends(get_database).

Raises
  • HTTPException – HTTP 500 Internal Server Error if unable to save file

  • HTTPException – HTTP 400 bad request if file was not provided

Returns

{

“hash_file”(str): hash file saved on file system, “file_size”(str): file size in human readable format, “file_ext”(str): file extension

}

Return type

dict