Coverage for .tox/coverage/lib/python3.11/site-packages/wuttjamaican/people.py: 100%
18 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-15 11:33 -0500
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-15 11:33 -0500
1# -*- coding: utf-8; -*-
2################################################################################
3#
4# WuttJamaican -- Base package for Wutta Framework
5# Copyright © 2023-2024 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
26This is a :term:`handler` to manage "people" in the DB.
27"""
29from wuttjamaican.app import GenericHandler
32class PeopleHandler(GenericHandler):
33 """
34 Base class and default implementation for the "people"
35 :term:`handler`.
37 This is responsible for managing
38 :class:`~wuttjamaican.db.model.base.Person` records, and related
39 things.
40 """
42 def make_person(self, **kwargs):
43 """
44 Make and return a new Person.
46 This mostly a convenience wrapper; it will auto-populate the
47 :attr:`~wuttjamaican.db.model.base.Person.full_name` if not
48 specified.
50 :param \**kwargs: All kwargs are passed as-is to the model
51 class constructor.
53 :rtype: :class:`~wuttjamaican.db.model.base.Person`
54 """
55 model = self.app.model
57 if 'full_name' not in kwargs:
58 full_name = self.app.make_full_name(kwargs.get('first_name'),
59 kwargs.get('middle_name'),
60 kwargs.get('last_name'))
61 if full_name:
62 kwargs['full_name'] = full_name
64 return model.Person(**kwargs)
66 def get_person(self, obj, **kwargs):
67 """
68 Return the :class:`~wuttjamaican.db.model.base.Person`
69 associated with the given object, if one can be found.
71 This method should accept "any" type of ``obj`` and inspect it
72 to determine if/how a person can be found. It should return
73 the "first, most obvious" person in the event that the object
74 is associated with multiple people.
76 This is a rather fundamental method, in that it is called by
77 several other methods, both within this handler as well as
78 others. There is also a shortcut to it, accessible via
79 :meth:`wuttjamaican.app.AppHandler.get_person()`.
80 """
81 model = self.app.model
83 if isinstance(obj, model.Person):
84 person = obj
85 return person
87 elif isinstance(obj, model.User):
88 user = obj
89 if user.person:
90 return user.person