9. Updater for existing spreadsheets

A module to handle the update of file batch. This module contains the BatchUpdater class. It requires multiple interaction with the database, the local filesystem and the Google Drive API.

exception ptmd.lib.updater.batch.BatchError(message: str, code: int)

Bases: Exception

A custom exception class to handle errors in the BatchUpdater class. This lets us return a response with a custom message and status code. We may want to make this a generic class to handle all errors.

args
serialize() tuple[flask.wrappers.Response, int]

Method to serialize the exception into a tuple containing a JSON response and a status code

Returns

a tuple containing a JSON response and a status code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class ptmd.lib.updater.batch.BatchUpdater(batch: str, file_id: int | None = None, filepath: str | None = None)

Bases: object

Class to update the batch of a file. Works both with files in the database and local files.

Parameters
  • batch – the new batch

  • file_id – the id of the file to be updated from the database

  • filepath – the path of the file to be updated from the local filesystem

file_id: int
filepath: str
modify_in_db() File

Method to modify the batch in the file from the database

modify_in_file() str

Method to modify the batch in the file from the local filesystem

old_batch: str
organisation_name: str