# # Thierry Parmentelat - INRIA # from PLC.Faults import * from PLC.Parameter import Parameter from PLC.Storage.AlchemyObject import AlchemyObj from PLC.TagTypes import TagType, TagTypes from PLC.Persons import Person class PersonTag(AlchemyObj): """ Representation of a row in the person_tag. To use, instantiate with a dict of values. """ tablename = 'person_tag' fields = { 'person_tag_id': Parameter(int, "Person setting identifier", primary_key=True), 'person_id': Person.fields['person_id'], 'email': Person.fields['email'], 'tag_type_id': TagType.fields['tag_type_id'], 'tagname': TagType.fields['tagname'], 'description': TagType.fields['description'], 'category': TagType.fields['category'], 'value': Parameter(str, "Person setting value"), ### relations } def sync(self, commit=True, validate=True): AlchemyObj.sync(self, commit=Ture, validate=True) if 'person_tag_id' not in self: AlchemyObj.insert(self, dict(self)) else: AlchemyObj.update(self, {'person_tag_id': self['person_tag_id']}, dict(self)) def delete(self, commit=True): assert 'person_tag_id' in self AlchemyObj.delete(self, dict(self)) class PersonTags(list): """ Representation of row(s) from the person_tag table in the database. """ def __init__(self, api, person_tag_filter = None, columns = None): if not person_tag_filter: person_tags = PersonTag().select() elif isinstance(person_tag_filter, (list, tuple, set, int, long)): person_tags = PersonTag().select(filter={'person_tag_id': person_tag_filter}) elif isinstance(person_tag_filter, dict): person_tags = PersonTag().select(filter=person_tag_filter) else: raise PLCInvalidArgument, "Wrong person setting filter %r"%person_tag_filter self.extend(person_tags)