def create_projects(number_of_projects, out_handle=None): """Creating some number of random projects The projects will start in various states with different user associations. Args: number_of_projects: The number of projects to be created. out_handle: The output handler for printing. """ # This extra work for user ids is necessary due to the fact that the # database might have been wiped, but the origin pk for the user still # has been claimed, so we must gather the current pk list to apply them # to create issues. try: user_ids = [] for user in User.objects.all(): user_ids.append(user.pk) user_count = len(user_ids) - 1 project_count = len(PROJECTS) - 1 if out_handle: out_handle.write('\nCreating projects') for i in xrange(number_of_projects): if out_handle: out_handle.write('.', ending='') out_handle.flush() fields = { 'title': '%s: %d' % (PROJECTS[random.randint(0, project_count)][0], i), 'description': PROJECTS[random.randint(0, project_count)][1] } excluded_users = [_get_random_user(user_ids)] p = project_api.create_project(user=excluded_users[0], fields=fields) # Now associate some number of developers to the project. for _ in xrange(random.randint(1, user_count)): # Remove the users already associated with the project ids = set(user_ids) - set([user.pk for user in excluded_users]) u = _get_random_user(list(ids)) excluded_users.append(u) project_api.add_user_to_project( p.id, u.username, user_association_model.ROLE_DEVELOPER) if out_handle: out_handle.write('\n') except Exception as e: print e
def create_projects(number_of_projects, out_handle=None): """Creating some number of random projects The projects will start in various states with different user associations. Args: number_of_projects: The number of projects to be created. out_handle: The output handler for printing. """ # This extra work for user ids is necessary due to the fact that the # database might have been wiped, but the origin pk for the user still # has been claimed, so we must gather the current pk list to apply them # to create issues. user_ids = [] for user in User.objects.all(): user_ids.append(user.pk) project_count = len(PROJECTS) - 1 if out_handle: out_handle.write('\nCreating projects') for i in xrange(number_of_projects): if out_handle: out_handle.write('.', ending='') out_handle.flush() fields = {'title': '%s: %d' % ( PROJECTS[random.randint(0, project_count)][0], i), 'description': PROJECTS[random.randint(0, project_count)][1]} excluded_users = [_get_random_user(user_ids)] p = project_api.create_project(user=excluded_users[0], fields=fields) # Now associate some number of developers to the project. for _ in xrange(random.randint(1, 5)): # Remove the users already associated with the project ids = set(user_ids) - set([user.pk for user in excluded_users]) u = _get_random_user(list(ids)) excluded_users.append(u) project_api.add_user_to_project( p.id, u.username, user_association_model.ROLE_DEVELOPER) if out_handle: out_handle.write('\n')
def add_user_to_project(request, projectID, username): project = project_api.get_project(projectID) if request.method == 'POST': form = SelectAccessLevelForm(request.POST) if form.is_valid(): user_role = (request.POST).get('user_role', '') project_api.add_user_to_project(projectID, username, user_role) else: form = SelectAccessLevelForm() users = user_manager.getActiveUsers() for puser in project.users.all(): users = users.exclude(username=puser.username) context = { 'title': 'Add User to Project', 'form': form, 'project': project, 'users': users, } return render(request, 'UserSummary.html', context)