Skip to content

Commit

Permalink
Model changes for LMSTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Jan 27, 2025
1 parent 34111de commit e0d995d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions lms/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
LMSCourseMembership,
)
from lms.models.lms_segment import LMSSegment, LMSSegmentMembership
from lms.models.lms_term import LMSTerm
from lms.models.lms_user import LMSUser, LMSUserApplicationInstance
from lms.models.lti_params import CLAIM_PREFIX, LTIParams
from lms.models.lti_registration import LTIRegistration
Expand Down
7 changes: 6 additions & 1 deletion lms/models/lms_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from lms.models._mixins import CreatedUpdatedMixin

if TYPE_CHECKING:
from lms.models import LMSUser, LTIRole
from lms.models import LMSTerm, LMSUser, LTIRole


class LMSCourse(CreatedUpdatedMixin, Base):
Expand Down Expand Up @@ -58,6 +58,11 @@ class LMSCourse(CreatedUpdatedMixin, Base):
ends_at: Mapped[datetime | None] = mapped_column()
"""The end date of the course. Only for when we get this information directly from the LMS"""

lms_term_id: Mapped[int | None] = mapped_column(
sa.ForeignKey("lms_term.id", ondelete="cascade"), index=True
)
lms_term: Mapped["LMSTerm"] = relationship()


class LMSCourseApplicationInstance(CreatedUpdatedMixin, Base):
"""Record of on which installs (application instances) we have seen one course."""
Expand Down
28 changes: 28 additions & 0 deletions lms/models/lms_term.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from datetime import datetime

from sqlalchemy.orm import Mapped, mapped_column

from lms.db import Base
from lms.models._mixins import CreatedUpdatedMixin


class LMSTerm(CreatedUpdatedMixin, Base):
__tablename__ = "lms_term"

id: Mapped[int] = mapped_column(autoincrement=True, primary_key=True)

tool_consumer_instance_guid: Mapped[str | None] = mapped_column(index=True)

name: Mapped[str | None] = mapped_column()

starts_at: Mapped[datetime | None] = mapped_column()
"""The start date of the term."""

ends_at: Mapped[datetime | None] = mapped_column()
"""The end date of the term."""

key: Mapped[str] = mapped_column(index=True, unique=True)
"""Not all installs will send us an ID so we'll mantaint an internal key to be able to idneitfy each term and avoid duplicates."""

lms_id: Mapped[str | None] = mapped_column(index=True)
"""ID of this term on the LMS."""

0 comments on commit e0d995d

Please sign in to comment.