2 # Functions for interacting with the key_types table in the database
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
11 from PLC.Faults import *
12 from PLC.Parameter import Parameter
13 from PLC.Table import Row, Table
17 Representation of a row in the key_types table. To use,
18 instantiate with a dict of values.
21 table_name = 'key_types'
22 primary_key = 'key_type'
23 join_tables = ['keys']
25 'key_type': Parameter(str, "Key type", max = 20),
28 def validate_key_type(self, name):
29 # Make sure name is not blank
31 raise PLCInvalidArgument, "Key type must be specified"
33 # Make sure key type does not alredy exist
34 conflicts = KeyTypes(self.api, [name])
36 raise PLCInvalidArgument, "Key type name already in use"
40 class KeyTypes(Table):
42 Representation of the key_types table in the database.
45 def __init__(self, api, key_types = None):
46 Table.__init__(self, api, KeyType)
48 sql = "SELECT %s FROM key_types" % \
49 ", ".join(KeyType.fields)
52 sql += " WHERE key_type IN (%s)" % ", ".join(map(api.db.quote, key_types))