def create_user(org_user_name, org, is_org_user=False, is_org_admin=False, password='******'): """ Crete Users and maps them to the org if needed. org_user_name - string if is_org_user = True, the user will be mapped to the org if is_org_admin = True, the user will be made an org admin org - Org object """ org_user = OcUser().setup_user(username=org_user_name, email=org_user_name + '@email.cc', first_name=org_user_name + '_first_name', last_name=org_user_name + '_last_name') if is_org_user: # mapping user to org oui = OrgUserInfo(org_user.id) oui.setup_orguser(org) # making a user an org admin if is_org_admin: oui.make_org_admin(org.id) org_user.set_password(password) org_user.save()
def setup_users(): users_all = [] for fxt in fixtures_user: try: user = OcUser().setup_user(fxt['email'], fxt['email'], fxt['firstname'], fxt['lastname']) print 'Created user %s' % user.username except UserExistsException: user = User.objects.get(email=fxt['email']) print 'User %s already exists' % fxt['email'] user.set_password('oc') user.save() users_all.append(user) if fxt['type'] != 'volunteer': org = None orgname = fxt['lastname'].strip('Admin') try: org = Org.objects.get(name=orgname) except Exception as e: print 'No org named %s (%s)' % (orgname, org.name) return oui = OrgUserInfo(user.id) try: oui.setup_orguser(org) except InvalidOrgUserException: print 'Unable to configure %s <=> %s mapping (possible it already exists)' % ( org.name, fxt['email']) try: oui.make_org_admin(org.id) except InvalidOrgException: print 'Unable to grant admin privilege to %s on org %s (check for exitence of admin group)' % ( user.username, org.name) except ExistingAdminException: print '%s already granted admin privilege on org %s' % ( user.username, org.name) return users_all
def _create_test_user( user_name, password='******', org=None, is_org_admin=False ): """ Create users and maps them to the org if needed. Takes: user_name - string org - Org object. A NPF admin will be created, if Org is provided and is_org_admin = True. An org user will be created if org is provided and is_org_admin = False. If no org provided - a volunteer will be created. is_org_admin - if True, the user will be made an org admin, if org is provided. """ test_user = OcUser().setup_user( username=user_name, email=user_name + '@email.cc', first_name=user_name + '_first_name', last_name=user_name + '_last_name' ) if org: # mapping user to org oui = OrgUserInfo(test_user.id) oui.setup_orguser(org) # making a user an org admin if is_org_admin: oui.make_org_admin(org.id) test_user.set_password(password) test_user.save() return test_user