Exemple #1
0
def log(r):
    form = ContentForm(r.POST or None, r.FILES or None)
    if r.method == 'POST':
        if form.is_valid():
            f = form.save(commit=False)
            f.user = r.user
            f.save()
            return redirect(log)

    return render(
        r, 'usercontent.html', {
            'con': Content.objects.filter(status='PUBLIC'),
            'add_form': form,
            'all_con': Content.objects.all(),
            'count': Content.objects.all().count(),
        })
Exemple #2
0
def fms_edit(request):

    error = ""
    id = request.GET.get("id")
    if id:
        try:
            user = User.objects.get(username=str(request.user.username))
            content = Content.objects.get(id=id)
            if not user.is_superuser and content.author.username != request.user.username:
                error = "没有权限!"
                form = ""
            else:
                form = ContentForm(instance=content)
                id = id
        except:
            error = "该报告不存在"
            form = ""

    if request.method == "POST":
        content = Content.objects.get(id=id)
        form = ContentForm(request.POST, instance=content)
        if form.is_valid():
            tmp = form.save(commit=False)
            tmp.save()
            return HttpResponseRedirect(reverse('fms_list'))
    return render(request, 'fms/fms_edit.html', {
        'request': request,
        'form': form,
        'error': error,
        'id': id
    })
Exemple #3
0
def fms_edit(request):

    error = ""
    cus_content = None
    zbx_content = None
    id = request.GET.get("id")
    user = MyUser.objects.get(email=request.user.email)
    try:
        cus_content = Content.objects.get(id=id)
    except:
        pass

    try:
        zbx_content = ZbxContent.objects.get(id=id)
    except:
        pass

    content = cus_content or zbx_content

    if content:
        if not user.is_superuser and content.author.username != request.user.username:
            error = "没有权限!"
            form = ""
        else:
            if cus_content:
                form = ContentForm(instance=content)
            else:
                form = ZbxContentForm(instance=content)
            id = id
    else:
        error = "该报告不存在"
        form = ""

    if request.method == "POST":
        if cus_content:
            # content = Content.objects.get(id=id)
            form = ContentForm(request.POST, instance=content)
        else:
            form = ZbxContentForm(request.POST, instance=content)
        print(form)
        # if form.is_valid():
        tmp = form.save(commit=False)
        tmp.save()
        return HttpResponseRedirect(reverse('fms_list'))
    return render(request, 'fms/fms_edit.html', {
        'request': request,
        'form': form,
        'error': error,
        'id': id
    })
Exemple #4
0
def fms_add(request):
    error = ""
    if request.method == "POST":
        title = Content.objects.filter(title=request.POST.get('title'))
        form = ContentForm(request.POST)
        if title:
            error = "简述标题冲突!"
        else:
            if form.is_valid():
                tmp = form.save(commit=False)
                tmp.author = request.user

                tmp.save()
                return HttpResponseRedirect(reverse('fms_list'))
    else:
        form = ContentForm()

    request.breadcrumbs((('首页', '/'), ('故障列表', reverse('fms_list')), ('添加故障', reverse('fms_add'))))
    return render(request, 'fms/fms_add.html', {'request': request, 'form': form, 'error': error})