예제 #1
0
def wiki_edit(request, project_id, wiki_id):
    """编辑Wiki"""
    # 判断是否存在此编辑对象,不存在则返回到Wiki页面
    wiki_object = models.Wiki.objects.filter(project_id=project_id,
                                             id=wiki_id).first()
    if not wiki_object:
        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    # 和wiki_add一样,先出现form表单,表单中有默认值
    if request.method == 'GET':
        form = WikiModelForm(request, instance=wiki_object)
        return render(request, 'web/wiki_form.html', {'form': form})
    form = WikiModelForm(request, data=request.POST, instance=wiki_object)
    if form.is_valid():
        # 判断是否选择父级文章,如果选择,则depth+1,如果没选择,则forms.instance.depth=1
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth = 1
        form.save()
        url = reverse('wiki', kwargs={'project_id': project_id})
        # 给他重新定位到当前Wiki的页面
        preview_url = "{0}?wiki_id={1}".format(url, wiki_id)
        return redirect(preview_url)
    return render(request, 'web/wiki_form.html', {'form': form})
예제 #2
0
def wiki_modify(request, project_id, wiki_id):
    """修改wiki"""
    if request.method == "GET":
        wiki_obj = models.Wiki.objects.filter(id=wiki_id,
                                              project_id=project_id).first()

        if not wiki_obj:
            return redirect(
                reverse('web:manage:wiki', kwargs={'project_id': project_id}))

        # 使用initial初始化表单
        # form = WikiModelForm(request, initial=dict(title=wiki_obj.title, content=wiki_obj.content, parent=wiki_obj.parent))
        # 或者直接传入wiki对象
        form = WikiModelForm(request, instance=wiki_obj)

        return render(request, 'web/wiki_form.html', {'form': form})

    if request.method == "POST":
        form = WikiModelForm(request, data=request.POST)

        if form.is_valid():
            # 数据验证通过 更新库
            models.Wiki.objects.filter(
                id=wiki_id, project_id=project_id).update(**form.cleaned_data)

        return redirect(
            reverse('web:manage:wiki', kwargs={'project_id': project_id}) +
            "?wiki_id=" + str(wiki_id))
예제 #3
0
def wiki_edit(request, project_id, wiki_id):
    """编辑文章"""

    wiki_object = models.Wiki.objects.filter(project_id=project_id, id=wiki_id).first()

    if not wiki_object:
        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    if request.method == 'GET':
        form = WikiModelForm(request, instance=wiki_object)
        return render(request, 'wiki_form.html', {'form': form, 'wiki_object': wiki_object})

    form = WikiModelForm(request, data=request.POST, instance=wiki_object)
    if form.is_valid():
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth = 1

        form.instance.project = request.tracer.project
        form.save()
        url = reverse('wiki', kwargs={'project_id': project_id})
        preview_url = "{0}?wiki_id={1}".format(url, wiki_id)
        return redirect(preview_url)

    return render(request, 'wiki_form.html', {'form': form})
예제 #4
0
def wiki_edit(request, project_id, wiki_id):
    """ 编辑文章 """
    # 获取要编辑wiki对象
    wiki_object = models.Wiki.objects.filter(project_id=project_id,
                                             id=wiki_id).first()
    # 如果没有,则跳转到wiki页面
    if not wiki_object:
        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    # 若有,则将要编辑的文档展示出来
    if request.method == "GET":
        form = WikiModelForm(request, instance=wiki_object)
        return render(request, 'wiki_form.html', {'form': form})
    # 当请求为POST时,用form对提交的wiki进行校验
    form = WikiModelForm(request, data=request.POST, instance=wiki_object)
    if form.is_valid():
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth = 1
        form.save()
        # 跳转到编辑成功的url
        url = reverse('wiki', kwargs={'project_id': project_id})
        preview_url = "{0}?wiki_id={1}".format(url, wiki_id)
        return redirect(preview_url)

    return render(request, 'wiki_form.html', {'form': form})
예제 #5
0
def wiki_add(request, project_id):
    if request.method == "GET":
        form = WikiModelForm(request)
        return render(request, 'wiki_form.html', {'form': form})
    form = WikiModelForm(request, data=request.POST)
    if form.is_valid():
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth += 1
        form.instance.project = request.tracer.project
        form.save()
        url = reverse('web:wiki', kwargs={'project_id': project_id})
        return redirect(url)
    return render(request, 'wiki_form.html', {'form': form})
예제 #6
0
def wiki_add(request, project_id):
    """添加wiki"""
    if request.method == 'GET':
        form = WikiModelForm(request)
        return render(request, 'wiki_add.html', {'forms': form})
    form = WikiModelForm(request, request.POST)

    if form.is_valid():
        if form.instance.parent:  # 如果选择了父wiki
            form.instance.depth = form.instance.parent.depth + 1  # 它的depth就应该是父wiki的depth+1
        else:
            form.instance.depth = 1
        form.instance.project = request.tracer.project  # 帮用户选择该wiki属于什么项目
        form.save()
        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    return render(request, 'wiki_add.html', {'forms': form})
예제 #7
0
def wiki_edit(request, project_id, wiki_id):
    """ 编辑wiki文章 """
    wiki_obj = models.Wiki.objects.filter(id=wiki_id,
                                          project_id=project_id).first()
    if not wiki_obj:
        url = reverse("web:wiki", kwargs={"project_id": project_id})
        return redirect(url)
    if request.method == "GET":
        form = WikiModelForm(request, instance=wiki_obj)
        return render(request, 'web/wiki_form.html', {"form": form})
    form = WikiModelForm(request, data=request.POST, instance=wiki_obj)
    if form.is_valid():
        form.save()
        url = reverse("web:wiki", kwargs={"project_id": project_id})
        edit_url = "{}?wiki_id={}".format(url, wiki_id)
        return redirect(edit_url)
    return render(request, 'web/wiki_form.html', {"form": form})
예제 #8
0
def wiki_add(request, project_id):
    """ 添加wiki文章 """
    if request.method == 'GET':
        form = WikiModelForm(request)
        return render(request, 'wiki_form.html', {'form': form})
    form = WikiModelForm(request, request.POST)
    if form.is_valid():
        # 判断用户是否已经选择父文章
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth = 1
        form.instance.project = request.tracer.project
        form.save()
        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    return render(request, 'wiki_form.html', {'form': form})
예제 #9
0
def wiki_add(request, project_id):
    """ wiki添加 """
    if request.method == "GET":
        form = WikiModelForm(request)
        return render(request, "wiki_form.html", {"form": form})
    form = WikiModelForm(request, data=request.POST)
    if form.is_valid():
        # 判断用户是否已经选择父文章
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth = 1
        form.instance.project = request.tracker.project
        form.save()
        url = reverse("wiki", kwargs={"project_id": project_id})
        return redirect(url)

    return render(request, "wiki_form.html", {"form": form})
예제 #10
0
def wiki_edit(request, project_id, wiki_id):
    wiki_obj = models.Wiki.objects.filter(project=request.lxyker.project,
                                          id=wiki_id).first()
    if not wiki_obj:
        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    if request.method == 'GET':
        form = WikiModelForm(request, instance=wiki_obj)
        return render(request, 'web/wiki_form.html', locals())
    form = WikiModelForm(request, data=request.POST, instance=wiki_obj)
    if form.is_valid():
        # 这篇文章的深度:如果有父深度,那么在父深度上加1;无父深度,表明深度为1
        form.instance.depth = form.instance.parent.depth + 1 if form.instance.parent else 1
        form.save()

        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    return render(request, 'web/wiki_form.html', locals())
예제 #11
0
def wiki_add(request, project_id):
    """增加wiki文章"""
    if request.method == 'GET':
        form = WikiModelForm(request)
        return render(request, 'web/wiki_form.html', locals())
    form = WikiModelForm(request, data=request.POST)
    if form.is_valid():

        # 这篇文章的深度:如果有父深度,那么在父深度上加1;无父深度,表明深度为1
        form.instance.depth = form.instance.parent.depth + 1 if form.instance.parent else 1

        # 用户没有填写project_id,需要我们自己传入保存
        form.instance.project = request.lxyker.project
        form.save()

        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    return render(request, 'web/wiki_form.html', locals())
예제 #12
0
def wiki_add(request, project_id):
    """ wiki添加 """
    if request.method == "GET":
        form = WikiModelForm(request)
        return render(request, 'web/wiki_form.html', {"form": form})

    form = WikiModelForm(request, data=request.POST)
    if form.is_valid():
        # 判断父文章是否为null
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth = 1
        # 校验通过,保存到数据库之前,还有一个必填字段,project
        form.instance.project = request.tracer.project
        form.save()
        url = reverse("web:wiki", kwargs={"project_id": project_id})
        return redirect(url)
    return render(request, "web/wiki_form.html", {"form": form})
예제 #13
0
def wiki_edit(request, project_id, wiki_id):
    """编辑文章"""
    wiki_object = models.Wiki.objects.filter(project_id=project_id, id=wiki_id).first()
    # 非法访问别人的wiki
    if not wiki_object:
        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    if request.method == "GET":
        form = WikiModelForm(request, wiki_id, instance=wiki_object)
        return render(request, 'wiki_add.html',{'form':form})
    # instance 是初始化的值,data是更新的数据,因为有数据在instance中,所以不需要和新建一样传一个
    # form.instance.project = request.tracer.project
    form = WikiModelForm(request,data=request.POST, instance=wiki_object)
    if form.is_valid():
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth = 1
        form.save()
        url = reverse('wiki', kwargs={'project_id': project_id})
        preview_url = "{0}?wiki_id={1}".format(url, wiki_id)
        return redirect(preview_url)
예제 #14
0
def wiki_add(request, project_id):
    """
    wiki添加
    :param request:
    :param project_id:
    :return:
    """
    if request.method == 'GET':
        form = WikiModelForm(request)
        return render(request, 'web/wiki_form.html', {'form': form})
    if request.method == 'POST':
        form = WikiModelForm(request, data=request.POST)
        if form.is_valid():
            # 判断是否选择父级文章,如果选择,则depth+1,如果没选择,则forms.instance.depth=1
            if form.instance.parent:
                form.instance.depth = form.instance.parent.depth + 1
            else:
                form.instance.depth = 1
            form.instance.project = request.bug_mgt.project
            form.save()
            url = reverse('wiki', kwargs={'project_id': project_id})
            return redirect(url)
        return render(request, 'web/wiki_form.html', {'form': form})
예제 #15
0
def wiki_edit(request, project_id, wiki_id):
    """ 编辑文章 """
    wiki_object = models.Wiki.objects.filter(project_id=project_id,
                                             id=wiki_id).first()
    if not wiki_object:
        url = reverse("wiki", kwargs={"project_id": project_id})
        return redirect(url)
    if request.method == "GET":
        form = WikiModelForm(request, instance=wiki_object)
        return render(request, "wiki_form.html", {"form": form})

    form = WikiModelForm(request, data=request.POST, instance=wiki_object)
    if form.is_valid():
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth = 1
        form.save()
        url = reverse("wiki", kwargs={"project_id": project_id})
        preview_url = "{0}?wiki_id={1}".format(url, wiki_id)
        return redirect(preview_url)

    return render(request, "wiki_form.html", {"form": form})
예제 #16
0
def wiki_add(request, project_id):
    """wiki添加"""
    # wiki_object = models.Wiki.objects.filter(project_id=project_id).first()
    #
    # if not wiki_object:
    #     url = reverse('wiki', kwargs={'project_id': project_id})
    #     return redirect(url)
    if request.method == 'GET':
        form = WikiModelForm(request)
        return render(request, 'wiki_form.html', {'form': form})
        # return render(request, 'wiki_form.html', {'form': form, 'wiki_object': wiki_object})
    form = WikiModelForm(request, request.POST)
    if form.is_valid():
        if form.instance.parent:
            form.instance.depth = form.instance.parent.depth + 1
        else:
            form.instance.depth = 1

        form.instance.project = request.tracer.project
        form.save()
        url = reverse('wiki', kwargs={'project_id': project_id})
        return redirect(url)
    return render(request, 'wiki_form.html', {'form': form})
예제 #17
0
def wiki_add(request, project_id):
    """wiki添加"""
    if request.method == 'GET':
        form = WikiModelForm(request)

        return render(request, 'web/wiki_form.html', {'form': form})

    if request.method == "POST":
        form = WikiModelForm(request, data=request.POST)

        if form.is_valid():

            # 这部分中需要将depth加入
            if form.instance.parent:  # 若是表单中存在父级,则子集需要深度depth加1
                form.instance.depth = form.instance.parent.depth + 1
            else:  # 不存在父级,直接设置为1
                form.instance.depth = 1

            form.instance.project = request.tracer.project
            form.save()

            return redirect(
                reverse('web:manage:wiki', kwargs={'project_id': project_id}))