Skip to content

Commit

Permalink
Allow fetching inactive students
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoni-Czaplicki committed Mar 14, 2024
1 parent 371dfd9 commit c93210c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
9 changes: 6 additions & 3 deletions vulcan/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ._api import Api
from ._data import VulcanData
from ._utils import log
from .model import Student
from .model import State, Student


class Vulcan:
Expand Down Expand Up @@ -50,15 +50,18 @@ def set_logging_level(logging_level: int):
"""
log.setLevel(logging_level)

async def get_students(self, cached=True) -> List[Student]:
async def get_students(
self, state: State = State.ACTIVE, cached=True
) -> List[Student]:
"""Gets students assigned to this account.
:param state: the state of the students to get
:param bool cached: whether to allow returning the cached list
:rtype: List[:class:`~vulcan.model.Student`]
"""
if self._students and cached:
return self._students
self._students = await Student.get(self._api)
self._students = await Student.get(self._api, state)
return self._students

@property
Expand Down
2 changes: 1 addition & 1 deletion vulcan/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ._pupil import Gender, Pupil
from ._school import School
from ._serializable import Serializable
from ._student import Student
from ._student import State, Student
from ._subject import Subject
from ._teacher import Teacher
from ._team import TeamClass, TeamVirtual
Expand Down
19 changes: 16 additions & 3 deletions vulcan/model/_student.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from enum import Enum
from typing import List

from related import ChildField, SequenceField, StringField, immutable
Expand All @@ -11,6 +12,17 @@
from ._unit import Unit


class State(Enum):
"""Student state enumeration.
:cvar int ACTIVE: active student
:cvar int INACTIVE: inactive student
"""

ACTIVE = 0
INACTIVE = 3


@immutable
class Student(Serializable):
"""A student object, along with his school, class and period information
Expand All @@ -31,6 +43,7 @@ class Student(Serializable):
class_: str = StringField(key="ClassDisplay")
symbol: str = StringField(key="TopLevelPartition")
symbol_code: str = StringField(key="Partition")
state: State = ChildField(State, key="State")

pupil: Pupil = ChildField(Pupil, key="Pupil")
unit: Unit = ChildField(Unit, key="Unit")
Expand Down Expand Up @@ -71,11 +84,11 @@ def period_by_id(self, period_id: int) -> Period:
return next((period for period in self.periods if period.id == period_id), None)

@classmethod
async def get(cls, api, **kwargs) -> List["Student"]:
async def get(cls, api, state, **kwargs) -> List["Student"]:
"""
:rtype: List[:class:`~vulcan.model.Student`]
"""
data = await api.get(STUDENT_LIST, **kwargs)
return [
Student.load(student) for student in data if student["State"] == 0
] # Ignore old student profiles that Vulcan started returning in their API
Student.load(student) for student in data if student["State"] == state.value
]

0 comments on commit c93210c

Please sign in to comment.