diff --git a/aim/digifeeds/database/models.py b/aim/digifeeds/database/models.py index b69850a..e3d0985 100644 --- a/aim/digifeeds/database/models.py +++ b/aim/digifeeds/database/models.py @@ -1,6 +1,6 @@ """ Digifeeds Models -================ +================ """ from sqlalchemy import String, ForeignKey, DateTime @@ -15,35 +15,49 @@ class Base(DeclarativeBase): class Item(Base): - __tablename__ = 'items' + """ + A representation of a digifeeds item. It has a barcode and statuses. + """ - barcode: Mapped[str] = mapped_column( - String(256), unique=True, primary_key=True) + __tablename__ = "items" + + barcode: Mapped[str] = mapped_column(String(256), unique=True, primary_key=True) created_at: Mapped[datetime.datetime] = mapped_column( - DateTime(timezone=True), server_default=func.now()) + DateTime(timezone=True), server_default=func.now() + ) statuses: Mapped[list["ItemStatus"]] = relationship() class Status(Base): - __tablename__ = 'statuses' - id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) + """ + A representation of a digifeeds status. It has a name and a description. + """ + + __tablename__ = "statuses" + id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) name: Mapped[str] = mapped_column(String(256)) - description: Mapped[str] = mapped_column(String(499)) + description: Mapped[str] = mapped_column(String(499)) items: Mapped[list["ItemStatus"]] = relationship() def __repr__(self): - return (f'Status(id={self.id}, name={self.name}, description={self.description})') + return f"Status(id={self.id}, name={self.name}, description={self.description})" class ItemStatus(Base): - __tablename__ = 'item_statuses' + """ + An association table for items and statuses. It includes the timestamp at + which the status for an item was created. + """ + + __tablename__ = "item_statuses" item_barcode: Mapped[int] = mapped_column( - ForeignKey('items.barcode'), primary_key=True) - status_id: Mapped[int] = mapped_column( - ForeignKey('statuses.id'), primary_key=True) + ForeignKey("items.barcode"), primary_key=True + ) + status_id: Mapped[int] = mapped_column(ForeignKey("statuses.id"), primary_key=True) # https://docs.sqlalchemy.org/en/20/core/functions.html#sqlalchemy.sql.functions.now Tell the db to set the date. created_at: Mapped[datetime.datetime] = mapped_column( - DateTime(timezone=True), server_default=func.now()) + DateTime(timezone=True), server_default=func.now() + ) item: Mapped["Item"] = relationship(back_populates="statuses") status: Mapped["Status"] = relationship(back_populates="items") @@ -51,19 +65,35 @@ class ItemStatus(Base): # proxies status_name = association_proxy(target_collection="status", attr="name") status_description = association_proxy( - target_collection="status", attr="description") + target_collection="status", attr="description" + ) def load_statuses(session: Session): + """ + Takes the list of statuses in the function and loads them into the digifeeds database. + + Args: + session (Session): A SqlAlchemy session object + """ statuses = [ {"name": "in_zephir", "description": "Item is in zephir"}, - {"name": "added_to_digifeeds_set", - "description": "Item has been added to the digifeeds set"}, - {"name": "copying_start", - "description": "The process for zipping and copying an item to the pickup location has started"}, - {"name": "copying_end", "description": "The process for zipping and copying an item to the pickup location has completed successfully"}, - {"name": "pending_deletion", - "description": "The item has been copied to the pickup location and can be deleted upon ingest confirmation"}, + { + "name": "added_to_digifeeds_set", + "description": "Item has been added to the digifeeds set", + }, + { + "name": "copying_start", + "description": "The process for zipping and copying an item to the pickup location has started", + }, + { + "name": "copying_end", + "description": "The process for zipping and copying an item to the pickup location has completed successfully", + }, + { + "name": "pending_deletion", + "description": "The item has been copied to the pickup location and can be deleted upon ingest confirmation", + }, {"name": "not_found_in_alma", "description": "Barcode wasn't found in Alma"}, ] objects = [] diff --git a/docs/conf.py b/docs/conf.py index fe52415..d529700 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,8 +14,16 @@ # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration -extensions = ["sphinx.ext.napoleon", "sphinx.ext.viewcode", "sphinx.ext.autosummary", - "sphinx.ext.autodoc", 'myst_parser', 'sphinxcontrib.mermaid', "sphinx_toolbox.more_autodoc.autonamedtuple"] +extensions = [ + "sphinx.ext.napoleon", + "sphinx.ext.viewcode", + "sphinx.ext.autosummary", + "sphinx.ext.autodoc", + "myst_parser", + "sphinxcontrib.mermaid", + "sphinx_toolbox.more_autodoc.autonamedtuple", +] +autodoc_mock_imports = ["sqlalchemy"] autosummary_generate = True mermaid_d3_zoom = True @@ -33,5 +41,5 @@ html_theme_options = { "navigation_depth": 5, "collapse_navigation": False, - "titles_only": True + "titles_only": True, }