Skip to content

Commit

Permalink
Model for CourseRoster
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Aug 29, 2024
1 parent 2adc0e4 commit 968539b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions lms/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from lms.models.assignment_grouping import AssignmentGrouping
from lms.models.assignment_membership import AssignmentMembership
from lms.models.course_groups_exported_from_h import CourseGroupsExportedFromH
from lms.models.course_roster import CourseRoster
from lms.models.dashboard_admin import DashboardAdmin
from lms.models.event import Event, EventData, EventType, EventUser
from lms.models.exceptions import ReusedConsumerKey
Expand Down
30 changes: 30 additions & 0 deletions lms/models/course_roster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from sqlalchemy import ForeignKey, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship

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


class CourseRoster(Base, CreatedUpdatedMixin):
__tablename__ = "course_roster"

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

lms_course_id: Mapped[int] = mapped_column(
ForeignKey("lms_course.id", ondelete="cascade")
)
lms_course = relationship("LMSCourse")

lms_user_id: Mapped[int] = mapped_column(
ForeignKey("lms_user.id", ondelete="cascade")
)
lms_user = relationship("LMSUser")

lti_role_id: Mapped[int] = mapped_column(
ForeignKey("lti_role.id", ondelete="cascade")
)
lti_role = relationship("LTIRole")

active: Mapped[bool] = mapped_column()

__table_args__ = (UniqueConstraint("lms_course_id", "lms_user_id", "lti_role_id"),)
4 changes: 2 additions & 2 deletions lms/models/lti_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LTIRole(Base):

id = sa.Column(sa.Integer(), autoincrement=True, primary_key=True)

_value = sa.Column("value", sa.UnicodeText(), nullable=False, unique=True)
_value: Mapped[str] = mapped_column("value", sa.UnicodeText(), unique=True)
"""The raw string from LTI params."""

type = varchar_enum(RoleType)
Expand All @@ -80,7 +80,7 @@ class LTIRole(Base):
"""Scope where this role applies"""

@hybrid_property
def value(self):
def value(self) -> str:
return self._value

@value.inplace.setter
Expand Down
4 changes: 3 additions & 1 deletion lms/models/lti_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def is_admin(self):
)


def display_name(given_name, family_name, full_name, custom_display_name):
def display_name(
given_name: str, family_name: str, full_name: str, custom_display_name: str
):
"""
Return an h-compatible display name the given name parts.
Expand Down
1 change: 1 addition & 0 deletions tests/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
TOOL_CONSUMER_INSTANCE_GUID,
USER_ID,
)
from tests.factories.course_roster import CourseRoster
from tests.factories.dashboard_admin import DashboardAdmin
from tests.factories.event import Event
from tests.factories.file import File
Expand Down
6 changes: 6 additions & 0 deletions tests/factories/course_roster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from factory import make_factory
from factory.alchemy import SQLAlchemyModelFactory

from lms import models

CourseRoster = make_factory(models.CourseRoster, FACTORY_CLASS=SQLAlchemyModelFactory)

0 comments on commit 968539b

Please sign in to comment.