Пример #1
0
def new_story(request, projectID):
    story = Story()
    project = project_api.get_project(projectID)
    association = UserAssociation.objects.get(user=request.user,
                                              project=project)
    if request.method == 'POST':
        form = StoryForm(request.POST, project=project)
        if form.is_valid():
            # <<<<<<< HEAD
            story = form.save(commit=False)
            formset = TaskFormSet(request.POST, instance=story)
            if formset.is_valid():
                story = mdl_story.create_story(project, request.POST)
                formset.instance = story
                formset.save()
                # return redirect('/req/projects/' + projectID)
                # return empty string and do the redirect stuff in front-end
                return HttpResponse('')
        else:
            formset = TaskFormSet(request.POST, instance=story)
            # formset.extra = 1
# =======
# story = mdl_story.create_story(project, request.POST)
# story = form.save(commit=False)
# if not 'next' in request.POST:
#     return redirect('/req/projectdetail/' + projectID)
# else:
#     next = request.POST['next']
#     return redirect(next)
# >>>>>>> newfeature-additerationdetail
    else:
        form = StoryForm(project=project)
        formset = TaskFormSet(instance=story)
        formset.extra = 1
    # project = project_api.get_project(projectID)
    # association = UserAssociation.objects.get(user=request.user, project=project)
    context = {
        'title': 'New User Story',
        'form': form,
        'project': project,
        'association': association,
        # <<<<<<< HEAD
        #                # 'formset' : formset,
        #                'action' : '/req/newstory/' + projectID ,
        #                'button_desc' : 'Create User Story',
        #                 }
        #     return render(request, 'StorySummary.html', context )
        # =======
        'formset': formset,
        'initTasks': formset.initial_form_count(),
        'numTasks': formset.total_form_count(),
        'action': '/req/newstory/' + projectID,
        'button_desc': 'Create User Story'
    }
    return render(request, 'StorySummary.html', context)
Пример #2
0
def edit_story(request, projectID, storyID):
    project = project_api.get_project(projectID)
    association = UserAssociation.objects.get(user=request.user,
                                              project=project)
    story = mdl_story.get_story(storyID)
    if story is None:
        # return redirect('/req/projectdetail/' + projectID)
        # return empty string and do the redirect stuff in front-end
        return HttpResponse('')
    if request.method == 'POST':
        form = StoryForm(request.POST, instance=story, project=project)
        if form.is_valid():
            # <<<<<<< HEAD
            story = form.save(commit=False)
            formset = TaskFormSet(request.POST, instance=story)

            if formset.is_valid():
                story.save()
                # formset.instance=story
                formset.save()
                # return redirect('/req/projects/' + projectID)
                # return empty string and do the redirect stuff in front-end
                return HttpResponse('')

        else:
            formset = TaskFormSet(request.POST, instance=story)
    else:

        form = StoryForm(instance=story, project=project)
        formset = TaskFormSet(instance=story)
        numTasks = initTasks = mdl_task.get_tasks_for_story(
            story).count()  # story.task_set.count()
        if numTasks == 0:
            numTasks = 1
        else:
            numTasks = numTasks + 1
        formset.extra = 1

    context = {
        'title': 'Edit User Story',
        'project': project,
        'association': association,
        'title': 'Edit User Story',
        'form': form,
        'formset': formset,
        'initTasks': formset.initial_form_count(),
        'numTasks': formset.total_form_count(),
        'action': '/req/editstory/' + projectID + '/' + storyID,
        'button_desc': 'Save Changes'
    }

    return render(request, 'StorySummary.html', context)
def new_story(request, projectID):
    story = Story()
    project = project_api.get_project(projectID)
    association = UserAssociation.objects.get(
        user=request.user,
        project=project)
    if request.method == 'POST':
        form = StoryForm(request.POST, project=project)

        if form.is_valid():
            story = form.save(commit=False)
            formset = TaskFormSet(request.POST, instance=story)
            if formset.is_valid():
                story = mdl_story.create_story(project, request.POST)
                formset.instance = story
                formset.save()
                # return empty string and do the redirect stuff in front-end
                return HttpResponse('')
        else:
            formset = TaskFormSet(request.POST, instance=story)
    else:
        form = StoryForm(project=project)
        formset = TaskFormSet(instance=story)
        formset.extra = 1
    context = {
        'title': 'New User Story',
        'form': form,
        'project': project,
        'association': association,

        'formset': formset,
        'initTasks': formset.initial_form_count(),
        'numTasks': formset.total_form_count(),
        'action': '/requirements/newstory/' + projectID,
        'button_desc': 'Create User Story'
    }
    return render(request, 'StorySummary.html', context)
Пример #4
0
def edit_story(request, projectID, storyID):
    project = project_api.get_project(projectID)
    association = UserAssociation.objects.get(user=request.user,
                                              project=project)
    story = mdl_story.get_story(storyID)
    if story is None:
        # return redirect('/req/projectdetail/' + projectID)
        # return empty string and do the redirect stuff in front-end
        return HttpResponse('')
    if request.method == 'POST':
        form = StoryForm(request.POST, instance=story, project=project)
        if form.is_valid():
            # <<<<<<< HEAD
            story = form.save(commit=False)
            formset = TaskFormSet(request.POST, instance=story)

            if formset.is_valid():
                story.save()
                # formset.instance=story
                formset.save()
                # return redirect('/req/projects/' + projectID)
                # return empty string and do the redirect stuff in front-end
                return HttpResponse('')
# =======
# story = form.save(commit=True)

# if not 'next' in request.POST:
#     return redirect('/req/projectdetail/' + projectID)
# else:
#     next = request.POST['next']
#     return redirect(next)
        else:
            formset = TaskFormSet(request.POST, instance=story)
# >>>>>>> newfeature-additerationdetail
    else:
        # <<<<<<< HEAD
        #         form = StoryForm(instance=story, project=project)
        # formset = TaskFormSet(instance=story)
        # if story.task_set.count() == 0: formset.extra = 1

        # test that association and permissions are working
        # print "UserID "+str(request.user.id)+" and ProjectID "+projectID+" and storyID "+storyID
        # can_edit_hours = association.get_permission("EditHours") # should become unnecessary
        # str_edit_hours = str(can_edit_hours)
        # print "In association of user and project, permission EditHours is "+str_edit_hours
        # =======
        form = StoryForm(instance=story, project=project)
        formset = TaskFormSet(instance=story)
        numTasks = initTasks = mdl_task.get_tasks_for_story(
            story).count()  # story.task_set.count()
        if numTasks == 0:
            numTasks = 1
        else:
            numTasks = numTasks + 1
        formset.extra = 1


# >>>>>>> newfeature-TasksFormset

    context = {
        'title': 'Edit User Story',
        'project': project,
        'association': association,
        'title': 'Edit User Story',
        'form': form,
        # <<<<<<< HEAD
        #                # 'formset' : formset,
        #                'action' : '/req/editstory/' + projectID + '/' + storyID,
        #                'button_desc' : 'Save Changes'}
        # =======
        'formset': formset,
        'initTasks': formset.initial_form_count(),
        'numTasks': formset.total_form_count(),
        'action': '/req/editstory/' + projectID + '/' + storyID,
        'button_desc': 'Save Changes'
    }
    # >>>>>>> newfeature-TasksFormset

    return render(request, 'StorySummary.html', context)