You are here
Code Example: Adding A User To A Team
You have a user who's login is "fred" and you wish to add them to the team name "User Support".
>>> from coils.core import initialize_COILS, AdministrativeContext
>>> initialize_COILS()
>>> ctx = AdministrativeContext()
>>> a = ctx.r_c('account::get', login='cleslie')
>>> a
<Contact objectId="9144860" version="617" displayName="Smith, Fred", login="fred" UID="9144860@27fd7d5-0c5e-4074-b2f0-7470a8sssdc9-815912229"/>
>>> t = ctx.r_c('team::get', name='User Support')
>>> t
<Team objectId=9154000 version=14 name="User Support">
>>> ctx.r_c('account::join-team', account=a, team=t)
account::join-team 0.00363612174988s
True
>>> ctx.commit()
>>> ctx.r_c('team::get-logins', team=t)
team::get-logins 0.0082790851593s
[u'george', u'fred', u'stanley']
The "r_c" method of the Context object is an abbreviated call to the "run_command" method.