git://git.onelab.eu
/
plcapi.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
- change variable name
[plcapi.git]
/
PLC
/
Methods
/
AddPerson.py
diff --git
a/PLC/Methods/AddPerson.py
b/PLC/Methods/AddPerson.py
index
fb4b887
..
511040f
100644
(file)
--- a/
PLC/Methods/AddPerson.py
+++ b/
PLC/Methods/AddPerson.py
@@
-2,42
+2,43
@@
from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Persons import Person, Persons
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field in \
+ ['first_name', 'last_name', 'title',
+ 'email', 'password', 'phone', 'url', 'bio']
class AddPerson(Method):
"""
class AddPerson(Method):
"""
- Adds a new account. Any fields specified in
optional_val
s are
+ Adds a new account. Any fields specified in
person_field
s are
used, otherwise defaults are used.
Accounts are disabled by default. To enable an account, use
used, otherwise defaults are used.
Accounts are disabled by default. To enable an account, use
-
SetPersonEnabled() or
UpdatePerson().
+ UpdatePerson().
Returns the new person_id (> 0) if successful, faults otherwise.
"""
roles = ['admin', 'pi']
Returns the new person_id (> 0) if successful, faults otherwise.
"""
roles = ['admin', 'pi']
- can_update = lambda (field, value): field in \
- ['title', 'email', 'password', 'phone', 'url', 'bio']
- update_fields = dict(filter(can_update, Person.fields.items()))
+ person_fields = dict(filter(can_update, Person.fields.items()))
accepts = [
accepts = [
- PasswordAuth(),
- Person.fields['first_name'],
- Person.fields['last_name'],
- update_fields
+ Auth(),
+ person_fields
]
returns = Parameter(int, 'New person_id (> 0) if successful')
]
returns = Parameter(int, 'New person_id (> 0) if successful')
- def call(self, auth, first_name, last_name, optional_vals = {}):
- if filter(lambda field: field not in self.update_fields, optional_vals):
- raise PLCInvalidArgument, "Invalid fields specified"
- person = Person(self.api, optional_vals)
- person
['first_name'] = first_name
- person
['last_name'] = last_nam
e
- person
['enabled'] = False
+ def call(self, auth, person_fields):
+ person
_fields = dict(filter(can_update, person_fields.items()))
+ person
_fields['enabled'] = Fals
e
+ person
= Person(self.api, person_fields)
person.sync()
person.sync()
+ # Logging variables
+ self.object_ids = [person['person_id']]
+ self.message = 'Person %d added' % person['person_id']
+
return person['person_id']
return person['person_id']