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())
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())
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())