FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bug fix: absences · robquant/python-webuntis@8943492 · GitHub

Repository navigation

Commit 8943492

Browse files
committed
bug fix: absences
1 parent e1691cc commit 8943492

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

‎tests/test_objects.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class StubSession(object):
351351
session=sess
352352
)
353353
student1 = webuntis.objects.StudentObject(
354-
data={u'id': 9, u'name': u'Potter', u'longName': u'Potter', u'foreName': 'Harry', u'key': 42},
354+
data={u'id': 9, u'name': u'Potter', u'longName': u'Potter', u'foreName': 'Harry', u'key': '42'},
355355
session=sess
356356
)
357357

@@ -609,7 +609,7 @@ def testExamObject(self):
609609
assert ex.klassen[0].name == u'1A'
610610
assert len(ex.students) == 1
611611
assert ex.students[0].name == u'Potter'
612-
assert ex.students[0].key == 42
612+
assert ex.students[0].key == '42'
613613

614614
def testExamList(selfself):
615615
exl = webuntis.objects.ExamsList(
@@ -626,10 +626,10 @@ class AbsencesTests(WebUntisTestCase):
626626
def testAbsence(self):
627627
ab = webuntis.objects.AbsenceObject(
628628
data={'date': 20180320, 'startTime': 850, 'endTime': 940,
629-
'studentId': '9',
629+
'studentId': '42', # <- key!
630630
'subjectId': '4',
631631
'teacherIds': ['3', '7'],
632-
'student_group': u'MAM_1A_M',
632+
'studentGroup': u'MAM_1A_M',
633633
'user': '',
634634
'checked': True},
635635
session=StubSession()

‎webuntis/objects.py‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,19 @@ class ExamsList(ListResult):
834834

835835

836836
class AbsenceObject(Result):
837-
"""Represents an absence."""
837+
"""Represents an absence.
838+
839+
Attention: if there are multiple teachers/groups at the same time -> multiple entries for the
840+
same student, but the absentTime is only set for one (the first?) entry.
841+
"""
838842

839843
@lazyproperty
840844
def student(self):
841-
return self._session.students(from_cache=True).filter(id=int(self._data[u'studentId']))[0]
845+
"""
846+
doku says: student ID, but it is the students KEY
847+
:return:
848+
"""
849+
return self._session.students(from_cache=True).filter(key=self._data[u'studentId'])[0]
842850

843851
@lazyproperty
844852
def subject(self):
@@ -861,7 +869,10 @@ def teachers(self):
861869

862870
@lazyproperty
863871
def student_group(self):
864-
return self._data[u'student_group']
872+
try:
873+
return self._data[u'studentGroup']
874+
except KeyError:
875+
return ''
865876

866877
@lazyproperty
867878
def checked(self):
@@ -890,6 +901,20 @@ def end(self):
890901
self._data[u'endTime']
891902
)
892903

904+
@lazyproperty
905+
def reason(self):
906+
try:
907+
return self._data[u'absenceReason']
908+
except KeyError:
909+
return ''
910+
911+
@lazyproperty
912+
def time(self):
913+
try:
914+
return int(self._data[u'absentTime'])
915+
except KeyError:
916+
return 0
917+
893918

894919
class AbsencesList(ListResult):
895920
"""A list of absences."""

‎webuntis/objects.pyi‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class PeriodList(ListResult):
196196
def combine(self) -> PeriodList:
197197
...
198198

199+
199200
class PersonObject(ListItem):
200201

201202
@property
@@ -352,6 +353,7 @@ class SubstitutionList(ListResult):
352353
def combine(self) -> SubstitutionList:
353354
...
354355

356+
355357
class TeacherObject(PersonObject):
356358
@property
357359
def title(self) -> str:
@@ -468,6 +470,7 @@ class ExamObject(Result):
468470
def students(self) -> StudentsList:
469471
...
470472

473+
471474
class ExamsList(ListResult):
472475
_itemclass = ExamObject
473476

@@ -507,6 +510,14 @@ class AbsenceObject(Result):
507510
def checked(self) -> bool:
508511
...
509512

513+
@property
514+
def reason(self) -> str:
515+
...
516+
517+
@property
518+
def time(self) -> int:
519+
...
520+
510521

511522
class AbsencesList(ListResult):
512523
_itemclass = AbsenceObject

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL