Ejemplo n.º 1
0
    def post(self, request):
        form = NewPlanForm(request.POST)
        form.populate(product_id=request.POST.get('product'))

        if form.is_valid():
            test_plan = TestPlan.objects.create(
                product=form.cleaned_data['product'],
                author=request.user,
                product_version=form.cleaned_data['product_version'],
                type=form.cleaned_data['type'],
                name=form.cleaned_data['name'],
                create_date=datetime.datetime.now(),
                extra_link=form.cleaned_data['extra_link'],
                parent=form.cleaned_data['parent'],
                text=form.cleaned_data['text'],
                is_active=form.cleaned_data['is_active'],
            )

            update_plan_email_settings(test_plan, form)

            return HttpResponseRedirect(
                reverse('test_plan_url_short', args=[
                    test_plan.plan_id,
                ]))

        context_data = {
            'form': form,
        }
        return render(request, self.template_name, context_data)
Ejemplo n.º 2
0
def new(request):
    """New testplan"""

    # If the form has been submitted...
    if request.method == 'POST':
        # A form bound to the POST data
        form = NewPlanForm(request.POST)
        form.populate(product_id=request.POST.get('product'))

        if form.is_valid():
            test_plan = TestPlan.objects.create(
                product=form.cleaned_data['product'],
                author=request.user,
                product_version=form.cleaned_data['product_version'],
                type=form.cleaned_data['type'],
                name=form.cleaned_data['name'],
                create_date=datetime.datetime.now(),
                extra_link=form.cleaned_data['extra_link'],
                parent=form.cleaned_data['parent'],
                text=form.cleaned_data['text'],
            )

            # create emailing settings to avoid Issue #181 on MySQL
            test_plan.emailing.save()

            return HttpResponseRedirect(
                reverse('test_plan_url_short', args=[test_plan.plan_id, ])
            )
    else:
        form = NewPlanForm()

    context_data = {
        'form': form,
    }
    return render(request, 'testplans/mutable.html', context_data)
Ejemplo n.º 3
0
def edit(request, plan_id):
    """Edit test plan view"""

    try:
        test_plan = TestPlan.objects.select_related().get(plan_id=plan_id)
    except ObjectDoesNotExist:
        raise Http404

    # If the form is submitted
    if request.method == "POST":
        form = NewPlanForm(request.POST)
        form.populate(product_id=request.POST.get('product'))

        # FIXME: Error handle
        if form.is_valid():
            test_plan.name = form.cleaned_data['name']
            test_plan.parent = form.cleaned_data['parent']
            test_plan.product = form.cleaned_data['product']
            test_plan.product_version = form.cleaned_data['product_version']
            test_plan.type = form.cleaned_data['type']
            test_plan.is_active = form.cleaned_data['is_active']
            test_plan.extra_link = form.cleaned_data['extra_link']
            test_plan.text = form.cleaned_data['text']
            test_plan.save()

            # Update plan email settings
            update_plan_email_settings(test_plan, form)
            return HttpResponseRedirect(
                reverse('test_plan_url',
                        args=[plan_id, slugify(test_plan.name)]))
    else:
        form = NewPlanForm(
            initial={
                'name': test_plan.name,
                'product': test_plan.product_id,
                'product_version': test_plan.product_version_id,
                'type': test_plan.type_id,
                'text': test_plan.text,
                'parent': test_plan.parent_id,
                'is_active': test_plan.is_active,
                'extra_link': test_plan.extra_link,
                'auto_to_plan_author': test_plan.emailing.auto_to_plan_author,
                'auto_to_case_owner': test_plan.emailing.auto_to_case_owner,
                'auto_to_case_default_tester':
                test_plan.emailing.auto_to_case_default_tester,
                'notify_on_plan_update':
                test_plan.emailing.notify_on_plan_update,
                'notify_on_case_update':
                test_plan.emailing.notify_on_case_update,
            })
        form.populate(product_id=test_plan.product_id)

    context_data = {
        'test_plan': test_plan,
        'form': form,
    }
    return render(request, 'testplans/mutable.html', context_data)
Ejemplo n.º 4
0
def new(request, template_name='plan/new.html'):
    """New testplan"""

    # If the form has been submitted...
    if request.method == 'POST':
        # A form bound to the POST data
        form = NewPlanForm(request.POST, request.FILES)
        form.populate(product_id=request.POST.get('product'))

        if form.is_valid():
            test_plan = TestPlan.objects.create(
                product=form.cleaned_data['product'],
                author=request.user,
                owner=request.user,
                product_version=form.cleaned_data['product_version'],
                type=form.cleaned_data['type'],
                name=form.cleaned_data['name'],
                create_date=datetime.datetime.now(),
                extra_link=form.cleaned_data['extra_link'],
                parent=form.cleaned_data['parent'],
            )

            # Add test plan text
            if request.user.has_perm('testplans.add_testplantext'):
                test_plan.add_text(author=request.user,
                                   plan_text=form.cleaned_data['text'])

            # Add test plan environment groups
            if request.user.has_perm('testplans.add_envplanmap'):
                if request.POST.get('env_group'):
                    env_groups = EnvGroup.objects.filter(
                        id__in=request.POST.getlist('env_group'))

                    for env_group in env_groups:
                        test_plan.add_env_group(env_group=env_group)

            # create emailing settings to avoid Issue #181 on MySQL
            test_plan.emailing.save()

            return HttpResponseRedirect(
                reverse('test_plan_url_short', args=[
                    test_plan.plan_id,
                ]))
    else:
        form = NewPlanForm()

    context_data = {
        'form': form,
    }
    return render(request, template_name, context_data)
Ejemplo n.º 5
0
    def post(self, request):
        form = NewPlanForm(request.POST, request.FILES)
        form.populate(product_id=request.POST.get('product'))

        if not form.is_valid():
            return self.make_response(form)

        # Process the upload plan document
        if form.cleaned_data.get('upload_plan_text'):
            # Set the summary form field to the uploaded text
            form.data['text'] = form.cleaned_data['text']
            return self.make_response(form)

        # Process the test plan submit to the form
        tp = TestPlan.objects.create(
            product=form.cleaned_data['product'],
            author=request.user,
            owner=request.user,
            product_version=form.cleaned_data['product_version'],
            type=form.cleaned_data['type'],
            name=form.cleaned_data['name'],
            create_date=datetime.datetime.now(),
            extra_link=form.cleaned_data['extra_link'],
            parent=form.cleaned_data['parent'],
        )

        tp.add_text(author=request.user, plan_text=form.cleaned_data['text'])

        # Add test plan environment groups
        if request.POST.get('env_group'):
            env_groups = TCMSEnvGroup.objects.filter(
                id__in=request.POST.getlist('env_group'))

            for env_group in env_groups:
                tp.add_env_group(env_group=env_group)

        return HttpResponseRedirect(reverse('plan-get', args=[tp.plan_id]))
Ejemplo n.º 6
0
def new(request, template_name='plan/new.html'):
    """New testplan"""

    SUB_MODULE_NAME = "new_plan"

    # If the form has been submitted...
    if request.method == 'POST':
        # A form bound to the POST data
        form = NewPlanForm(request.POST, request.FILES)
        form.populate(product_id=request.POST.get('product'))

        # Process the upload plan document
        if form.is_valid():
            if form.cleaned_data.get('upload_plan_text'):
                # Set the summary form field to the uploaded text
                form.data['text'] = form.cleaned_data['text']

                # Generate the form
                context_data = {
                    'module': MODULE_NAME,
                    'sub_module': SUB_MODULE_NAME,
                    'form': form,
                }
                return render(request, template_name, context=context_data)

        # Process the test plan submit to the form

        if form.is_valid():
            tp = TestPlan.objects.create(
                product=form.cleaned_data['product'],
                author=request.user,
                owner=request.user,
                product_version=form.cleaned_data['product_version'],
                type=form.cleaned_data['type'],
                name=form.cleaned_data['name'],
                create_date=datetime.datetime.now(),
                extra_link=form.cleaned_data['extra_link'],
                parent=form.cleaned_data['parent'],
            )

            TestPlanEmailSettings.objects.create(plan=tp)

            # Add test plan text
            if request.user.has_perm('testplans.add_testplantext'):
                tp.add_text(author=request.user,
                            plan_text=form.cleaned_data['text'])

            # Add test plan environment groups
            if request.user.has_perm('management.add_tcmsenvplanmap'):
                if request.POST.get('env_group'):
                    env_groups = TCMSEnvGroup.objects.filter(
                        id__in=request.POST.getlist('env_group'))

                    for env_group in env_groups:
                        tp.add_env_group(env_group=env_group)

            return HttpResponseRedirect(reverse('plan-get', args=[tp.plan_id]))
    else:
        form = NewPlanForm()

    context_data = {
        'module': MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'form': form,
    }
    return render(request, template_name, context=context_data)
Ejemplo n.º 7
0
def edit(request, plan_id):
    """Edit test plan view"""

    try:
        test_plan = TestPlan.objects.select_related().get(plan_id=plan_id)
    except ObjectDoesNotExist:
        raise Http404

    # If the form is submitted
    if request.method == "POST":
        form = NewPlanForm(request.POST)
        form.populate(product_id=request.POST.get('product'))

        # FIXME: Error handle
        if form.is_valid():
            if request.user.has_perm('testplans.change_testplan'):
                test_plan.name = form.cleaned_data['name']
                test_plan.parent = form.cleaned_data['parent']
                test_plan.product = form.cleaned_data['product']
                test_plan.product_version = form.cleaned_data[
                    'product_version']
                test_plan.type = form.cleaned_data['type']
                test_plan.is_active = form.cleaned_data['is_active']
                test_plan.extra_link = form.cleaned_data['extra_link']
                # IMPORTANT! tp.current_user is an instance attribute,
                # added so that in post_save, current logged-in user info
                # can be accessed.
                # Instance attribute is usually not a desirable solution.
                test_plan.current_user = request.user
                test_plan.text = form.cleaned_data['text']
                test_plan.save()

            # Update plan email settings
            update_plan_email_settings(test_plan, form)
            return HttpResponseRedirect(
                reverse('test_plan_url',
                        args=[plan_id, slugify(test_plan.name)]))
    else:
        form = NewPlanForm(
            initial={
                'name': test_plan.name,
                'product': test_plan.product_id,
                'product_version': test_plan.product_version_id,
                'type': test_plan.type_id,
                'text': test_plan.text,
                'parent': test_plan.parent_id,
                'is_active': test_plan.is_active,
                'extra_link': test_plan.extra_link,
                'auto_to_plan_author': test_plan.emailing.auto_to_plan_author,
                'auto_to_case_owner': test_plan.emailing.auto_to_case_owner,
                'auto_to_case_default_tester':
                test_plan.emailing.auto_to_case_default_tester,
                'notify_on_plan_update':
                test_plan.emailing.notify_on_plan_update,
                'notify_on_case_update':
                test_plan.emailing.notify_on_case_update,
            })
        form.populate(product_id=test_plan.product_id)

    context_data = {
        'test_plan': test_plan,
        'form': form,
    }
    return render(request, 'testplans/mutable.html', context_data)
Ejemplo n.º 8
0
def new(request, template_name='plan/new.html'):
    """New testplan"""

    SUB_MODULE_NAME = "new_plan"

    # If the form has been submitted...
    if request.method == 'POST':
        # A form bound to the POST data
        form = NewPlanForm(request.POST, request.FILES)
        form.populate(product_id=request.POST.get('product'))

        # Process the upload plan document
        if form.is_valid():
            if form.cleaned_data.get('upload_plan_text'):
                # Set the summary form field to the uploaded text
                form.data['text'] = form.cleaned_data['text']

                # Generate the form
                context_data = {
                    'module': MODULE_NAME,
                    'sub_module': SUB_MODULE_NAME,
                    'form': form,
                }
                return render_to_response(template_name, context_data,
                                          context_instance=RequestContext(request))

        # Process the test plan submit to the form

        if form.is_valid():
            tp = TestPlan.objects.create(
                product=form.cleaned_data['product'],
                author=request.user,
                owner=request.user,
                product_version=form.cleaned_data['product_version'],
                type=form.cleaned_data['type'],
                name=form.cleaned_data['name'],
                create_date=datetime.datetime.now(),
                extra_link=form.cleaned_data['extra_link'],
                parent=form.cleaned_data['parent'],
            )

            # Add test plan text
            if request.user.has_perm('testplans.add_testplantext'):
                tp.add_text(author=request.user, plan_text=form.cleaned_data['text'])

            # Add test plan environment groups
            if request.user.has_perm('management.add_tcmsenvplanmap'):
                if request.POST.get('env_group'):
                    env_groups = TCMSEnvGroup.objects.filter(
                        id__in=request.POST.getlist('env_group')
                    )

                    for env_group in env_groups:
                        tp.add_env_group(env_group=env_group)

            return HttpResponseRedirect(
                reverse('tcms.testplans.views.get', args=[tp.plan_id, ])
            )
    else:
        form = NewPlanForm()

    context_data = {
        'module': MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'form': form,
    }
    return render_to_response(template_name, context_data,
                              context_instance=RequestContext(request))