diff --git a/vulcan/_client.py b/vulcan/_client.py index cffbdf9..212de2c 100644 --- a/vulcan/_client.py +++ b/vulcan/_client.py @@ -4,7 +4,7 @@ from ._api import Api from ._data import VulcanData from ._utils import log -from .model import Student +from .model import Student, StudentState class Vulcan: @@ -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: StudentState = StudentState.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 diff --git a/vulcan/model/__init__.py b/vulcan/model/__init__.py index 43b4702..721af1d 100644 --- a/vulcan/model/__init__.py +++ b/vulcan/model/__init__.py @@ -7,7 +7,7 @@ from ._pupil import Gender, Pupil from ._school import School from ._serializable import Serializable -from ._student import Student +from ._student import Student, StudentState from ._subject import Subject from ._teacher import Teacher from ._team import TeamClass, TeamVirtual diff --git a/vulcan/model/_student.py b/vulcan/model/_student.py index 870b7bb..bd252d8 100644 --- a/vulcan/model/_student.py +++ b/vulcan/model/_student.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from enum import Enum from typing import List from related import ChildField, SequenceField, StringField, immutable @@ -12,6 +13,17 @@ from ._unit import Unit +class StudentState(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 @@ -33,6 +45,7 @@ class Student(Serializable): class_: str = StringField(key="ClassDisplay") symbol: str = StringField(key="TopLevelPartition") symbol_code: str = StringField(key="Partition") + state: StudentState = ChildField(StudentState, key="State") pupil: Pupil = ChildField(Pupil, key="Pupil") unit: Unit = ChildField(Unit, key="Unit") @@ -74,9 +87,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] + return [ + Student.load(student) for student in data if student["State"] == state.value + ]