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
8 from PLC.Faults import *
9 from PLC.Parameter import Parameter
10 from PLC.Table import Row, Table
14 Representation of a row in the key_types table. To use,
15 instantiate with a dict of values.
18 table_name = 'key_types'
19 primary_key = 'key_type'
20 join_tables = ['keys']
22 'key_type': Parameter(str, "Key type", max = 20),
25 def validate_key_type(self, name):
26 # Make sure name is not blank
28 raise PLCInvalidArgument("Key type must be specified")
30 # Make sure key type does not alredy exist
31 conflicts = KeyTypes(self.api, [name])
33 raise PLCInvalidArgument("Key type name already in use")
37 class KeyTypes(Table):
39 Representation of the key_types table in the database.
42 def __init__(self, api, key_types = None):
43 Table.__init__(self, api, KeyType)
45 sql = "SELECT %s FROM key_types" % \
46 ", ".join(KeyType.fields)
49 sql += " WHERE key_type IN (%s)" % ", ".join( [ api.db.quote (t) for t in key_types ] )