Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid loading old stunent profiles #138

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions vulcan/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ async def _request(
full_url = (
url
if url.startswith("http")
else self._rest_url + url
if self._rest_url
else None
else self._rest_url + url if self._rest_url else None
)

if not full_url:
Expand Down
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
kapi2289 marked this conversation as resolved.
Show resolved Hide resolved
) -> 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 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 @@ -11,6 +12,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 @@ -31,6 +43,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 @@ -71,9 +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]
return [
Student.load(student) for student in data if student["State"] == state.value
]
Loading