def db_add_user(**kwargs):
 groups_post = kwargs.pop('groups')
 admin_groups = kwargs.pop('admin_groups')
 role = kwargs.get('role', 'CU')
 user = User(**kwargs)
 user.set_password(kwargs.get('password'))
 user.save()
 if groups_post:
  group_select = []
  for group_id in groups_post:
   group = UserGroup.objects.filter(id=group_id)
   group_select.extend(group)
  user.group = group_select
 if (admin_groups and (role == 'GA')):
  for group_id in admin_groups:
   group = get_object(UserGroup, id=group_id)
   if group:
    AdminGroup(user=user, group=group).save()
 return user

def db_add_user ( ** kwargs ) : groups_post = kwargs . pop ( 'groups' ) admin_groups = kwargs . pop ( 'admin_groups' ) role = kwargs . get ( 'role' , 'CU' ) user = User ( ** kwargs ) user . set_password ( kwargs . get ( 'password' ) ) user . save ( ) if groups_post : group_select = [ ] for group_id in groups_post : group = UserGroup . objects . filter ( id = group_id ) group_select . extend ( group ) user . group = group_select if ( admin_groups and ( role == 'GA' ) ) : for group_id in admin_groups : group = get_object ( UserGroup , id = group_id ) if group : AdminGroup ( user = user , group = group ) . save ( ) return user
add a user in database .