Skip to content

Commit

Permalink
Avoid loading old stunent profiles (#138)
Browse files Browse the repository at this point in the history
* Avoid loading old stunent profiles

* Fix lint

* Undo version change

* Allow fetching inactive students

* Rename State class to StudentState
  • Loading branch information
Antoni-Czaplicki authored Apr 9, 2024
1 parent 7e75c9f commit 3f4efd9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 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 Student, StudentState


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: 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
Expand Down
2 changes: 1 addition & 1 deletion vulcan/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 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 @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
]

0 comments on commit 3f4efd9

Please sign in to comment.