added create_network(), delete_network(), create_subnet(), delete_subnet(), process_t...
[plcapi.git] / PLC / SlicePersons.py
1 from types import StringTypes
2 import time
3 import re
4 import datetime
5
6 from PLC.Faults import *
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.Filter import Filter
9 from PLC.Debug import profile
10 from PLC.Timestamp import Timestamp
11 from PLC.Storage.AlchemyObject import AlchemyObj
12
13 class SlicePerson(AlchemyObj):
14     """
15     Representation of a row in the slice_person table. To use, optionally
16     instantiate with a dict of values. Update as you would a
17     dict. Commit to the database with sync().To use, instantiate
18     with a dict of values.
19     """
20
21     tablename = 'slice_person'
22  
23     fields = {
24         'slice_id': Parameter(int, "Slice identifier", primary_key=True),
25         'person_id': Parameter(int, "Person identifier", indexed=True),
26         }
27     tags = {}
28
29     def sync(self, commit = True, validate=True):
30         """
31         Add the record
32         """
33         AlchemyObj.sync(self, commit, validate)
34         AlchemyObj.insert(self, dict(self))
35
36     def delete(self, commit = True):
37         """
38         Delete existing slice.
39         """
40         AlchemyObj.delete(self, dict(self))
41
42
43 class SlicePersons(list):
44     """
45     Representation of row(s) from the slices table in the
46     database.
47     """
48
49     def __init__(self, api, filter = None, columns = None):
50          
51         # the view that we're selecting upon: start with view_slices
52         if not filter:
53             slice_persons = SlicePerson().select()
54         elif isinstance(filter, dict):
55             slice_persons = SlicePerson().select(filter=filter)
56         else:
57             raise PLCInvalidArgument, "Wrong slice_person filter %r"%filter
58
59         for slice_person in slice_persons:
60             self.append(slice_person)