X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FTable.py;h=2362d61a56e4e9db93e0dd568e1c0357b56157f0;hb=730642259a8851fa626b7dd4c0e1332cd8b1d006;hp=cb0eb6b6008d1bd31450aec8c54a8f480614e905;hpb=d016b01f1145899e697f1f49233710bb464d438c;p=plcapi.git diff --git a/PLC/Table.py b/PLC/Table.py index cb0eb6b..2362d61 100644 --- a/PLC/Table.py +++ b/PLC/Table.py @@ -50,6 +50,35 @@ class Row(dict): if value is not None and hasattr(self, 'validate_' + key): validate = getattr(self, 'validate_' + key) self[key] = validate(value) + + def separate_types(self, items): + """ + Separate a list of different typed objects. + Return a list for each type (ints, strs and dicts) + """ + + if isinstance(items, (list, tuple, set)): + ints = filter(lambda x: isinstance(x, (int, long)), items) + strs = filter(lambda x: isinstance(x, StringTypes), items) + dicts = filter(lambda x: isinstance(x, dict), items) + return (ints, strs, dicts) + else: + raise PLCInvalidArgument, "Can only separate list types" + + + def associate(self, *args): + """ + Provides a means for high lvl api calls to associate objects + using low lvl calls. + """ + + if len(args) < 3: + raise PLCInvalidArgumentCount, "auth, field, value must be specified" + elif hasattr(self, 'associate_' + args[1]): + associate = getattr(self, 'associate_'+args[1]) + associate(*args) + else: + raise PLCInvalidArguemnt, "No such associate function associate_%s" % args[1] def validate_timestamp(self, timestamp, check_future = False): """ @@ -92,7 +121,7 @@ class Row(dict): assert isinstance(obj, classobj) assert isinstance(obj, Row) assert obj.primary_key in obj - assert join_table in obj.join_tables + assert join_table in obj.join_tables # By default, just insert the primary keys of each object # into the join table.