예제 #1
0
def list_nodefalse(request, current_user):
    if request.META['REQUEST_METHOD'] == 'GET':
        realestatenodes = Realestatenode.objects.filter(
            userid=current_user.id,
            status=True,
            timefrom__gte=datetime.datetime.now(),
            typenode=True).order_by('timecreate')
        serialized = []
        if realestatenodes:
            serializer = RealestatenodeSerializer(realestatenodes, many=True)
            serializer = serializer.data
            for s in serializer:
                serialized.append(s)

        realestates = Realestatenode.objects.filter(
            userid=current_user.id,
            status=True,
            timeto__lte=datetime.datetime.now(),
            typenode=True).order_by('timecreate')
        if realestates:
            serializer = RealestatenodeSerializer(realestates, many=True)
            serializer = serializer.data
            for s in serializer:
                serialized.append(s)

        return JsonResponse({'data': serialized, 'status': 'success'})
예제 #2
0
def detail_node(request, current_user, node_id):
    try:
        realestatenode = Realestatenode.objects.get(id=node_id,
                                                    userid=current_user.id)
    except:
        return JsonResponse({
            'data': 'Không tìm thấy bài đăng',
            'status': 'error'
        })

    if request.method == 'PUT':
        data = json.loads(json.dumps(request.data))
        data['id'] = node_id
        data['title'] = realestatenode.title
        data['latitude'] = realestatenode.latitude
        data['longitude'] = realestatenode.longitude
        data['area'] = realestatenode.area
        data['tinh'] = realestatenode.tinh
        data['huyen'] = realestatenode.huyen
        data['xa'] = realestatenode.xa
        data['duong'] = realestatenode.duong
        data['details_address'] = realestatenode.details_address
        data['address'] = realestatenode.address
        data['huong'] = realestatenode.huong
        data['sophongngu'] = realestatenode.sophongngu
        data['tang'] = realestatenode.tang
        data['sotang'] = realestatenode.sotang
        data['rongtien'] = realestatenode.rongtien
        data['rongduong'] = realestatenode.rongduong
        data['status'] = realestatenode.status
        data['tenduan'] = realestatenode.tenduan
        data['tenlienhe'] = realestatenode.tenlienhe
        data['diachi'] = realestatenode.diachi
        data['dienthoai'] = realestatenode.dienthoai
        data['email'] = realestatenode.email
        data['rank'] = realestatenode.rank
        data['timefrom'] = realestatenode.timefrom
        data['timeto'] = realestatenode.timeto
        data['typenode'] = realestatenode.typenode
        data['vip'] = realestatenode.vip
        data['modname'] = realestatenode.modname
        data['timecreate'] = realestatenode.timecreate
        data['timemodify'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        data['duanid'] = realestatenode.duanid
        data['modid'] = realestatenode.modid
        data['type'] = realestatenode.type
        data['userid'] = realestatenode.userid

        serializer = RealestatenodeSerializer(realestatenode, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse({'data': serializer.data, 'status': 'success'})
        else:
            return JsonResponse({
                'data':
                'Lỗi hệ thống! Vui lòng liên hệ với quản trị viên để được hỗ trợ sớm nhất!',
                'status': 'error'
            })
예제 #3
0
def dangbaitimkiem(request, current_user):
    if request.method == 'POST':
        data = json.loads(json.dumps(request.data))

        #sinh id
        list_id = Realestatenode.objects.all().values_list('id', flat=True)
        data['id'] = str(uuid.uuid4().get_hex().upper()[0:20])
        while data['id'] in list_id:
            data['id'] = str(uuid.uuid4().get_hex().upper()[0:20])

        data['typenode'] = True
        data['latitude'] = 0
        data['longitude'] = 0
        data['userid'] = current_user.id

        data['status'] = False
        data['rank'] = 0
        data['vip'] = 0
        data['modname'] = ''
        data['modid'] = ''

        data['timecreate'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        data['timemodify'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        data['timefrom'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        data['timeto'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        data['tenlienhe'] = current_user.name
        data['diachi'] = current_user.address
        data['dienthoai'] = current_user.phone
        data['email'] = current_user.email

        data['thumbs'] = ''
        data['video'] = ''
        data['anh360'] = ''
        data['panorama_image'] = ''

        serializer = RealestatenodeSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse({'status': 'success'})
        else:
            return JsonResponse({'data': serializer.errors, 'status': 'error'})
    else:
        return JsonResponse({
            'data':
            'Lỗi hệ thống! Vui lòng liên hệ với quản trị viên để được hỗ trợ sớm nhất!',
            'status': 'error'
        })
예제 #4
0
def list_nodefalse(request, current_smod):
    if request.META['REQUEST_METHOD'] == 'GET':
        realestatenodes = Realestatenode.objects.filter(status=False)
        if realestatenodes:
            serializer = RealestatenodeSerializer(realestatenodes, many=True)
            return JsonResponse({'data': serializer.data})
        return JsonResponse({'data': []})
예제 #5
0
def allnode(request, current_smod):
    if request.META['REQUEST_METHOD'] == 'GET':
        ktra = Mod.objects.filter(type=current_smod.id)
        realestatenodes = Realestatenode.objects.filter(modid__in=ktra)
        if realestatenodes:
            serializer = RealestatenodeSerializer(realestatenodes, many=True)
            return JsonResponse({'data': serializer.data})
        return JsonResponse({'data': []})
예제 #6
0
def allnode(request, current_user):
    if request.META['REQUEST_METHOD'] == 'GET':
        realestatenodes = Realestatenode.objects.filter(
            status=True).order_by('rank')
        if realestatenodes:
            serializer = RealestatenodeSerializer(realestatenodes, many=True)
            return Response(serializer.data)
        return JsonResponse({'message': 'No Node!!!'})
예제 #7
0
def danhsachtimkiem(request, current_user):
    if request.method == 'GET':
        data = json.loads(json.dumps(request.data))
        nodes = Realestatenode.objects.filter(
            status=True, typenode=False,
            userid=current_user.id).order_by('-timecreate')
        serializer = RealestatenodeSerializer(nodes, many=True)
        return JsonResponse({'data': serializer.data, 'status': 'success'})
예제 #8
0
def detail_node(request, current_smod, node_id):
    try:
        realestatenode = Realestatenode.objects.get(id=node_id)
    except:
        return JsonResponse({'data': []})

    if request.method == 'GET':
        serializer = RealestatenodeSerializer(realestatenode)
        return JsonResponse({'data': serializer.data})

    if request.method == 'PUT':
        data = json.loads(json.dumps(request.data))

        mod = Mod.objects.filter(id=realestatenode.modid,
                                 rank=False,
                                 type=current_smod)
        if not mod:
            return JsonResponse({"data": []})

        serializer = RealestatenodeSerializer(realestatenode, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse({"data": serializer.data})
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        realestatenode.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
예제 #9
0
def detail_node(request, current_mod, node_id):
    try:
        realestatenode = Realestatenode.objects.get(id=node_id,
                                                    modid=current_mod.id)
    except:
        return JsonResponse({'message': 'Not found!!!'})

    if request.method == 'GET':
        serializer = RealestatenodeSerializer(realestatenode)
        return Response({'data': serializer.data})

    if request.method == 'PUT':
        data = json.loads(json.dumps(request.data))

        if realestatenode.modid != current_mod.id:
            return JsonResponse({"data": []})

        data['id'] = node_id
        data['modid'] = realestatenode.modid
        data['timemodify'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')

        serializer = RealestatenodeSerializer(realestatenode, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse({"data": serializer.data})
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        realestatenode.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
예제 #10
0
def list_nodewait(request, current_user):
    if request.META['REQUEST_METHOD'] == 'GET':
        realestatenodes = Realestatenode.objects.filter(
            userid=current_user.id, status=False,
            typenode=True).order_by('timecreate')
        if realestatenodes:
            serializer = RealestatenodeSerializer(realestatenodes, many=True)
            return JsonResponse({'data': serializer.data, 'status': 'success'})
        return JsonResponse({'data': [], 'status': 'success'})
예제 #11
0
def list_node(request, current_smod):
    if request.META['REQUEST_METHOD'] == 'GET':
        realestatenodes = Realestatenode.objects.all()
        if realestatenodes:
            serializer = RealestatenodeSerializer(realestatenodes, many=True)
            return JsonResponse({'data': serializer.data})
        return JsonResponse({'data': []})

    if request.method == 'POST':
        data = json.loads(json.dumps(request.data))

        #sinh id
        list_id = Realestatenode.objects.all().values_list('id', flat=True)
        data['id'] = str(uuid.uuid4().get_hex().upper()[0:20])
        while data['id'] in list_id:
            data['id'] = str(uuid.uuid4().get_hex().upper()[0:20])

        mod = Mod.objects.filter(id=data['modid'],
                                 rank=False,
                                 type=current_smod.id)
        if not mod:
            return JsonResponse({"data": []})

        data['status'] = False
        data['coin'] = 0
        data['rank'] = data['rank']
        data['timefrom'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        data['timemodify'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        data['timecreate'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')

        serializer = RealestatenodeSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
예제 #12
0
def confirm_node(request, current_smod):
    data = json.loads(json.dumps(request.data))
    try:
        ktra = Mod.objects.filter(type=current_smod.id)
        realestatenode = Realestatenode.objects.get(
            id=data['realestatenode_id'], modid__in=ktra, status=False)
    except:
        return JsonResponse({'message': 'Not result!!!'})

    current_user = User.objects.get(id=realestatenode.userid)

    coin = Coin.objects.get(vip=realestatenode.vip)
    realcoins = coin.coin * (realestatenode.timeto -
                             realestatenode.timefrom).days
    if current_user.coin < realcoins:
        return JsonResponse({'data': 'Khong du coin'})

    if request.method == 'PUT':
        data['id'] = realestatenode.id
        data['title'] = realestatenode.title
        data['latitude'] = realestatenode.latitude
        data['longitude'] = realestatenode.longitude
        data['price'] = realestatenode.price
        data['pricem2'] = realestatenode.pricem2
        data['area'] = realestatenode.area
        data['tinh'] = realestatenode.tinh
        data['huyen'] = realestatenode.huyen
        data['xa'] = realestatenode.xa
        data['duong'] = realestatenode.duong
        data['details_address'] = realestatenode.details_address
        data['address'] = realestatenode.address
        data['huong'] = realestatenode.huong
        data['sophongngu'] = realestatenode.sophongngu
        data['tang'] = realestatenode.tang
        data['sotang'] = realestatenode.sotang
        data['rongtien'] = realestatenode.rongtien
        data['rongduong'] = realestatenode.rongduong
        data['details'] = realestatenode.details
        data['status'] = True
        data['thumbs'] = realestatenode.thumbs
        data['anh360'] = realestatenode.anh360
        data['panorama_image'] = realestatenode.panorama_image
        data['video'] = realestatenode.video
        data['tenduan'] = realestatenode.tenduan
        data['tenlienhe'] = realestatenode.tenlienhe
        data['diachi'] = realestatenode.diachi
        data['dienthoai'] = realestatenode.dienthoai
        data['email'] = realestatenode.email
        data['rank'] = realestatenode.rank
        data['timefrom'] = realestatenode.timefrom
        data['timeto'] = realestatenode.timeto
        data['typenode'] = realestatenode.typenode
        data['vip'] = realestatenode.vip
        data['modname'] = realestatenode.modname
        data['timecreate'] = realestatenode.timecreate
        data['timemodify'] = realestatenode.timemodify
        data['duanid'] = realestatenode.duanid
        data['modid'] = realestatenode.modid
        data['type'] = realestatenode.type
        data['userid'] = realestatenode.userid

        serializer = RealestatenodeSerializer(realestatenode, data=data)
        if serializer.is_valid():
            serializer.save()
            data['id'] = current_user.id
            data['username'] = current_user.username
            data['password'] = current_user.password
            data['name'] = current_user.name
            data['email'] = current_user.email
            data['phone'] = current_user.phone
            data['address'] = current_user.address
            data['company'] = current_user.company
            data['sex'] = current_user.sex
            data['birthday'] = current_user.birthday
            data['coin'] = int(current_user.coin) - realcoins
            data['avatar'] = current_user.avatar
            data['status'] = current_user.status
            data['rank'] = current_user.rank
            data['details'] = current_user.details
            data['social'] = current_user.social

            serializer = UserSerializer(current_user, data=data)
            if serializer.is_valid():
                serializer.save()
                return JsonResponse({'message': 'OK'})
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
예제 #13
0
def postagain(request, current_user, node_id):
    if request.method == 'POST':
        data = json.loads(json.dumps(request.data))
        realestatenode = Realestatenode.objects.get(id=node_id,
                                                    userid=current_user.id)
        if not realestatenode:
            return JsonResponse({'data': []})

        #Tinh gia data['vip']
        coin = Coin.objects.get(vip=data['vip'])

        timef = datetime.datetime.strptime(data['timefrom'],
                                           '%Y-%m-%d %H:%M:%S')
        timet = datetime.datetime.strptime(data['timeto'], '%Y-%m-%d %H:%M:%S')

        if (timet - timef).days <= 0 or (timet -
                                         realestatenode.timeto).days <= 0:
            return JsonResponse({'data': 'Sai thoi gian'})

        if (timef - realestatenode.timeto).days > 0:
            realcoins = coin.coin * (timet - timef).days
        else:
            realcoins = coin.coin * (timet - realestatenode.timeto).days

        if current_user.coin < realcoins:
            return JsonResponse({'data': 'Khong du coin'})

        data['id'] = realestatenode.id
        data['title'] = realestatenode.title
        data['latitude'] = realestatenode.latitude
        data['longitude'] = realestatenode.longitude
        data['price'] = realestatenode.price
        data['pricem2'] = realestatenode.pricem2
        data['area'] = realestatenode.area
        data['tinh'] = realestatenode.tinh
        data['huyen'] = realestatenode.huyen
        data['xa'] = realestatenode.xa
        data['duong'] = realestatenode.duong
        data['details_address'] = realestatenode.details_address
        data['address'] = realestatenode.address
        data['huong'] = realestatenode.huong
        data['sophongngu'] = realestatenode.sophongngu
        data['tang'] = realestatenode.tang
        data['sotang'] = realestatenode.sotang
        data['rongtien'] = realestatenode.rongtien
        data['rongduong'] = realestatenode.rongduong
        data['details'] = realestatenode.details
        data['status'] = realestatenode.status
        data['thumbs'] = realestatenode.thumbs
        data['anh360'] = realestatenode.anh360
        data['panorama_image'] = realestatenode.panorama_image
        data['video'] = realestatenode.video
        data['tenduan'] = realestatenode.tenduan
        data['tenlienhe'] = realestatenode.tenlienhe
        data['diachi'] = realestatenode.diachi
        data['dienthoai'] = realestatenode.dienthoai
        data['email'] = realestatenode.email
        data['rank'] = realestatenode.rank
        data['typenode'] = realestatenode.typenode
        data['modname'] = realestatenode.modname
        data['timecreate'] = realestatenode.timecreate
        data['timemodify'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        data['duanid'] = realestatenode.duanid
        data['modid'] = realestatenode.modid
        data['type'] = realestatenode.type
        data['userid'] = realestatenode.userid

        serializer = RealestatenodeSerializer(realestatenode, data=data)
        if serializer.is_valid():
            serializer.save()
            data = {}
            data['id'] = current_user.id
            data['username'] = current_user.username
            data['password'] = current_user.password
            data['name'] = current_user.name
            data['email'] = current_user.email
            data['phone'] = current_user.phone
            data['address'] = current_user.address
            data['company'] = current_user.company
            data['details'] = current_user.details
            data['sex'] = current_user.sex
            data['birthday'] = current_user.birthday
            data['coin'] = int(current_user.coin) - realcoins
            data['avatar'] = current_user.avatar
            data['status'] = current_user.status
            data['rank'] = current_user.rank
            data['social'] = current_user.social
            serializer = UserSerializer(current_user, data=data)
            if serializer.is_valid():
                serializer.save()
                return JsonResponse({'data': 'OK'})
        return JsonResponse({'data': 'error'})
예제 #14
0
def list_node(request, current_user):
    if request.META['REQUEST_METHOD'] == 'GET':
        realestatenodes = Realestatenode.objects.filter(
            userid=current_user.id,
            status=True,
            timefrom__lte=datetime.datetime.now(),
            timeto__gte=datetime.datetime.now(),
            typenode=True).order_by('timecreate')
        if realestatenodes:
            serializer = RealestatenodeSerializer(realestatenodes, many=True)
            return JsonResponse({'data': serializer.data, 'status': 'success'})
        return JsonResponse({'data': [], 'status': 'success'})

    # Dang bai moi
    if request.method == 'POST':
        data = json.loads(json.dumps(request.data))

        #sinh id
        list_id = Realestatenode.objects.all().values_list('id', flat=True)
        data['id'] = str(uuid.uuid4().get_hex().upper()[0:20])
        while data['id'] in list_id:
            data['id'] = str(uuid.uuid4().get_hex().upper()[0:20])

        data['userid'] = current_user.id
        data['status'] = False
        data['rank'] = 0
        data['timecreate'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        data['timemodify'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')

        #Kiem tra timefrom va timeto.
        timef = datetime.datetime.strptime(data['timefrom'],
                                           '%Y-%m-%d %H:%M:%S')
        timet = datetime.datetime.strptime(data['timeto'], '%Y-%m-%d %H:%M:%S')
        if ((timet - datetime.datetime.now()).days <= 0) or (
            (timet - timef).days <= 0):
            return JsonResponse({'data': 'Thời gian sai', 'status': 'error'})

        #kiem tra coin
        coin = Coin.objects.get(vip=data['vip'])
        realcoins = coin.coin * (timet - timef).days
        if current_user.coin < realcoins:
            return JsonResponse({'data': 'Không đủ coin', 'status': 'error'})

        #Phan chia khu vuc cho mod
        duanid = ''
        if data['duanid'] != '':
            duanid = Duan.objects.get(id=data['duanid'])
        if duanid != '':  #node thuoc duan
            list_duanid = Duan.objects.filter(status=True).values_list(
                'id', flat=True)
            if duanid.id not in list_duanid:
                return JsonResponse({
                    'data':
                    'Lỗi hệ thống! Vui lòng liên hệ với quản trị viên để được hỗ trợ sớm nhất!',
                    'status': 'error'
                })

            data['rongtien'] = 0
            data['rongduong'] = 0
            data['latitude'] = duanid.latitude
            data['longitude'] = duanid.longitude

            data['modid'] = str(
                phanchiamodduan(duanid.id, duanid.tinh, duanid.huyen))
        else:  #node rieng
            data['modid'] = '16B651'
            #data['modid'] = str(phanchiamod(indexdpro(data['tinh']),indexd(data['tinh'], data['huyen'])))
            #if data['modid'] == "":
            #    return JsonResponse({'data': 'Lỗi hệ thống! Vui lòng liên hệ với quản trị viên để được hỗ trợ sớm nhất!', 'status': 'error'})

        serializer = RealestatenodeSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse({'status': 'success'})
        else:
            return JsonResponse({
                'data':
                'Lỗi hệ thống! Vui lòng liên hệ với quản trị viên để được hỗ trợ sớm nhất!',
                'status': 'error'
            })
    else:
        return JsonResponse({
            'data':
            'Lỗi hệ thống! Vui lòng liên hệ với quản trị viên để được hỗ trợ sớm nhất!',
            'status': 'error'
        })