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