Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

""" 

---------------------------------------------------------------------- 

Authors: Jan-Justin van Tonder 

---------------------------------------------------------------------- 

This file contains the logic used to manage the various ID contexts. 

Should ideally be extended to do more than it currently does. 

---------------------------------------------------------------------- 

""" 

 

from id_contexts.sa_id_card import SAIDCard 

from id_contexts.sa_id_book import SAIDBook 

from id_contexts.sa_id_book_old import SAIDBookOld 

from id_contexts.up_student_card import UPStudentCard 

 

 

class ContextManager: 

""" 

A class responsible for managing and maintaining the various ID contexts. 

 

Attributes: 

_sa_id_card (IDContext): A South African ID card context. 

_sa_id_book (IDContext): A South African ID book context. 

_sa_id_book_old (IDContext): An old South African ID book context. 

_up_card (IDContext): A University of Pretoria staff/student card context. 

""" 

def __init__(self): 

""" 

Responsible for initialising the ContextManager object. 

""" 

# Create ID contexts to manage and maintain. 

self._sa_id_card = SAIDCard() 

self._sa_id_book = SAIDBook() 

self._sa_id_book_old = SAIDBookOld() 

self._up_card = UPStudentCard() 

 

def get_id_context(self, id_type): 

""" 

Returns an ID context based on the ID type that is passed in as an arg. 

 

Authors: 

Jan-Justin van Tonder 

 

Args: 

id_type (str): A string indicating a type of ID. 

 

Returns: 

(IDContext): An IDContext object determined by the ID type passed in as an arg. 

(None): In the event that the ID type is unrecognisable. 

""" 

# Determine which ID context to return, otherwise return None. 

if id_type == 'idcard': 

return self._sa_id_card 

elif id_type == 'idbook': 

return self._sa_id_book 

elif id_type == 'idbookold': 

return self._sa_id_book_old 

elif id_type == 'studentcard': 

return self._up_card 

return None