Exemplo n.º 1
0
def editProject(request, pid):
    """
    编辑项目
    :param request: 
    :return: 
    """
    if request.method == "GET":
        pro = Project.objects.get(id=pid)
        print(pro.status)
        form = ProjectForm(instance=pro)
        return render(request, "project_manage.html", {
            "type": "edit",
            "form": form,
            "id": pid,
            "pro": pro
        })
    if request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            describle = form.cleaned_data['describle']
            status = form.cleaned_data['status']
            print(status)
            pro_update = Project.objects.get(id=pid)
            pro_update.name = name
            pro_update.describle = describle
            pro_update.status = status
            pro_update.save()
            return HttpResponseRedirect("/ProManage/")
Exemplo n.º 2
0
def edit_project(request, pid):
    """
    编辑项目
    :param request:
    :return:
    """
    if request.method == "GET":
        if pid:
            p = Project.objects.get(id=pid)
            form = ProjectForm(isinstance(p))
            return render(request, "project.html", {
                "type": "edit",
                "form": form,
                "id": pid
            })
        elif request.method == "POST":
            form = ProjectForm(request.POST)
            if form.is_valid():
                name = form.cleaned_data['name']
                describe = form.cleaned_data['describe']
                status = form.cleaned_data['status']
                p = Project.objects.get(id=pid)
                p.name = name
                p.describe = describe
                p.status = status
                p.save()
            return HttpResponseRedirect("/project")
Exemplo n.º 3
0
def edit_project(request,pid):
    """
    编辑项目
    """
    # print("请求方法",request.method)
    if request.method == "GET":

        if pid:
            p = Project.objects.get(id=pid)
            project_form = ProjectForm(instance=p)
            return render(request,"project.html",{"type":"edit",
                                                  "form":project_form,
                                                  "id":pid})
# 编辑完数据更新数据
    if request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data["name"]
            describe = form.cleaned_data["describe"]
            status = form.cleaned_data["status"]

            p = Project.objects.get(id=pid)
            p.name = name
            p.describe = describe
            p.status = status
            p.save()
        return HttpResponseRedirect("/project/")
Exemplo n.º 4
0
def edit_project(request, pid):
    '''
    编辑项目
    :param request:
    :return:
    '''
    if request.method == "GET":
        pro = Project.objects.get(id=pid)
        form = ProjectForm(instance=pro)
        return render(request, "project_manage.html", {
            "type": "edit",
            "form": form,
            "pid": pid
        })
    elif request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            describle = form.cleaned_data['describle']
            status = form.cleaned_data['status']
            #保存更新
            p = Project.objects.get(id=pid)
            p.status = status
            p.name = name
            p.describle = describle
            p.save()
        return HttpResponseRedirect('/project/')
Exemplo n.º 5
0
    def test_project_form_valid_data(self):
        form = ProjectForm(
            data={
                'name': 'TESTPRO00013',
                'description':
                'API Test 11 API Test 11 API Test 11 API Test 1 API Test 1 API Test 1 API Test 1 API Test 1 API Test 1 API Test 1 API Test 1 API Test 1',
                'start_date': '2021-02-03'
            })

        self.assertTrue(form.is_valid())
Exemplo n.º 6
0
def add_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            describe = form.cleaned_data['describe']
            status = form.cleaned_data['status']
            Project.objects.create(name=name, describe=describe, status=status)
            return HttpResponseRedirect('/manage/project_manage/')

    else:
        form = ProjectForm()

    return render(request, 'project_manage.html', {
        'form': form,
        "type": "add",
    })
Exemplo n.º 7
0
def add_project(request):
    if request.method == 'POST':  #提交表单的post请求
        form = ProjectForm(request.POST)  #用ProjectForm校验表单数据
        if form.is_valid():  #判断表单数据校验结果
            #获取表单数据
            name = form.cleaned_data['name']
            describe = form.cleaned_data['describe']
            status = form.cleaned_data['status']
            #保存表单数据到库
            Project.objects.create(name=name, describe=describe, status=status)
            return HttpResponseRedirect('/manage/project_manage/')
    else:  #进入表单页面的get请求
        form = ProjectForm()
    return render(request, 'project_manage.html', {
        'form': form,
        'type': 'add'
    })
Exemplo n.º 8
0
def edit_project(request, pid):
    """
    编辑/修改项目
    :param request:
    :param pid:
    :return:
    """
    if request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            model = Project.objects.get(id=pid)
            model.name = form.cleaned_data['name']
            model.describe = form.cleaned_data['describe']
            model.status = form.cleaned_data['status']
            model.save()
            return HttpResponseRedirect('/manage/project_manage/')

    else:
        if pid:
            # instance属性,表示与它绑定的模型实例
            form = ProjectForm(
                instance=Project.objects.get(id=pid)  # 赋值instance可以使form表单是可以接受对象的数据
            )
        else:
            form = ProjectForm()

    return render(request, 'project_manage.html', {
        'form': form,
        "type": "edit",
    })
Exemplo n.º 9
0
def edit_project(request, pid):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            model = Project.objects.get(id=pid)
            model.name = form.cleaned_data['name']
            model.describe = form.cleaned_data['describe']
            model.status = form.cleaned_data['status']
            model.save()
            return HttpResponseRedirect('/manage/project_manage/')
    else:
        if pid:
            form = ProjectForm(instance=Project.objects.get(id=pid))

    return render(request, 'project_manage.html', {
        'form': form,
        'type': 'edit',
    })
Exemplo n.º 10
0
def add_project(request):
    """
    添加项目
    :param request:
    :return:
    """
    if request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            describe = form.cleaned_data['describe']
            status = form.cleaned_data['status']
            Project.objects.create(name=name, describe=describe, status=status)
            return HttpResponseRedirect('/project/')
    else:
        form = ProjectForm()
        return render(request, "project.html", {"type": "add",
                                                "form": form}
                      )
Exemplo n.º 11
0
def edit_project(request, pid):
    """编辑项目"""
    if request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            model = Project.objects.get(id=pid)
            model.name = form.cleaned_data['name']
            model.describe = form.cleaned_data['describe']
            model.status = form.cleaned_data['status']
            model.save()
            return HttpResponseRedirect('/manage/project_manage/')
    else:
        if pid:
            form = ProjectForm(instance=Project.objects.get(id=pid))
    context = {
        "form": form,
        "type": "edit",
    }
    return render(request, 'project_manage.html', context=context)
Exemplo n.º 12
0
def edit_project(request, pid):
    porject = Project.objects.get(id=pid)
    if request.method == 'POST':  #提交表单的post请求
        form = ProjectForm(request.POST)  #用ProjectForm校验表单数据
        # 如果是post,instance=article当前数据填充表单,并用data=request.POST获取到表单里的内容
        form = ProjectForm(instance=porject, data=request.POST)
        form.save()  # 保存
        if form.is_valid():  #判断表单数据校验结果
            return HttpResponseRedirect('/manage/project_manage/')
    else:  #进入表单页面的get请求
        if pid:
            form = ProjectForm(instance=porject)
    return render(request, 'project_manage.html', {
        'form': form,
        'type': 'edit'
    })
Exemplo n.º 13
0
def add_project(request):
    '''
    项目添加
    '''
    if request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data["title"]
            describe = form.cleaned_data["describe"]
            status = form.cleaned_data["status"]
            Project.objects.create(title=title,
                                   describe=describe,
                                   status=status)
            return HttpResponseRedirect('/manage/project_manage/')
    else:
        form = ProjectForm()
    return render(request, "project_manage.html", {
        "type": "add",
        "form": form
    })
Exemplo n.º 14
0
def edit_project(request, pid):

    if request.method == 'GET':

        if pid:

            pro = Project.objects.get(id=pid)

            form = ProjectForm(instance=pro)

            return render(request, "project.html", {
                "type": "edit",
                "form": form,
                "pid": pid
            })

    elif request.method == 'POST':

        form = ProjectForm(request.POST)

        if form.is_valid():

            name = form.cleaned_data['name']

            describe = form.cleaned_data['describe']

            status = form.cleaned_data['status']

            p_update = Project.objects.get(id=pid)

            p_update.name = name

            p_update.describe = describe

            p_update.status = status

            p_update.save()

            return HttpResponseRedirect("/project/")
Exemplo n.º 15
0
def edit_project(request, pid):
    if request.method == 'GET':
        project = Project.objects.get(id=pid)
        form = ProjectForm(instance=project)
        return render(request, 'project.html', {
            'type': 'edit',
            'form': form,
            'id': pid
        })

    elif request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            describe = form.cleaned_data['describe']
            status = form.cleaned_data['status']
            p = Project.objects.get(id=pid)
            p.name = name
            p.describe = describe
            p.status = status
            p.save()
            return HttpResponseRedirect('/project/')
Exemplo n.º 16
0
def add_project(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = ProjectForm(request.POST)
        # check whether it's valid:
        if form.is_valid():

            # process the data in form.cleaned_data as required
            name = form.cleaned_data['name']
            describe = form.cleaned_data['describe']
            status=form.cleaned_data['status']
            Project.objects.create(name=name,describe=describe,status=status)
            # redirect to a new URL:
            return HttpResponseRedirect('/manage/project_manage/')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = ProjectForm()

    return render(request, 'project_manage.html', {'type':'add',
                                                   'form': form})
Exemplo n.º 17
0
def add_project(request):
    # 如果form通过POST方法发送数据
    if request.method == 'POST':
        # 接受request.POST参数构造form类的实例
        form = ProjectForm(request.POST)
        # print(request.POST)
        # 验证数据是否合法
        if form.is_valid():
            name = form.cleaned_data["name"]
            describe = form.cleaned_data["describe"]
            status = form.cleaned_data["status"]
            # create_time = form.cleaned_data["create_time"]
            project = Project(name=name, describe=describe, status=status)
            project.save()
            # return HttpResponse("添加成功")
            return HttpResponseRedirect('/manage/project_manage/')
    # 如果是通过GET方法请求数据,返回一个空的表单
    else:
        form = ProjectForm()
    return render(request, 'project_app/project_manage.html', {
        'type': 'add',
        'form': form
    })
Exemplo n.º 18
0
def add_project(request):
    """
    添加项目
    :param request:
    :return:
    """
    if request.method == "POST":
        form = ProjectForm(request.POST)
        # 判断表单是否有效
        if form.is_valid():
            # 已验证的表单数据将被放到form.cleaned_data字典中,这里的数据已经很好的转化为python类型。
            name = form.cleaned_data['name']
            describe = form.cleaned_data['describe']
            status = form.cleaned_data['status']
            Project.objects.create(name=name, describe=describe, status=status)
            return HttpResponseRedirect('/manage/project_manage/')
    else:
        form = ProjectForm()

    return render(request, 'project_manage.html', {
        'form': form,
        "type": "add",
    })
Exemplo n.º 19
0
def edit_project(request, project_id):
    # print("编辑项目的id:", project_id)
    if request.method == 'POST':
        # 接受request.POST参数构造form类的实例
        form = ProjectForm(request.POST)
        if form.is_valid():
            # 数据库查询数据
            project = Project.objects.get(id=project_id)
            # 更新数据
            project.name = form.cleaned_data['name']
            project.describe = form.cleaned_data["describe"]
            project.status = form.cleaned_data["status"]
            # 保存
            project.save()
            return HttpResponseRedirect('/manage/project_manage/')
    else:
        project = Project.objects.get(id=project_id)
        form = ProjectForm(instance=project)

    return render(request, "project_app/project_manage.html", {
        'type': 'edit',
        'form': form
    })
Exemplo n.º 20
0
def edit_project(request, pid):
    """
    编辑项目
    :param request:
    :return:
    """
    if request.method == "GET":
        try:
            if pid:
                p = Project.objects.get(id=pid)
                """
                子类ModelForm 可以接受现有的模型实例作为关键字参数instance,
                如果提供了这个,save()
                将更新该实例
                ps:instance其实就是此处ProjectForm的实例
                """
                form = ProjectForm(instance=p)
                return render(request, "project.html", {"type": "edit",
                                                        "form": form,
                                                        "id": pid})
        except:
            # return HttpResponse("待编辑的项目不存在")
            return render(request, "project.html", {"error": "待编辑的项目不存在",
                                                    "type": "error"})
    if request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            p = Project.objects.get(id=pid)
            """
              将form表单新的值,赋值给p.name, p.describe等
            """
            p.name = form.cleaned_data["name"]
            p.describe = form.cleaned_data["describe"]
            p.status = form.cleaned_data["status"]
            p.save()
            return HttpResponseRedirect('/project/')
Exemplo n.º 21
0
def edit_project(request, pid):
    '''
    项目编辑功能
    '''
    if request.method == "POST":
        form = ProjectForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data["title"]
            describe = form.cleaned_data["describe"]
            status = form.cleaned_data["status"]
            Project.objects.filter(id=pid).update(title=title,
                                                  describe=describe,
                                                  status=status)
            return HttpResponseRedirect('/manage/project_manage/')
    else:
        if pid:
            form = ProjectForm(instance=Project.objects.filter(id=pid).first())
        #project_data = Project.objects.filter(id=pid).first()

    return render(request, "project_manage.html", {
        "type": "edit",
        "form": form,
        "id": pid
    })
Exemplo n.º 22
0
    def test_project_form_no_data(self):
        form = ProjectForm(data={})

        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 3)