Skip to content

Commit

Permalink
excludes sqlalchemy from module loading
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Nov 7, 2024
1 parent f9c9fbb commit 238150e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 25 deletions.
74 changes: 52 additions & 22 deletions aim/digifeeds/database/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Digifeeds Models
================
================
"""

from sqlalchemy import String, ForeignKey, DateTime
Expand All @@ -15,55 +15,85 @@ 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")

# 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 = []
Expand Down
14 changes: 11 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,5 +41,5 @@
html_theme_options = {
"navigation_depth": 5,
"collapse_navigation": False,
"titles_only": True
"titles_only": True,
}

0 comments on commit 238150e

Please sign in to comment.