예제 #1
0
def zupu_part(request):
    if request.method == "GET":
        openid = request.GET.get("openid", "")
        page = int(request.GET.get("page", "1"))
        dai = request.GET.get("dai", "")
        dai_obj = models.zupu_level.objects.get(dai=dai)
        user = models.Users.objects.get(openid=openid)
        community = models.Communities.objects.filter(
            myid=user.community_id)[0]
        start_num = (page - 1) * 10
        end_num = (page) * 10
        if func.auth_role(func.role_weight("people"), user.role_weight):
            qs_part = models.zupu_relationship.objects.filter(
                community=community, dai=dai_obj,
                stati__gt=0).order_by("create_time")
            zupu_part = []
            for item in qs_part:
                zupu_part.append(item.short_show())
            res = msg.table("success")
            res["zupu_part"] = zupu_part
            return JsonResponse(res)
    if request.method == "POST":
        info_dict = json.loads(request.body.decode('utf-8'))
        user = models.Users.objects.get(openid=info_dict["openid"])
        del info_dict["openid"]
        if not func.auth_role(func.role_weight("people"), user.role_weight):
            return JsonResponse(msg.table("error"))
        community = models.Communities.objects.filter(
            myid=user.community_id)[0]
        if info_dict["type"] == "new":
            f = models.zupu_relationship.objects.get(myid=info_dict["fid"])
            dai = int(info_dict["dai"])
            dai_obj = models.zupu_level.objects.get(dai=int(dai + 1))

            xh = (models.zupu_relationship.objects.filter(
                community=community, dai=dai_obj, stati__gt=0).count()) + 1
            child = models.zupu_relationship.objects.create(
                myid=number.get_id("zupu"),
                name=info_dict["name"],
                dai=dai_obj,
                community=community,
                parent=f.myid,
                xh=xh)
        elif info_dict["type"] == "edit":
            del info_dict["type"]
            del info_dict["dai"]
            for key, value in info_dict.items():
                qs = models.zupu_relationship.objects.get(myid=key)
                qs.set_name(value)
        elif info_dict["type"] == "del":
            qs = models.zupu_relationship.objects.get(myid=info_dict["myid"])
            qs.change_stati(-1)

        return JsonResponse(msg.table("success"))
    return JsonResponse(msg.table("error"))
예제 #2
0
def m_volunteer(request):
    user = models.Users.objects.get(
        account=request.session["community_username"])
    auth_res = func.auth_role(func.role_weight("leader"), user.role_weight)
    if not auth_res:
        return JsonResponse(msg.table("no_authority"))
    if request.method == "GET":
        type = request.GET.get("type", "")
        flag = request.GET.get("flag", "")
        if type == "edit":
            volunteer_id = request.GET.get("volunteer_id")
            this_volunteer = models.User.objects.get(myid=volunteer_id)
            this_volunteer.role = "people"
            this_volunteer.save()
            return JsonResponse(msg.table("success"))
        else:
            volunteers = models.Users.objects.filter(role="volunteer",
                                                     stati__gt=0,
                                                     valid=1)
            return render(request, 'font/m_volunteer.html', {
                "items": volunteers,
                "flag": flag
            })
    if request.method == "POST":
        info_dict = json.loads(request.body.decode('utf-8'))
        volunteer = models.Users.objects.get(myid=info_dict["myid"])
        if info_dict["flag"] == "volunteer":
            volunteer.delete_role("people", 2)
            return JsonResponse(msg.table("success"))
        if info_dict["flag"] == "leader":
            volunteer.set_role("volunteer", 3)
            return JsonResponse(msg.table("success"))
    return JsonResponse(msg.table("error"))
예제 #3
0
def people_l(request):
    user = models.Users.objects.get(
        account=request.session["community_username"])
    auth_res = func.auth_role(func.role_weight("administrator"),
                              user.role_weight)
    if not auth_res:
        return JsonResponse(msg.table("no_authority"))
    if request.method == "GET":
        flag = request.GET.get("flag", "")
        adm = models.Communities.objects.filter(myid=user.community_id,
                                                stati__gt=0,
                                                valid=1)
        if adm:
            if flag == "volunteer":
                people = models.Users.objects.filter(community_id=adm[0].myid,
                                                     role_weight=3,
                                                     stati__gt=0,
                                                     valid=1)
            elif flag == "leader":
                people = models.Users.objects.filter(community_id=adm[0].myid,
                                                     role_weight=4,
                                                     stati__gt=0,
                                                     valid=1)
            return render(request, 'font/people_l.html', {"items": people})
    elif request.method == "POST":
        return JsonResponse(msg.table("success"))
    return JsonResponse(msg.table("error"))
예제 #4
0
def help_respects(request):
    page_id = int(request.GET.get('page_id'))
    snum = (page_id - 1) * 10
    enum = page_id * 10
    respects = models.Respects.objects.filter(valid=1)[snum:enum]
    po = False
    user = models.Users.objects.get(
        account=request.session['community_username'], valid=1, stati__gt=0)
    if func.auth_role(func.role_weight("leader"), user.role_weight):
        po = True
    return render(request, 'font/help_respects.html', {
        "respects": respects,
        "po": po
    })
예제 #5
0
def xusers(request):
    if request.method == "GET":
        openid = request.GET.get("openid", "0")
        name = request.GET.get("name", "")
        user = models.Users.objects.get(openid=openid)
        if func.auth_role(func.role_weight("people"), user.role_weight):
            community = models.Communities.objects.filter(
                myid=user.community_id)
            zupu_users = models.zupu_relationship.objects.filter(
                name__icontains=name).values('name', "myid")
            res = msg.table("success")
            res["users"] = list(zupu_users)
            return JsonResponse(res)
    return JsonResponse(msg.table("error"))
예제 #6
0
def get_user_info(request):
    openid = request.GET.get("openid", "0")
    user_id = request.GET.get("user_id", "0")
    user = models.Users.objects.get(openid=openid)
    if func.auth_role(func.role_weight("people"), user.role_weight):
        zupu_user = models.zupu_relationship.objects.get(myid=user_id)
        res = msg.table("success")
        if not zupu_user.info:
            res["user_info"] = {"name": zupu_user.name}
            res["dai"] = zupu_user.dai.dai
        else:
            res["user_info"] = zupu_user.info.user_info()
            res["dai"] = zupu_user.dai.dai
        return JsonResponse(res)
    return JsonResponse(msg.table("error"))
예제 #7
0
def zupu_connet(request):
    '''
    族谱关联个人
    :param request: 
    :return: 
    '''
    if request.method == "POST":
        info_dict = json.loads(request.body.decode('utf-8'))
        user = models.Users.objects.get(openid=info_dict["openid"])
        if func.auth_role(func.role_weight("zupu"), user.role_weight):
            zupu_user = models.zupu_relationship.objects.get(
                myid=info_dict["zupu_id"])
            r_user = models.Users.objects.get(myid=info_dict["user_id"])
            qs_user = models.zupu_relationship.objects.filter(info=r_user,
                                                              stati=1)
            if not qs_user:
                zupu_user.connect(r_user)
                return JsonResponse(msg.table("success"))
    return JsonResponse(msg.table("error"))
예제 #8
0
def del_people(request):
    user = models.Users.objects.get(
        account=request.session["community_username"])
    auth_res = func.auth_role(func.role_weight("administrator"),
                              user.role_weight)
    if not auth_res:
        return JsonResponse(msg.table("no_authority"))
    if request.method == "GET":
        adm = models.Communities.objects.filter(myid=user.community_id,
                                                stati__gt=0,
                                                valid=1)
        if adm:
            people = models.Users.objects.filter(community_id=adm[0].myid,
                                                 role_weight__lt=5,
                                                 stati__gt=0,
                                                 valid=1)
            return render(request, 'font/del_people.html', {"items": people})
    elif request.method == "POST":
        info_dict = json.loads(request.body.decode('utf-8'))
        del_people = models.Users.objects.get(myid=info_dict["myid"],
                                              role_weight__lt=5)
        del_people.del_community()
        return JsonResponse(msg.table("success"))
    return JsonResponse(msg.table("error"))
예제 #9
0
def zupu_dai(request):
    '''
    编辑代数
    :param request: 
    :return: 
    '''
    if request.method == "GET":
        openid = request.GET.get("openid", "")
        user = models.Users.objects.get(openid=openid)
        community = models.Communities.objects.filter(myid=user.community_id)
        if not community:
            return JsonResponse(msg.table("error"))
        else:
            community = community[0]
        if func.auth_role(func.role_weight("people"), user.role_weight):
            dai = list(
                models.zupu_level.objects.filter(
                    community=community).order_by("dai"))
            dai_list = []
            for item in dai:
                sub = item.get_subords()
                dai_list.append({
                    "dai": item.dai,
                    "fid": item.myid,
                    "name": item.name,
                    "degs": 0,
                    "subords": sub["subords"]
                })
            res = msg.table("success")
            res["zupu"] = dai_list
            if func.auth_role(func.role_weight("administrator"),
                              user.role_weight):
                res["flag"] = True
            return JsonResponse(res)
        return JsonResponse(msg.table("error"))
    if request.method == "POST":
        info_dict = json.loads(request.body.decode('utf-8'))
        user = models.Users.objects.get(openid=info_dict["openid"])
        community = models.Communities.objects.filter(myid=user.community_id)
        if not community:
            return JsonResponse(msg.table("error"))
        del info_dict["openid"]
        if func.auth_role(func.role_weight("administrator"), user.role_weight):

            for dai, name in info_dict.items():

                qs_dai = models.zupu_level.objects.filter(
                    dai=dai, community=community[0])
                if qs_dai:
                    qs_dai[0].name = name
                    qs_dai[0].save()

                else:
                    dai_o = models.zupu_level.objects.create(
                        myid=number.get_id("dai"),
                        community=community[0],
                        level_key="ddd",
                        dai=dai,
                        name=name,
                        create_person=user)
                    # 初始化孩子
                    if dai == "0":
                        models.zupu_relationship.objects.create(
                            myid=number.get_id("zupu"),
                            name="始祖",
                            dai=dai_o,
                            community=community[0],
                            parent="",
                            xh=0)

            return JsonResponse(msg.table("success"))
    return JsonResponse(msg.table("error"))
예제 #10
0
def edit_product(request):
    user = models.Users.objects.get(
        account=request.session["community_username"])
    if not func.auth_role(func.role_weight("people"), user.role_weight):
        return msg.table("no_authority")

    if request.method == "GET":
        type = request.GET.get("type")
        if type == "del":
            pro_id = request.GET.get("pro_id")
            opr_product = models.Products.objects.get(myid=pro_id)
            opr_product.stati = 0
            opr_product.save()
            return JsonResponse(msg.table("success"))
        elif type == "edit":
            pro_id = request.GET.get("pro_id")
            opr_product = models.Products.objects.get(myid=pro_id)
            return render(request, 'font/edit_product.html', {
                "product": opr_product,
                "type": "edit"
            })
        elif type == "new":
            return render(request, 'font/edit_product.html', {
                "product": {},
                "type": "new"
            })

    elif request.method == "POST":
        type = request.GET.get("type")
        info_dict = json.loads(request.body.decode('utf-8'))
        if data_format.auth(info_dict):
            this_type = models.Product_type.objects.get(
                type_id=info_dict[5]["value"])
            if type == "new":
                models.Products.objects.create(
                    myid=number.get_id("product"),
                    title=info_dict[0]["value"],
                    price=info_dict[1]["value"],
                    unit=info_dict[2]["value"],
                    inventory=info_dict[3]["value"],
                    start_price=info_dict[4]["value"],
                    type=this_type,
                    phone=info_dict[6]["value"],
                    get_type=info_dict[7]["value"],
                    note=info_dict[8]["value"],
                    publish_person=user,
                    community=models.Communities.objects.get(
                        myid=user.community_id))
                return JsonResponse(msg.table("success"))
            elif type == "edit":
                pro_id = request.GET.get("pro_id")
                opr_product = models.Products.objects.get(myid=pro_id)
                opr_product.title = info_dict[0]["value"],
                opr_product.price = info_dict[1]["value"],
                opr_product.unit = info_dict[2]["value"],
                opr_product.inventory = info_dict[3]["value"],
                opr_product.start_price = info_dict[4]["value"],
                opr_product.type = this_type,
                opr_product.phone = info_dict[6]["value"],
                opr_product.get_type = info_dict[7]["value"],
                opr_product.note = info_dict[8]["value"]
                opr_product.save()
                return JsonResponse(msg.table("success"))
    return JsonResponse(msg.table("error"))