Esempio n. 1
0
def add_forum(request):
    """
    新增帖子
    :param request:
    :return:
    """
    category = Forum_plate.objects.all()
    seo_list = get_object_or_404(Seo, name='社区论坛')
    if request.method == 'POST':
        form = Forum_form(request.POST)
        if form.is_valid():
            forum = Forum()
            forum.title = form.cleaned_data.get('title')
            forum.category_id = form.cleaned_data.get('category')
            forum.keywords = request.POST.get('keywords')
            forum.content = form.cleaned_data.get('content')
            forum.authors = form.cleaned_data.get('authors')
            try:
                forum.save()
                return JsonResponse({"code": 200, "data": "发布成功"})
            except Exception as e:
                return JsonResponse({"code": 400, "data": "发布失败"})
        pattern = re.compile(r'<[^>]+>', re.S)
        result = pattern.sub("", str(form.errors))
        return JsonResponse({"code": 400, "data": result})
    return render(request,'pc/forum_add.html',locals())
Esempio n. 2
0
def update_forum(request, forum_id):
    if request.method == 'GET':
        item = get_object_or_404(Forum, pk=forum_id)
        plate = Forum_plate.objects.all()
        seos = get_object_or_404(Seo, name='社区论坛')
        return render(request, 'pc/forum_update.html', {
            'plate': plate,
            'seos': seos,
            'forum': item
        })
    elif request.method == 'POST':
        form = Forum_form(request.POST)
        if form.is_valid():
            forum = get_object_or_404(Forum, pk=forum_id)
            forum.title = form.cleaned_data.get('title')
            forum.category_id = form.cleaned_data.get('category')
            forum.keywords = request.POST.get('keywords')
            forum.content = form.cleaned_data.get('content')
            forum.authors = form.cleaned_data.get('authors')
            try:
                forum.save()
                return JsonResponse({"code": 200, "data": "修改成功"})
            except Exception:
                return JsonResponse({"code": 400, "data": "修改失败"})
        else:
            pattern = re.compile(r'<[^>]+>', re.S)
            result = pattern.sub("", str(form.errors))
            return JsonResponse({"code": 400, "data": result})
Esempio n. 3
0
def add_forum(request):
    """
    新增帖子
    :param request:
    :return:
    """
    category = Forum_plate.objects.all()
    if request.method == 'POST':
        form = Forum_form(request.POST)
        if form.is_valid():
            forum = Forum()
            forum.title = form.cleaned_data.get('title')
            forum.category_id = form.cleaned_data.get('category')
            forum.keywords = form.cleaned_data.get('keywords')
            forum.content = form.cleaned_data.get('content')
            forum.authors = form.cleaned_data.get('authors')
            try:
                forum.save()
                return JsonResponse({"code": 200, "data": "发布成功"})
            except Exception:
                return JsonResponse({"code": 400, "data": "发布失败"})
    return render(request,'pc/forum_add.html',locals())