Add PersonTags as well. Performed a simple test but not extensive regression
[plcapi.git] / PLC / PersonTags.py
1 # $Id: PersonTags.py 14587 2009-07-19 13:18:50Z thierry $
2 # $URL: http://svn.planet-lab.org/svn/PLCAPI/tags/PLCAPI-4.3-27/PLC/PersonTags.py $
3 #
4 # Thierry Parmentelat - INRIA
5 #
6 # $Revision: 14587 $
7 #
8 from PLC.Faults import *
9 from PLC.Parameter import Parameter
10 from PLC.Filter import Filter
11 from PLC.Table import Row, Table
12 from PLC.TagTypes import TagType, TagTypes
13 from PLC.Persons import Person
14
15 class PersonTag(Row):
16     """
17     Representation of a row in the person_tag.
18     To use, instantiate with a dict of values.
19     """
20
21     table_name = 'person_tag'
22     primary_key = 'person_tag_id'
23     fields = {
24         'person_tag_id': Parameter(int, "Person setting identifier"),
25         'person_id': Person.fields['person_id'],
26         'email': Person.fields['email'],
27         'tag_type_id': TagType.fields['tag_type_id'],
28         'tagname': TagType.fields['tagname'],
29         'description': TagType.fields['description'],
30         'category': TagType.fields['category'],
31         'min_role_id': TagType.fields['min_role_id'],
32         'value': Parameter(str, "Person setting value"),
33         ### relations
34         
35         }
36
37 class PersonTags(Table):
38     """
39     Representation of row(s) from the person_tag table in the
40     database.
41     """
42
43     def __init__(self, api, person_tag_filter = None, columns = None):
44         Table.__init__(self, api, PersonTag, columns)
45
46         sql = "SELECT %s FROM view_person_tags WHERE True" % \
47               ", ".join(self.columns)
48
49         if person_tag_filter is not None:
50             if isinstance(person_tag_filter, (list, tuple, set)):
51                 person_tag_filter = Filter(PersonTag.fields, {'person_tag_id': person_tag_filter})
52             elif isinstance(person_tag_filter, dict):
53                 person_tag_filter = Filter(PersonTag.fields, person_tag_filter)
54             elif isinstance(person_tag_filter, int):
55                 person_tag_filter = Filter(PersonTag.fields, {'person_tag_id': [person_tag_filter]})
56             else:
57                 raise PLCInvalidArgument, "Wrong person setting filter %r"%person_tag_filter
58             sql += " AND (%s) %s" % person_tag_filter.sql(api)
59
60
61         self.selectall(sql)