c035fe6b0b6dcc2d66d6986022a08bc36eb03540
[plcapi.git] / PLC / Roles.py
1 #
2 # Functions for interacting with the roles table in the database
3 #
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
6 #
7 # $Id: Roles.py,v 1.1 2006/09/06 15:36:07 mlhuang Exp $
8 #
9
10 class Roles(dict):
11     """
12     Representation of the roles table in the database.
13     """
14
15     # Role IDs equal to or lower than this number are for use by real
16     # accounts. Other role IDs are used internally.
17     role_max = 500
18
19     def __init__(self, api):
20         sql = "SELECT * FROM roles" \
21               " WHERE role_id <= %d" % self.role_max
22
23         for row in api.db.selectall(sql):
24             self[row['role_id']] = row['name']
25             self[row['name']] = row['role_id']