2 # Thierry Parmentelat - INRIA
4 from PLC.Faults import *
5 from PLC.Parameter import Parameter
6 from PLC.Storage.AlchemyObject import AlchemyObj
7 from PLC.TagTypes import TagType, TagTypes
8 from PLC.Persons import Person
10 class PersonTag(AlchemyObj):
12 Representation of a row in the person_tag.
13 To use, instantiate with a dict of values.
16 tablename = 'person_tag'
18 'person_tag_id': Parameter(int, "Person setting identifier", primary_key=True),
19 'person_id': Person.fields['person_id'],
20 'email': Person.fields['email'],
21 'tag_type_id': TagType.fields['tag_type_id'],
22 'tagname': TagType.fields['tagname'],
23 'description': TagType.fields['description'],
24 'category': TagType.fields['category'],
25 'value': Parameter(str, "Person setting value"),
30 def sync(self, commit=True, validate=True):
31 AlchemyObj.sync(self, commit=Ture, validate=True)
32 if 'person_tag_id' not in self:
33 AlchemyObj.insert(self, dict(self))
35 AlchemyObj.update(self, {'person_tag_id': self['person_tag_id']}, dict(self))
38 def delete(self, commit=True):
39 assert 'person_tag_id' in self
40 AlchemyObj.delete(self, dict(self))
42 class PersonTags(list):
44 Representation of row(s) from the person_tag table in the
48 def __init__(self, api, person_tag_filter = None, columns = None):
49 if not person_tag_filter:
50 person_tags = PersonTag().select()
51 elif isinstance(person_tag_filter, (list, tuple, set, int, long)):
52 person_tags = PersonTag().select(filter={'person_tag_id': person_tag_filter})
53 elif isinstance(person_tag_filter, dict):
54 person_tags = PersonTag().select(filter=person_tag_filter)
56 raise PLCInvalidArgument, "Wrong person setting filter %r"%person_tag_filter
58 self.extend(person_tags)