Coverage for .tox/coverage/lib/python3.11/site-packages/wuttjamaican/people.py: 100%
12 statements
« prev ^ index » next coverage.py v7.3.2, created at 2024-07-14 23:25 -0500
« prev ^ index » next coverage.py v7.3.2, created at 2024-07-14 23:25 -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 get_person(self, obj, **kwargs):
43 """
44 Return the :class:`~wuttjamaican.db.model.base.Person`
45 associated with the given object, if one can be found.
47 This method should accept "any" type of ``obj`` and inspect it
48 to determine if/how a person can be found. It should return
49 the "first, most obvious" person in the event that the object
50 is associated with multiple people.
52 This is a rather fundamental method, in that it is called by
53 several other methods, both within this handler as well as
54 others. There is also a shortcut to it, accessible via
55 :meth:`wuttjamaican.app.AppHandler.get_person()`.
56 """
57 model = self.app.model
59 if isinstance(obj, model.Person):
60 person = obj
61 return person
63 elif isinstance(obj, model.User):
64 user = obj
65 if user.person:
66 return user.person