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

19 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-10-07 21:12 -0500

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

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

3# 

4# WuttJamaican -- Base package for Wutta Framework 

5# Copyright © 2023-2026 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""" 

26 

27from wuttjamaican.app import GenericHandler 

28 

29 

30class PeopleHandler(GenericHandler): 

31 """ 

32 Base class and default implementation for the :term:`people 

33 handler`. 

34 """ 

35 

36 def make_person(self, **kwargs): 

37 """ 

38 Make and return a new Person. 

39 

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

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

42 specified. 

43 

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

45 class constructor. 

46 

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

48 """ 

49 model = self.app.model 

50 

51 if "full_name" not in kwargs: 

52 full_name = self.app.make_full_name( 

53 kwargs.get("first_name"), 

54 kwargs.get("middle_name"), 

55 kwargs.get("last_name"), 

56 ) 

57 if full_name: 

58 kwargs["full_name"] = full_name 

59 

60 return model.Person(**kwargs) 

61 

62 def get_person(self, obj): 

63 """ 

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

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

66 

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

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

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

70 is associated with multiple people. 

71 

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

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

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

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

76 """ 

77 model = self.app.model 

78 

79 if isinstance(obj, model.Person): 

80 person = obj 

81 return person 

82 

83 if isinstance(obj, model.User): 

84 user = obj 

85 if user.person: 

86 return user.person 

87 

88 return None