Initial checkin of new API implementation
[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$
8 #
9
10 from PLC.Parameter import Parameter
11
12 class Roles(dict):
13     """
14     Representation of the roles table in the database.
15     """
16
17     fields = {
18         'role_id': Parameter(int, "Role identifier"),
19         'name': Parameter(str, "Role name"),
20         }
21
22     # Role IDs equal to or lower than this number are for use by real
23     # accounts. Other role IDs are used internally.
24     role_max = 500
25
26     def __init__(self, api):
27         sql = "SELECT * FROM roles" \
28               " WHERE role_id <= %d" % self.role_max
29
30         for row in api.db.selectall(sql):
31             self[row['role_id']] = row['name']
32             self[row['name']] = row['role_id']