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"""Factory to make derived Table classes.""" 

2 

3from config import Names as N 

4from control.utils import factory as baseFactory 

5 

6from control.table import Table 

7from control.cust.contrib_table import ContribT 

8from control.cust.assessment_table import AssessmentT 

9from control.cust.review_table import ReviewT 

10 

11 

12DERIVEDS = ( 

13 (N.contrib, ContribT), 

14 (N.assessment, AssessmentT), 

15 (N.review, ReviewT), 

16) 

17"""Search space for classes derived from `control.table.Table`.""" 

18 

19 

20def factory(name): 

21 """Look up a derived class by registered name. 

22 

23 See `DERIVEDS`. 

24 

25 Parameters 

26 ---------- 

27 name: string 

28 The name under which the derived class is registered. 

29 

30 Returns 

31 ------- 

32 class 

33 The derived class if it can be found, otherwise the base class. 

34 """ 

35 

36 return baseFactory(name, Table, DERIVEDS) 

37 

38 

39def make(context, name): 

40 """Create an object in a registered table class. 

41 

42 This function will be stored in that object, so that the new table object 

43 is able to create new table objects in its class. 

44 

45 !!! hint 

46 This is needed when the user wants to insert new records in the table. 

47 

48 Parameters 

49 ---------- 

50 context: object 

51 The context singleton in which this very function will be stored 

52 under attribute `mkTable`. 

53 name: string 

54 The registered name of the derived table class. 

55 """ 

56 tableObj = factory(name)(context, name) 

57 tableObj.mkTable = make 

58 return tableObj