From: Tony Mack Date: Tue, 11 Dec 2012 00:12:27 +0000 (-0500) Subject: initial checkin X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=commitdiff_plain;h=9e3d21d7a4a1a129c25081904c2d32dbdf48a686 initial checkin --- diff --git a/PLC/SitePersons.py b/PLC/SitePersons.py new file mode 100644 index 0000000..aba207e --- /dev/null +++ b/PLC/SitePersons.py @@ -0,0 +1,59 @@ +from types import StringTypes +import time +import re +import datetime + +from PLC.Faults import * +from PLC.Parameter import Parameter, Mixed +from PLC.Debug import profile +from PLC.Timestamp import Timestamp +from PLC.Storage.AlchemyObject import AlchemyObj + +class SitePerson(AlchemyObj): + """ + Representation of a row in the site_person table. To use, optionally + instantiate with a dict of values. Update as you would a + dict. Commit to the database with sync().To use, instantiate + with a dict of values. + """ + + tablename = 'site_person' + + fields = { + 'site_id': Parameter(int, "Slice identifier", primary_key=True), + 'person_id': Parameter(int, "Person identifier", indexed=True), + } + tags = {} + + def sync(self, commit = True, validate=True): + """ + Add the record + """ + AlchemyObj.sync(self, commit, validate) + AlchemyObj.insert(self, dict(self)) + + def delete(self, commit = True): + """ + Delete existing slice. + """ + AlchemyObj.delete(self, dict(self)) + + +class SitePersons(list): + """ + Representation of row(s) from the slices table in the + database. + """ + + def __init__(self, api, filter = None, columns = None): + + # the view that we're selecting upon: start with view_slices + if not filter: + site_persons = SitePerson().select() + elif isinstance(filter, dict): + site_persons = SitePerson().select(filter=filter) + else: + raise PLCInvalidArgument, "Wrong site_person filter %r"%filter + + for site_person in site_persons: + self.append(site_person)