Esempio n. 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())
Esempio n. 2
0
def tag_list(request):
    jrs = JsonResponse()
    if request.method == "GET":
        tg_obj_list = Tag.objects.all()
        tg_list = []
        for tg_obj in tg_obj_list:
            tg_list.append(tg_obj.name)
        jrs.set_success(0, "ok")
        jrs.data = tg_list
    else:
        name = request.POST.get("name")
        tg = Tag()
        tg.name = name
        tg.save()

        jrs.set_success(0, "ok")
        jrs.id = tg.id
        jrs.name = tg.name
    return HttpResponse(jrs.set_json_pack())