Пример #1
0
def create_community(request):
    if request.method == "GET":
        return render(request, 'font/create_community.html')
    if request.method == "POST":
        now_account = request.session["community_username"]
        user = models.Users.objects.get(account=now_account)
        if user.community_id:
            return JsonResponse(msg.table("error"))
        info_dict = json.loads(request.body.decode('utf-8'))
        if now_account != info_dict[3]["value"]:
            JsonResponse(msg.table("wrong_account"))
        if data_format.auth(info_dict):
            user = models.Users.objects.get(account=now_account)
            community = models.Communities.objects.filter(create_person=user,
                                                          valid=1)
            name_repeat = models.Communities.objects.filter(
                name=info_dict[0]["value"], valid=1)
            if not community and not name_repeat:
                res = models.Communities.objects.create(
                    myid=number.get_id("community"),
                    create_person=user,
                    name=info_dict[0]["value"],
                    administrator=user,
                    province=info_dict[1]["value"],
                    address=info_dict[2]["value"],
                    in_code=number.get_id("in_code"))
                user.set_community_id(id=res.myid)
                user.set_role("administrator", 5)
                user.save()
                return JsonResponse(msg.table("success"))
            else:
                return JsonResponse(msg.table("repeat"))

    return JsonResponse(msg.table("error"))
Пример #2
0
def add_respect(request):
    if request.method == "POST":
        info_dict = json.loads(request.body.decode('utf-8'))
        publish_person = models.Users.objects.get(
            account=request.session.get("community_username"), valid=1)
        community = models.Communities.objects.get(
            myid=publish_person.community_id, valid=1)
        res = models.Respects.objects.create(
            myid=number.get_id("respect"),
            name=info_dict["name"],
            age=info_dict["age"],
            gender=info_dict["gender"],
            single=info_dict["single"],
            live_situation=info_dict["live_situation"],
            health_situation=info_dict["health_situation"],
            phone=info_dict["phone"],
            families=info_dict["families"],
            note=info_dict["note"],
            address=info_dict["address"],
            hobby=info_dict["hobby"],
            avatar='images/respect5.jpg',
            # families=families
            publish_person=publish_person,
            community=community)
        if res:
            return JsonResponse(msg.table("success"))
        else:
            return JsonResponse(msg.table("error"))
    elif request.method == "GET":
        aRespect = {}
        return render(request, 'font/add_respect.html', {"aRespect": aRespect})
    return render(request, 'font/add_respect.html')
Пример #3
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"))
Пример #4
0
def init_data(request):
    '''初始数据,用于测试
    :param request:
    :return msg:
    '''
    for item in range(0, 10):
        res = models.Users.objects.create(
            myid=number.get_id("user"),
            account="1588992350" + str(item),
            password="******")
    return JsonResponse(msg.table("success"))
Пример #5
0
def phone_code(request):
    '''
    验证码
    :param request:
    :return msg: 状态信息
    '''
    if request.method == "POST":
        info_dict = json.loads(request.body.decode('utf-8'))
        if len(info_dict["account"]) == 11:
            code = number.get_id("phone_code")
            request.session["phone_code"] = code
            send_sms(info_dict["account"], code)
            return JsonResponse(msg.table("success"))
    return JsonResponse(msg.table("error"))
Пример #6
0
def mycommunity(request):
    '''
    我的社区
    :param request: 
    :return: 
    '''
    now_account = request.session["community_username"]
    if request.method == "GET":
        user = models.Users.objects.get(account=now_account, valid=1)
        mycommunity = models.Communities.objects.get(myid=user.community_id)
        people = models.Users.objects.filter(community_id=user.community_id)
        return render(request, 'font/mycommunity.html', {
            "mycommunity": mycommunity,
            "people": people
        })
    if request.method == "POST":
        info_dict = json.loads(request.body.decode('utf-8'))
        if now_account != info_dict[1]["value"]:
            JsonResponse(msg.table("wrong_account"))
        if data_format.auth(info_dict):
            user = models.Users.objects.get(account=now_account)
            community = models.Communities.objects.fillter(create_person=user,
                                                           valid=1)
            name_repeat = models.Communities.objects.fillter(
                name=info_dict[0]["value"], valid=1)
            if not community and not name_repeat:
                res = ""
                res = models.Communities.objects.create(
                    create_person=user,
                    name=info_dict[0]["value"],
                    administrator=user,
                    province=info_dict[1]["value"],
                    address=info_dict[2]["value"],
                    in_code=number.get_id("in_code"),
                )
                if not res:
                    JsonResponse(msg.table("success"))
            return JsonResponse(msg.table("repeat"))
    return JsonResponse(msg.table("error"))
Пример #7
0
def register(request):
    if request.method == "POST":
        info_dict = json.loads(request.body.decode('utf-8'))
        if info_dict["captcha"] != request.session["phone_code"]:
            return JsonResponse(msg.table("error_code"))
        user = models.Users.objects.filter(account=info_dict["username"],
                                           valid=1)

        if not user:
            password = encrype.password(info_dict["password"])
            res = models.Users.objects.create(myid=number.get_id("user"),
                                              account=info_dict["username"],
                                              password=password)
            # 记住我
            # if info_dict["remember"]:
            #     request.session.set_expiry(50000)
            return JsonResponse(msg.table("success"))
        else:
            return JsonResponse(msg.table("repeat"))
    elif request.method == "GET":
        return render(request, 'font/register.html')
    return JsonResponse(msg.table("error"))
Пример #8
0
def add_activity_d(request):
    if request.method == "GET":
        return render(request, 'font/add_activity_d.html')
    elif request.method == "POST":
        user = models.Users.objects.get(
            account=request.session["community_username"], valid=1)
        community = models.Communities.objects.get(myid=user.community_id,
                                                   valid=1)
        info_dict = json.loads(request.body.decode('utf-8'))
        models.Volun_activity.objects.create(
            myid=number.get_id("volun_activity"),
            title=info_dict["title"],
            description=info_dict["description"],
            need_number=info_dict["need_people"],
            # start_time = info_dict["start_time"],
            # end_time = info_dict["start_time"],
            # deadline=info_dict["deadline"],
            plan=info_dict["plan"],
            create_person=user,
            leader=user,
            community=community,
        )
        return JsonResponse(msg.table("success"))
Пример #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"))
Пример #11
0
def model_data():
    #User:
    user = models.Users.objects.create(myid=number.get_id("user"),
                                       name="Victroy",
                                       community_id="",
                                       age=20,
                                       gender=1,
                                       occupation="学生",
                                       specialty="打代码",
                                       content="我是一个好女孩",
                                       contact="18293876721",
                                       create_time=now_time,
                                       vatara="images/smile.jpg")

    # Communities
    community = models.Communities.objects.create(
        myid=number.get_id("community"),
        name="社区1",
        address="xx省xx市",
        administrator=user,
        deadline=now_time,
        create_time=now_time,
        create_person=user,
        province="广东肇庆")

    #Volunteers
    volunteer = models.Volunteers.objects.create(user_info=user,
                                                 create_time=now_time,
                                                 activtiy="")

    #ProductType
    product_type = models.Product_type.objects.create(
        myid=number.get_id("product_type"), type_name="肉类", type_id=2001)

    # Products(models.Model):
    product = models.Products.objects.create(myid=number.get_id("product"),
                                             title="本地土鸡",
                                             price=20.01,
                                             unit="只",
                                             inventory=20,
                                             start_price=10.01,
                                             type=product_type,
                                             contact="78932786122",
                                             contact_type="手机联系",
                                             note="",
                                             publish_person=user,
                                             community=community)

    # Respects
    respect = models.Respects.objects.create(myid=number.get_id("respect"),
                                             publish_person=user,
                                             name="老人1",
                                             community=community,
                                             age=88,
                                             gender=1,
                                             live_situation="夫妻居住",
                                             health_situation="身体良好",
                                             address="xx镇",
                                             hobby="",
                                             phone="28937465321",
                                             families="",
                                             family_call="89374856321",
                                             note="",
                                             create_time=now_time)

    #volun_leader
    volun_leader = models.Volun_leader.objects.create(user_info=user,
                                                      add_person=user,
                                                      create_time=now_time)

    #Volun_activity
    volun_activity = models.Volun_activity.objects.create(
        myid=number.get_id("volun_activity"),
        title="共度重阳",
        create_time=now_time,
        start_time=now_time,
        end_time=now_time,
        create_person=volun_leader,
        leader=volun_leader,
        description="",
        img="images/spellGroup.jpg",
        plan="计划1",
        community=community)

    #VolunActivityD
    volun_activity_d = models.Volun_activity_d.objects.create(
        activity=volun_activity,
        user_info=user,
        create_time=now_time,
        reason="原因1",
        job="后勤",
        my_start_time=now_time,
        my_end_time=now_time)
    #activity_respect
    activity_respect = models.Activty_respects.objects.create(
        activity=volun_activity, respect=respect)
    #administrator
    # administrator=models.administrator.objects.create(
    #     myid = user,
    #     create_time = now_time,
    #     phone = "83943434332",
    #     community_id = "2001"
    # )

    #Family
    family = models.Family.objects.create(user_info=user,
                                          community=community,
                                          dai_number=2,
                                          married=1,
                                          mate="xxx",
                                          parent="")

    #Authority
    authority = models.Authority.objects.create(
        myid=number.get_id("authority"), title="编辑")

    #Role
    role = models.Role.objects.create(myid=number.get_id("role"),
                                      authority="001,002",
                                      title="管理员")

    #Images
    image = models.Images.objects.create(url="images/mouse.jpg",
                                         title="本地鸡",
                                         type="proMain",
                                         product=product)