Esempio n. 1
0
def new_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        name = str(request.POST['title'])
        #list=(str(project_api.get_projects_for_user(request.user.id))).replace("<Project: ","").replace(', ','').replace('[','').replace("]",'').split('>')
        #list = project_api.get_projects_for_user(request.user.id).values_list('title',flat=True)
        #print list

        #if name in list:
        if project_api.duplicate_project(request.user,request.POST):
            form.if_dup(1)
        if form.is_valid() :
            project_api.create_project(request.user, request.POST)
            project = form.save(commit=False)
            # return redirect('/req/projects')
            # return empty string and do the redirect stuff in front-end
            return HttpResponse('')

    else:
        form = ProjectForm()

    context = {'projects': project_api.get_projects_for_user(request.user.id),
               'canOwnProject': request.user.has_perm(PERMISSION_OWN_PROJECT),
               'title': 'New Project',
               'form': form, 'action': '/req/newproject', 'button_desc': 'Create Project'}
    return render(request, 'ProjectSummary.html', context)
Esempio n. 2
0
def new_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        name = str(request.POST['title'])
        #list=(str(project_api.get_projects_for_user(request.user.id))).replace("<Project: ","").replace(', ','').replace('[','').replace("]",'').split('>')
        #list = project_api.get_projects_for_user(request.user.id).values_list('title',flat=True)
        #print list

        #if name in list:
        if project_api.duplicate_project(request.user, request.POST):
            form.if_dup(1)
        if form.is_valid():
            project_api.create_project(request.user, request.POST)
            project = form.save(commit=False)
            # return redirect('/req/projects')
            # return empty string and do the redirect stuff in front-end
            return HttpResponse('')

    else:
        form = ProjectForm()

    context = {
        'projects': project_api.get_projects_for_user(request.user.id),
        'canOwnProject': request.user.has_perm(PERMISSION_OWN_PROJECT),
        'title': 'New Project',
        'form': form,
        'action': '/req/newproject',
        'button_desc': 'Create Project'
    }
    return render(request, 'ProjectSummary.html', context)
Esempio n. 3
0
def new_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            project_api.create_project(request.user, request.POST)
            project = form.save(commit=False)
            return redirect('/req/projects')
    else:
        form = ProjectForm()
        
    context = {'projects' : project_api.get_projects_for_user(request.user.id),
               'canOwnProject' : request.user.has_perm(PERMISSION_OWN_PROJECT),
               'title' : 'New Project',
               'form' : form, 'action' : '/req/newproject' , 'desc' : 'Create Project' }
    return render(request, 'ProjectSummary.html', context )
Esempio n. 4
0
def new_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            project_api.create_project(request.user, request.POST)
            project = form.save(commit=False)
            # return redirect('/req/projects')
            # return empty string and do the redirect stuff in front-end
            return HttpResponse('')
    else:
        form = ProjectForm()
        
    context = {'projects' : project_api.get_projects_for_user(request.user.id),
               'canOwnProject' : request.user.has_perm(PERMISSION_OWN_PROJECT),
               'title' : 'New Project',
               'form' : form, 'action' : '/req/newproject' , 'button_desc' : 'Create Project' }
    return render(request, 'ProjectSummary.html', context )
Esempio n. 5
0
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
Esempio n. 6
0
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')