25e275871b17c9e4ca7a118ec9a62745c6877b4b
[pygrader.git] / pygrader / model / person.py
1 # Copyright (C) 2012 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of pygrader.
4 #
5 # pygrader is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # pygrader is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # pygrader.  If not, see <http://www.gnu.org/licenses/>.
16
17 class Person (object):
18     def __init__(self, name, emails=None, pgp_key=None, aliases=None,
19                  groups=None):
20         self.name = name
21         self.emails = emails
22         self.pgp_key = pgp_key
23         if not aliases:
24             aliases = [self.name]
25         self.aliases = aliases
26         self.groups = groups
27
28     def __str__(self):
29         return '<{} {}>'.format(type(self).__name__, self.name)
30
31     def __lt__(self, other):
32         return self.name < other.name
33
34     def alias(self):
35         """Return a good alias for direct address
36         """
37         try:
38             return self.aliases[0]
39         except KeyError:
40             return self.name