Coverage for .tox/coverage/lib/python3.11/site-packages/wuttjamaican/people.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-19 13:14 -0500

1# -*- coding: utf-8; -*- 

2################################################################################ 

3# 

4# WuttJamaican -- Base package for Wutta Framework 

5# Copyright © 2023-2025 Lance Edgar 

6# 

7# This file is part of Wutta Framework. 

8# 

9# Wutta Framework is free software: you can redistribute it and/or modify it 

10# under the terms of the GNU General Public License as published by the Free 

11# Software Foundation, either version 3 of the License, or (at your option) any 

12# later version. 

13# 

14# Wutta Framework is distributed in the hope that it will be useful, but 

15# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 

16# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 

17# more details. 

18# 

19# You should have received a copy of the GNU General Public License along with 

20# Wutta Framework. If not, see <http://www.gnu.org/licenses/>. 

21# 

22################################################################################ 

23""" 

24People Handler 

25 

26This is a :term:`handler` to manage "people" in the DB. 

27""" 

28 

29from wuttjamaican.app import GenericHandler 

30 

31 

32class PeopleHandler(GenericHandler): 

33 """ 

34 Base class and default implementation for the "people" 

35 :term:`handler`. 

36 

37 This is responsible for managing 

38 :class:`~wuttjamaican.db.model.base.Person` records, and related 

39 things. 

40 """ 

41 

42 def make_person(self, **kwargs): 

43 """ 

44 Make and return a new Person. 

45 

46 This mostly a convenience wrapper; it will auto-populate the 

47 :attr:`~wuttjamaican.db.model.base.Person.full_name` if not 

48 specified. 

49 

50 :param \\**kwargs: All kwargs are passed as-is to the model 

51 class constructor. 

52 

53 :rtype: :class:`~wuttjamaican.db.model.base.Person` 

54 """ 

55 model = self.app.model 

56 

57 if "full_name" not in kwargs: 

58 full_name = self.app.make_full_name( 

59 kwargs.get("first_name"), 

60 kwargs.get("middle_name"), 

61 kwargs.get("last_name"), 

62 ) 

63 if full_name: 

64 kwargs["full_name"] = full_name 

65 

66 return model.Person(**kwargs) 

67 

68 def get_person(self, obj): 

69 """ 

70 Return the :class:`~wuttjamaican.db.model.base.Person` 

71 associated with the given object, if one can be found. 

72 

73 This method should accept "any" type of ``obj`` and inspect it 

74 to determine if/how a person can be found. It should return 

75 the "first, most obvious" person in the event that the object 

76 is associated with multiple people. 

77 

78 This is a rather fundamental method, in that it is called by 

79 several other methods, both within this handler as well as 

80 others. There is also a shortcut to it, accessible via 

81 :meth:`wuttjamaican.app.AppHandler.get_person()`. 

82 """ 

83 model = self.app.model 

84 

85 if isinstance(obj, model.Person): 

86 person = obj 

87 return person 

88 

89 if isinstance(obj, model.User): 

90 user = obj 

91 if user.person: 

92 return user.person 

93 

94 return None