Example #1
0
def kind_list(request):
    jrs = JsonResponse()
    if request.method == "POST":
        name = request.POST.get("name").strip()
        alias = request.POST.get('alias').strip()
        introdution = request.POST.get("introdution").strip()
        if not alias:
            alias = name

        try:
            bk = BlogKind()
            bk.name = name
            bk.alias = alias
            bk.introdution = introdution
            bk.create_date = datetime.datetime.now()
            bk.save()
            jrs.set_success(0, "ok")
            jrs.url = "/blog-backend/display-blog-list/"
            jrs.id = bk.id
            jrs.name = bk.name
        except:
            jrs.set_error(300, "create failure")
    else:  # GET
        bk_obj_list = BlogKind.objects.all()
        bk_list = []
        for bk_obj in bk_obj_list:
            bk_list.append(bk_obj.name)
        jrs.set_success(0, "ok")
        jrs.data = bk_list
    return HttpResponse(jrs.set_json_pack())
Example #2
0
def tag_verify(request):
    name = request.POST.get("name")

    tg = Tag.objects.filter(name=name)
    jrs = JsonResponse()
    if tg or not name:
        jrs.set_error(300, "error")
    else:
        jrs.set_success(0, "ok")

    return HttpResponse(jrs.set_json_pack())
Example #3
0
def blog_title_verify(request):
    typ = request.POST.get("typ")
    value = request.POST.get("value")

    jrs = JsonResponse()
    if typ == "normal":
        if not value:
            jrs.set_error(300, "error")
        else:
            try:
                bl = BlogList.objects.get(title=value)
            except:
                jrs.set_success(0, "ok")

            else:
                jrs.set_error(300, "error")

    elif typ == "markdown":
        try:
            bl = BlogList.objects.get(title=value)
        except:
            jrs.set_success(0, "ok")
        else:
            jrs.set_error(300, "error")
    else:
        jrs.set_error(300, "error")
    return HttpResponse(jrs.set_json_pack())
Example #4
0
def kind_verify(request):
    field = request.POST.get("verify_field").strip()
    value = request.POST.get("value").strip()
    jrs = JsonResponse()
    if field == "name":
        if not value:
            jrs.set_error(300, "repeated")
        else:
            try:
                BlogKind.objects.get(name=value)
            except:
                jrs.set_success(0, "ok")
            else:
                jrs.set_error(300, "repeated")
    elif field == "alias":
        if value:
            try:
                BlogKind.objects.get(alias=value)
            except:
                jrs.set_success(0, "ok")
            else:
                jrs.set_error(300, "repeated")
        else:
            print("none")
            jrs.set_success(0, "ok")

    else:
        jrs.set_error(300, "repeated")
    return HttpResponse(jrs.set_json_pack())
Example #5
0
def get_blog_message(request):
    jrs = JsonResponse()
    blog_id = request.GET.get("id")

    if blog_id:
        bl_obj = BlogList.objects.filter(id=blog_id).first()
        if bl_obj:
            jrs.set_success(0, "ok")
            jrs.title = bl_obj.title
            jrs.content = bl_obj.blog_content
            jrs.kind_id = bl_obj.blog_kind_id
            jrs.tag_id_list = [str(tag.id) for tag in bl_obj.tag.all()]
            if jrs.tag_id_list:
                jrs.tag_id_list = ",".join(jrs.tag_id_list)
            return HttpResponse(jrs.set_json_pack())

    jrs.set_error(300, "error")
    return HttpResponse(jrs.set_json_pack())
Example #6
0
def blog_view(request):
    """
    display blog view
    1, list->view
    2, editing->cache file->view
    """
    if request.method == "POST":
        title = request.POST.get("title")
        blog_content = request.POST.get("blog_content")
        blog_kind_id = request.POST.get("blog_kind_id")
        tag_id_list = request.post.get("tag_id_list")
        jrs = JsonResponse()
        jrs.set_error(0, "error")
        return redirect("/blog-backend/blog-view/?from=cache")
    else:
        blog_id = request.GET.get("id")
        bl_obj = BlogList.objects.get(id=blog_id)
        tag_list = bl_obj.tag.all()
        return render(request, "blog_backend/blog_view.html", locals())
Example #7
0
def verify_related(request):
    """
    verify that blog kind or blog tag is related the blog
    typ: 
    k_b kind to blog, search kind-name探した上に、逆にブロックリストへ探す、探さなければ、異常を捨てる
    t_b tag to blog
    """
    jrs = JsonResponse()
    typ = request.POST.get("typ")
    name_list = request.POST.get("name_list")

    namelist = json.loads(name_list)
    for name in namelist:

        if typ == "k_b":
            try:
                bk_obj = BlogKind.objects.get(name=name)
                bl_li_co = bk_obj.bloglist_set.all().count()
                if bl_li_co == 0:
                    continue

                else:
                    jrs.set_success(
                        1,
                        "the kind's relateds is having some blogs, can't delete"
                    )
                    jrs.name = name
            except:
                jrs.set_error(300, "didn't find out the kind name")

        elif typ == "t_b":
            try:
                tg_obj = Tag.objects.get(name=name)
                bl_li_co = tg_obj.bloglist_set.all().count()
                if bl_li_co == 0:
                    continue
                else:
                    jrs.set_success(
                        1,
                        "the tag's relateds is having some blogs, can't delete"
                    )
                    jrs.name = name
            except:
                jrs.set_error(300, "didn't find out the tag name")
        else:
            jrs.set_error(300, "didn't find out the name")

        return HttpResponse(jrs.set_json_pack())

    jrs.set_success(0, "the kind's relateds is never, can delete")
    return HttpResponse(jrs.set_json_pack())