From c93210c838b4bc7ef6c489a23b43aa71ac0e62ad Mon Sep 17 00:00:00 2001 From: Antoni-Czaplicki <56671347+Antoni-Czaplicki@users.noreply.github.com> Date: Thu, 14 Mar 2024 15:41:24 +0100 Subject: [PATCH] Allow fetching inactive students --- vulcan/_client.py | 9 ++++++--- vulcan/model/__init__.py | 2 +- vulcan/model/_student.py | 19 ++++++++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/vulcan/_client.py b/vulcan/_client.py index cffbdf9..7ebaa97 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 State, Student 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: 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 diff --git a/vulcan/model/__init__.py b/vulcan/model/__init__.py index 8120ff8..fe0a3a0 100644 --- a/vulcan/model/__init__.py +++ b/vulcan/model/__init__.py @@ -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 diff --git a/vulcan/model/_student.py b/vulcan/model/_student.py index 01cf10d..f253fe1 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 @@ -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 @@ -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") @@ -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 + ]