X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FUpdatePCU.py;h=84c35730eefe2092b36eb70b95a0ec3569f43e29;hb=b5780972105512f088c235b1538e6cbbb1ee1ae4;hp=5a702c81a6085b56f7abd6e7ce9a83778ec31f77;hpb=286cdfc25f6ef8fd3e0ed59a175bcf801b14038a;p=plcapi.git diff --git a/PLC/Methods/UpdatePCU.py b/PLC/Methods/UpdatePCU.py index 5a702c8..84c3573 100644 --- a/PLC/Methods/UpdatePCU.py +++ b/PLC/Methods/UpdatePCU.py @@ -1,11 +1,10 @@ -# $Id# from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.PCUs import PCU, PCUs from PLC.Auth import Auth -can_update = lambda (field, value): field not in \ +can_update = lambda field_value: field_value[0] not in \ ['pcu_id', 'site_id'] class UpdatePCU(Method): @@ -20,7 +19,7 @@ class UpdatePCU(Method): roles = ['admin', 'pi', 'tech'] - update_fields = dict(filter(can_update, PCU.fields.items())) + update_fields = dict(list(filter(can_update, list(PCU.fields.items())))) accepts = [ Auth(), @@ -31,23 +30,24 @@ class UpdatePCU(Method): returns = Parameter(int, '1 if successful') def call(self, auth, pcu_id, pcu_fields): - pcu_fields = dict(filter(can_update, pcu_fields.items())) + pcu_fields = dict(list(filter(can_update, list(pcu_fields.items())))) # Get associated PCU details pcus = PCUs(self.api, [pcu_id]) if not pcus: - raise PLCInvalidArgument, "No such PCU" + raise PLCInvalidArgument("No such PCU") pcu = pcus[0] if 'admin' not in self.caller['roles']: if pcu['site_id'] not in self.caller['site_ids']: - raise PLCPermissionDenied, "Not allowed to update that PCU" + raise PLCPermissionDenied("Not allowed to update that PCU") pcu.update(pcu_fields) + pcu.update_last_updated(commit=False) pcu.sync() - - # Logging variables - self.event_objects = {'PCU': [pcu['pcu_id']]} - self.message = 'PCU %d updated: %s' % \ - (pcu['pcu_id'], ", ".join(pcu_fields.keys())) + + # Logging variables + self.event_objects = {'PCU': [pcu['pcu_id']]} + self.message = 'PCU %d updated: %s' % \ + (pcu['pcu_id'], ", ".join(list(pcu_fields.keys()))) return 1