Ejemplo n.º 1
0
def update_index(request):
    # 修改用户信息
    if request.method == 'POST':
        # 相册
        imgs = request.POST.get('imgs', None)
        username = request.POST.get('username', None)
        code_id = request.POST.get('code_id', None)
        gender = request.POST.get('gender', None)
        birth = request.POST.get('birth', None)
        scope = request.POST.get('scope', None)
        signature = request.POST.get('signature', None)
        if not all([username, code_id]):
            return JsonResponse(JsonRep().FAILED(msg='必要参数没有传递'))
        user = get_token(request)
        try:
            if user:
                user.username = username
                user.gender = gender
                user.birth = birth
                user.scope = scope
                user.signature = signature
                if not user.is_alter:
                    user.code_id = code_id
                user.save()

            user.userimg_set.all().delete()
            img = base_image(imgs)
            UserImg(user=user, img=img, img_type=1).save()

            return JsonResponse(JsonRep().SUCCESS(msg='保存成功'))
        except Exception as e:
            print('==================\n', e, '==================\n')
            return JsonResponse(JsonRep().FAILED(code=-2, msg='保存失败'))
Ejemplo n.º 2
0
def like_friend(request):
    dynamictalk_id = int(request.POST.get('dynamictalk_id', 0))
    like = int(request.POST.get('like', 0))
    user = get_token(request)
    try:
        dynamictalk = DynamicTalk.objects.get(id=dynamictalk_id)
        # 判断点赞记录是否存在,如果存在则不进行点赞,如果不存在则进行点赞数量加一
        if Like.objects.filter(dynamictalk=dynamictalk,
                               like=like,
                               user_id=user.id).exists():
            Like.objects.get(dynamictalk=dynamictalk,
                             like=like,
                             user_id=user.id).delete()
            if dynamictalk.like_count >= 1:
                dynamictalk.like_count = F('like_count') - 1
                dynamictalk.save()
        else:
            Like.objects.create(dynamictalk=dynamictalk,
                                like=like,
                                user_id=user.id)
            dynamictalk.like_count = F('like_count') + 1
            dynamictalk.save()

    except Exception as e:
        print('==================\n', e, '==================\n')
        return JsonResponse(JsonRep().FAILED(msg='操作失败'))

    return JsonResponse(JsonRep().SUCCESS(msg='操作成功'))
Ejemplo n.º 3
0
def check_index(request):
    if request.method == 'POST':
        friend_id = request.POST.get('friend_id')
        page = int(request.POST.get('page', 1))
        user_friend = User.objects.filter(pk=friend_id).first()
        user = get_token(request)
        dynamictalk = DynamicTalk.objects.filter(
            user_id=friend_id).all().order_by('-id')
        dynamictalk_count = dynamictalk.count()
        pg = Paginator(dynamictalk, 10)
        dynamictalk = pg.page(page)
        friend_dict = {}
        result = []
        if dynamictalk:
            label = DynamicTalk.objects.filter(user_id=friend_id).first()
            login_time = UserToken.objects.filter(
                user_id=friend_id).order_by('-id')
            jl = user.meetnum_set.filter(meetcount=friend_id).first()
            dt = datetime.datetime.now()
            age = dt.year - user_friend.birth.year
            img = user.userimg_set.filter(img_type=1).first()
            friend_dict['img'] = img.img.name
            friend_dict['username'] = user_friend.username
            friend_dict['gender'] = user_friend.gender
            friend_dict['age'] = age
            friend_dict['dynamictalk_count'] = dynamictalk_count
            friend_dict['login_time'] = login_time[0].create_time.strftime(
                '%F %X')
            friend_dict['distance'] = jl.distance
            friend_dict['labels'] = label.labels
            for cls in dynamictalk:
                dict = {}
                pictures = user_friend.userimg_set.filter(
                    Q(img_type=3) & Q(dynamictalk_id=cls.id)).all()
                if pictures:
                    images = []
                    for picture in pictures:
                        images.append(picture.img.name)
                    dict['id'] = cls.id
                    dict['content_text'] = cls.content_text
                    dict['images'] = images
                    dict['create_time'] = cls.create_time.strftime('%F %X')
                    dict['like_count'] = cls.like_count
                    dict['address'] = cls.address
                    result.append(dict)
                else:
                    dict['id'] = cls.id
                    dict['content_text'] = cls.content_text
                    dict['images'] = []
                    dict['create_time'] = cls.create_time.strftime('%F %X')
                    dict['like_count'] = cls.like_count
                    dict['address'] = cls.address
                    result.append(dict)
            friend_dict['result'] = result
            return JsonResponse(JsonRep().SUCCESS(msg='请求成功',
                                                  data=friend_dict))
        else:
            return JsonResponse(JsonRep().SUCCESS(msg='请求成功',
                                                  data=friend_dict))
Ejemplo n.º 4
0
def issue_friend(request):
    if request.method == 'POST':
        # 获取要上传的数据
        content_text = request.POST.get('content_text', None)
        pictures = request.POST.get('pictures', None)
        latitude = request.POST.get('latitude', None)
        longitude = request.POST.get('longitude', None)
        open_type = request.POST.get('open_type', 0)
        address = request.POST.get('address')
        labels = request.POST.get('labels')
        picture_list = [] if len(
            pictures) == 0 or pictures is None else pictures.split(',')
        if not all([latitude, longitude]) and (not all(pictures) or
                                               (content_text is None
                                                and len(content_text) == 0)):
            return JsonResponse(JsonRep().FAILED(msg='缺少必要参数'))
        user = get_token(request)
        try:
            dynamictalk = DynamicTalk()
            dynamictalk.content_text = content_text
            dynamictalk.user = user
            dynamictalk.latitude = latitude
            dynamictalk.longitude = longitude
            dynamictalk.open_type = open_type
            dynamictalk.address = address
            dynamictalk.labels = labels
            dynamictalk.save()
            for picture in picture_list:
                img = base_image(picture)
                UserImg(user=user,
                        img=img,
                        img_type=3,
                        dynamictalk_id=dynamictalk.id).save()
            cls_dict = {}
            pictures = user.userimg_set.filter(
                Q(img_type=3) & Q(dynamictalk_id=dynamictalk.id)).all()
            if pictures:
                images = []
                for picture in pictures:
                    images.append(picture.img.name)
                cls_dict['id'] = dynamictalk.id
                cls_dict['user_id'] = dynamictalk.user_id
                cls_dict['content_text'] = dynamictalk.content_text
                cls_dict['images'] = images
                cls_dict['gauge_type'] = dynamictalk.gauge_type
                cls_dict['latitude'] = dynamictalk.latitude
                cls_dict['longitude'] = dynamictalk.longitude
                cls_dict['open_type'] = dynamictalk.open_type
                cls_dict['like_count'] = dynamictalk.like_count
                cls_dict['create_time'] = dynamictalk.create_time.strftime(
                    '%F %X')
                cls_dict['address'] = dynamictalk.address
                cls_dict['labels'] = dynamictalk.labels

            return JsonResponse(JsonRep().SUCCESS(msg='发布成功', data=cls_dict))
        except Exception as e:
            print('==================\n', e, '==================\n')
        return JsonResponse(JsonRep().FAILED(code=-2, msg='发布失败'))
Ejemplo n.º 5
0
def del_gauge(request):
    gauge_point_id = request.POST.get('gauge_point_id')
    try:
        gauge_point = Gauge_Point.objects.get(id=gauge_point_id)
        gauge_point.delete()
        return JsonResponse(JsonRep().SUCCESS(msg='删除成功'))
    except Exception as e:
        print('==================\n', e, '==================\n')
        return JsonResponse(JsonRep().SUCCESS(msg='删除失败'))
Ejemplo n.º 6
0
def feedback(request):
    centent = request.GET.get('centent', None)
    user = get_token(request)
    try:
        Feedback(user=user, centent=centent).save()
        return JsonResponse(JsonRep().SUCCESS(msg='反馈成功'))
    except Exception as e:
        print('==================\n', e, '==================\n')
        return JsonResponse(JsonRep().FAILED(msg='反馈失败'))
Ejemplo n.º 7
0
def del_friend(request):
    dynamictalk_id = request.POST.get('dynamictalk_id')
    try:
        dynamictalk = DynamicTalk.objects.get(id=dynamictalk_id)
        dynamictalk.delete()
        return JsonResponse(JsonRep().SUCCESS(msg='删除成功'))
    except Exception as e:
        print('==================\n', e, '==================\n')
        return JsonResponse(JsonRep().SUCCESS(msg='删除失败'))
Ejemplo n.º 8
0
def issue_gauge(request):
    if request.method == 'POST':
        content_text = request.POST.get('content_text', None)
        # 多个文件上传 图片、视频
        pictures = request.FILES.getlist('pictures', None)
        latitude = request.POST.get('latitude', None)
        longitude = request.POST.get('longitude', None)
        address = request.POST.get('address')
        labels = request.POST.get('labels')
        pictures = [] if (pictures is None or len(pictures) == 0) else (
            pictures if isinstance(pictures, list) else [pictures])
        if not all([latitude, longitude]) and (not all(pictures) or (
                content_text is None and len(content_text) == 0)):
            return JsonResponse(JsonRep().FAILED(msg='缺少必要参数'))
        try:
            user = get_token(request)
            dt = datetime.datetime.now()
            today_gauge_point_set_count = user.gauge_point_set.filter(create_time__year=dt.year,
                                                                      create_time__month=dt.month,
                                                                      create_time__day=dt.day).count()
            if today_gauge_point_set_count > 5:
                return JsonResponse(JsonRep().FAILED(code=-2, msg='一天只能发布5条'))
            gauge_point = Gauge_Point()
            gauge_point.content_text = content_text
            gauge_point.user = user
            gauge_point.latitude = latitude
            gauge_point.longitude = longitude
            gauge_point.address = address
            gauge_point.labels = labels
            gauge_point.save()
            for picture in pictures:
                img = base_image(picture)
                UserImg(user=user, img=img, img_type=3, gauge_point_id=gauge_point.id).save()
            cls_dict = {}
            pictures = user.userimg_set.filter(Q(img_type=3) & Q(gauge_point_id=gauge_point.id)).all()
            if pictures:
                images = []
                for picture in pictures:
                    images.append(picture.img.name)
                cls_dict['id'] = gauge_point.id
                cls_dict['user_id'] = gauge_point.user_id
                cls_dict['content_text'] = gauge_point.content_text
                cls_dict['images'] = images
                cls_dict['gauge_type'] = gauge_point.gauge_type
                cls_dict['latitude'] = gauge_point.latitude
                cls_dict['longitude'] = gauge_point.longitude
                cls_dict['like_num'] = gauge_point.like_num
                cls_dict['create_time'] = gauge_point.create_time.strftime('%F %X')
                cls_dict['address'] = gauge_point.address
                cls_dict['labels'] = gauge_point.labels
            return JsonResponse(JsonRep().SUCCESS(msg='发布成功', data=cls_dict))
        except Exception as e:
            print(e)
            return JsonResponse(JsonRep().FAILED(code=-3, msg='发布失败'))
Ejemplo n.º 9
0
def report_friend(request):
    dynamictalk_id = int(request.POST.get('dynamictalk_id', 0))
    cause = request.POST.get('cause', None)
    user = get_token(request)
    try:
        dynamictalk = DynamicTalk.objects.get(pk=dynamictalk_id)
        Report_Friends(user=user, dynamictalk=dynamictalk, cause=cause).save()
        return JsonResponse(JsonRep().SUCCESS(msg='举报成功'))
    except Exception as e:
        print('==================\n', e, '==================\n')
        return JsonResponse(JsonRep().FAILED(msg='举报失败'))
Ejemplo n.º 10
0
def report_gauge(request):
    # 得到GET中的数据以及当前用户
    gauge_point_id = int(request.GET.get('gauge_point_id', 0))
    cause = request.GET.get('cause', None)
    user = get_User(request)
    try:
        gauge_point = Gauge_Point.objects.get(pk=gauge_point_id)
        Report(user=user, gauge_point=gauge_point, cause=cause).save()
        return JsonResponse(JsonRep().SUCCESS(msg='举报成功'))
    except Exception as e:
        print('==================\n', e, '==================\n')
        return JsonResponse(JsonRep().FAILED(msg='举报失败'))
Ejemplo n.º 11
0
def reset_pwd(request):
    mobile = request.POST.get('mobile', None)
    password = request.POST.get('password', None)
    verify = request.POST.get('verify', None)
    if not all([mobile, password, verify]):
        return JsonResponse(JsonRep().FAILED(msg='必要参数没有传递'))
    user = get_token(request)
    if verify != opr.getredis(mobile):
        return JsonResponse(JsonRep().FAILED(code=-2, msg='短信验证失败'))
    if not user:
        return JsonResponse(JsonRep().FAILED(code=-3, msg='用户验证失败'))
    user.password = make_password(password)
    user.save()
    return JsonResponse(JsonRep().SUCCESS(msg='重置密码成功'))
Ejemplo n.º 12
0
def add_label(request):
    lables = request.POST.get('lables', None)
    lables_list = [] if len(lables) == 0 or lables is None else lables.split(
        ',')
    try:
        user = get_token(request)

        if user:
            [Lable(user=user, lable=labels).save() for labels in lables_list]
            return JsonResponse(JsonRep().SUCCESS(msg='设置标签成功'))
        else:
            return JsonResponse(JsonRep().FAILED(msg='设置标签失败'))
    except Exception as e:
        print('==================\n', e, '==================\n')
        return JsonResponse(JsonRep().FAILED(msg='设置标签失败'))
Ejemplo n.º 13
0
def detail_user(request):
    user_id = request.POST.get('user_id')
    head_portrait = request.POST.get('head_portrait', None)
    username = request.POST.get('username', None)
    gender = request.POST.get('gender', None)
    birth = request.POST.get('birth', None)
    scope = request.POST.get('scope', None)
    signature = request.POST.get('signature', None)
    latitude = request.POST.get('latitude', 0)
    longitude = request.POST.get('longitude', 0)
    # print(get_constellation(8, 23))

    img = base_image(head_portrait)
    # imgdata = base64.b64decode(head_portrait)
    # file = open('./media/upload/aa.jpg', 'wb')
    # file.write(imgdata)
    # file.close()
    # user = get_User(request)
    # user = User.objects.filter(pk=user_id).first()
    user = get_token(request)
    if user:
        try:
            user.username = username  # if not username else user.mobile
            user.gender = gender
            user.birth = birth
            user.scope = scope
            user.signature = signature
            user.latitude = latitude
            user.longitude = longitude
            user.save()
            UserImg(user_id=user.id, img=img, img_type=1).save()

        except Exception as e:
            return JsonResponse({'code': 201, 'msg': '完善信息失败'})
        img = user.userimg_set.filter(img_type=1).first()
        data = dict(id=user.id,
                    username=user.username,
                    gender=user.gender,
                    birthday=user.birth,
                    scope=user.scope,
                    signature=user.signature,
                    img=img.img.name,
                    code_id=user.code_id)
        return JsonResponse(JsonRep().SUCCESS(msg='完善信息成功!', data=data))
    return JsonResponse(JsonRep().FAILED(msg='完善信息失败'))
Ejemplo n.º 14
0
def register(request):
    mobile = request.POST.get('mobile', None)  # 手机号
    password = request.POST.get('password', None)  # 密码
    verify = request.POST.get('verify', None)  # 验证码
    if mobile is None or len(mobile) == 0:
        return JsonResponse(JsonRep().FAILED(code=-1, msg='没有传递参数mobile'))
    if password is None or len(password) == 0:
        return JsonResponse(JsonRep().FAILED(code=-2, msg='密码不能为空'))
    if not re.match(MOBILE_RE, mobile):
        return JsonResponse(JsonRep().FAILED(code=-3, msg='请输入正确手机号'))
    user = User.objects.filter(mobile=mobile).first()
    if user:
        return JsonResponse(JsonRep().FAILED(code=-5, msg='用户已注册请去登录'))
    code = opr.getredis(mobile)
    # 如果code is None 就是False  / code is not None 就是True
    if code != verify:
        return JsonResponse(JsonRep().FAILED(code=-4, msg='验证错误,请重新发送验证码'))
    user_code = random_id()
    try:
        user = User.objects.create(mobile=mobile,
                                   password=make_password(password),
                                   code_id=user_code)
        # request.session['user_id'] = user.id
        data = dict(id=user.id,
                    mobile=mobile,
                    password=password,
                    code_id=user_code,
                    verify=verify)
        # 创建成功后清除redis中该key值
        opr.delredis(mobile)
    except Exception as e:
        raise e
    return JsonResponse(JsonRep().SUCCESS(msg='注册成功!', data=data))
Ejemplo n.º 15
0
def send_message(request):
    # 第一步 request.GET --> dict(key , value)  ['Name'] / get('Name')
    mobile = request.POST.get('mobile', None)
    # /user/send_message?mobile=
    if mobile is None or len(mobile) == 0:
        return JsonResponse(JsonRep().FAILED(code=-1, msg='没有传递参数mobile'))
    if not re.match(MOBILE_RE, mobile):
        return JsonResponse(JsonRep().FAILED(code=-2, msg='请输入正确手机号'))
    tengxun = TengXun()
    code = Random_verify()
    results = tengxun.send_message(code, mobile)
    try:
        if results['result'] == 0:
            # request.session.setdefault(mobile, code) 存在就不能设置
            # request.session[mobile] = code
            opr.setredis(mobile, code)
        else:
            return JsonResponse(JsonRep().FAILED(code=-3, msg='发送失败'))
    except Exception as e:
        print(e)
        return JsonResponse(JsonRep().FAILED(code=-3, msg='发送失败'))
    return JsonResponse(JsonRep().SUCCESS(msg='发送成功!有效期10分钟'))
Ejemplo n.º 16
0
def index(request):
    # 查看个人信息
    if request.method == 'POST':
        user = get_token(request)
        if not user:
            return JsonResponse(JsonRep().FAILED(code=-3, msg='用户不存在'))
        index_dict = {}
        dt = datetime.datetime.now()
        age = dt.year - user.birth.year
        # 获取我喜欢、喜欢我、相互喜欢数量
        user_likes = user.meetlike_set.all().count()
        like_users = MeetLike.objects.filter(friend_id=user.id).all().count()
        if user_likes and like_users:
            friend_list = []
            for user_like in user_likes:
                x = user_like.friend_id
                friend_list.append(x)
            for like_user in like_users:
                i = like_user.user.first()
                nums = 0
                if i.id in friend_list:
                    nums += 1
                index_dict['together_like_count'] = nums
        friend_count = DynamicTalk.objects.filter(
            user_id=user.id).all().count()
        # gauge_count = Gauge_Point.objects.filter(user_id=user.id).all().count()
        img = user.userimg_set.filter(img_type=1).first()
        index_dict['img'] = img.img.name
        index_dict['username'] = user.username
        index_dict['gender'] = user.gender
        index_dict['age'] = age
        index_dict['code_id'] = user.code_id
        index_dict['user_like_count'] = user_likes
        index_dict['user_meet_count'] = like_users
        index_dict['friend_count'] = friend_count
        # index_dict['gauge_coutn'] = gauge_count
        # index_dict['together_like_count'] = together_like_count
        return JsonResponse(JsonRep().SUCCESS(msg='请求成功', data=index_dict))
Ejemplo n.º 17
0
def like_gauge(request):
    gauge_point_id = int(request.GET.get('gauge_point_id', 0))
    like = int(request.GET.get('like', 0))
    user = get_token(request)
    try:
        gauge_point = Gauge_Point.objects.get(pk=gauge_point_id)
        # 判断点赞记录是否存在,如果存在则不进行点赞,如果不存在则进行点赞数量加一
        if Like_Count.objects.filter(gauge_point=gauge_point, like=like, user_id=user.id).exists():
            # 存在则进行取消点赞,删除点赞记录
            Like_Count.objects.get(gauge_point=gauge_point, like=like, user_id=user.id).delete()
            if gauge_point.like_num >= 1:
                gauge_point.like_num = F('like_num') - 1
                gauge_point.save()
        else:
            # 进行点赞,即实例化一个点赞记录
            Like_Count.objects.create(gauge_point=gauge_point, like=like, user_id=user.id)
            gauge_point.like_num = F('like_num') + 1
            gauge_point.save()
    except Exception as e:
        print('==================\n', e, '==================\n')
        return JsonResponse(JsonRep().FAILED(msg='操作失败'))

    return JsonResponse(JsonRep().SUCCESS(msg='操作成功'))
Ejemplo n.º 18
0
def register(request):
    if request.method == 'GET':
        return render(request, 'back/register.html')
    if request.method == 'POST':
        username = request.POST.get('username', None)  # 手机号
        password = request.POST.get('password', None)  # 密码
        password1 = request.POST.get('password1', None)  # 密码

        user = BackUser.objects.filter(username=username).first()
        if user:
            return JsonResponse(JsonRep().FAILED(code=-5, msg='用户已注册请去登录'))
        if password != password1:
            return JsonResponse({'code': 201, 'msg': '两次密码不同'})
        try:
            BackUser.objects.create(username=username,
                                    password=make_password(password))

        except Exception as e:
            raise e
        return HttpResponseRedirect(reverse('backstage:login'))
Ejemplo n.º 19
0
def login(request):
    mobile = request.POST.get('mobile', None)  # 手机号
    password = request.POST.get('password', None)  # 密码
    verify = request.POST.get('verify', None)  # 验证码
    if mobile is None or len(mobile) == 0:
        return JsonResponse(JsonRep().FAILED(code=-1, msg='没有传递参数mobile'))
    if not re.match(MOBILE_RE, mobile):
        return JsonResponse(JsonRep().FAILED(code=-3, msg='请输入正确手机号'))
    user = User.objects.filter(mobile=mobile).first()
    if not user:
        return JsonResponse(JsonRep().FAILED(code=-5, msg='不存在该用户'))
    if password is None or len(password) == 0:
        try:
            # 如果code is None 就是False  / code is not None 就是True
            code = opr.getredis(mobile)
            if code != verify:
                return JsonResponse(JsonRep().FAILED(code=-4,
                                                     msg='验证错误,请重新发送验证码'))
            return JsonResponse(JsonRep().SUCCESS(msg='登录成功!'))
        except Exception as e:
            print(e)
            return JsonResponse({'code': -1, 'msg': '不存在该用户!'})
    else:
        if check_password(password, user.password):
            s = '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
            token = ''
            for i in range(20):
                token += random.choice(s)
            us_token = UserToken.objects.filter(user_id=user.id).first()
            if us_token:
                UserToken.objects.filter(user_id=user.id).update(token=token)
            else:
                UserToken.objects.create(user_id=user.id, token=token)
            if_complete = user.username
            if_complete_index_img = AddPhoto.objects.filter(
                user_id=user.id).first()
            if if_complete:
                user_img = UserImg.objects.filter(user_id=user.id).first()
                if if_complete_index_img:
                    data = dict(id=user.id,
                                mobile=user.mobile,
                                username=user.username,
                                if_complete_index_img=True,
                                code_id=user.code_id,
                                img=user_img.img.name,
                                if_complete=True,
                                token=token)
                    return JsonResponse(JsonRep().SUCCESS(msg='登录成功!',
                                                          data=data))
                else:
                    data = dict(id=user.id,
                                mobile=user.mobile,
                                username=user.username,
                                if_complete_index_img=False,
                                code_id=user.code_id,
                                img=user_img.img.name,
                                if_complete=True,
                                token=token)
                    return JsonResponse(JsonRep().SUCCESS(msg='登录成功!',
                                                          data=data))

            else:
                if if_complete_index_img:
                    data = dict(id=user.id,
                                mobile=user.mobile,
                                if_complete=False,
                                if_complete_index_img=True,
                                token=token)
                    return JsonResponse(JsonRep().SUCCESS(msg='登录成功!',
                                                          data=data))
                else:
                    data = dict(id=user.id,
                                mobile=user.mobile,
                                if_complete=False,
                                if_complete_index_img=False,
                                token=token)
                    return JsonResponse(JsonRep().SUCCESS(msg='登录成功!',
                                                          data=data))
    return JsonResponse(JsonRep().FAILED(code=-6, msg='校验失败'))
Ejemplo n.º 20
0
def check_gauge(request):
    # 查看标记点
    if request.method == 'GET':
        create_time = request.GET.get('create_time', 'desc')
        like_num = request.GET.get('like_num', 'desc')
        page = request.POST.get('page')
        user = get_token(request)
        # 只查看最近7天的记录
        dt = datetime.datetime.now()
        old_dt = get_end_by_dt_7(dt)
        # desc降序
        create_time = '-create_time' if create_time == 'desc' else 'create_time'
        like_num = '-like_num' if like_num == 'desc' else 'like_num'
        gauge_point = Gauge_Point.objects.filter(create_time__lte=dt,
                                                 create_time__gte=old_dt).order_by(create_time).order_by(like_num)
        pg = Paginator(gauge_point, 10)
        gauge_point = pg.page(page)

        gauge_point_dict = {}
        result = []
        if gauge_point:
            for cls in gauge_point:
                dict = {}
                pictures = UserImg.objects.filter(Q(img_type=3) & Q(gauge_point_id=cls.id)).all()
                if pictures:
                    images = []
                    for picture in pictures:
                        images.append(picture.img.name)
                    img = UserImg.objects.filter(img_type=1).first()

                    dict['img'] = img.img.name
                    dict['username'] = User.objects.get(id=cls.user_id).username
                    dict['id'] = cls.id
                    dict['user_id'] = cls.user_id
                    dict['content_text'] = cls.content_text
                    dict['images'] = images
                    dict['gauge_type'] = cls.gauge_type
                    dict['latitude'] = cls.latitude
                    dict['longitude'] = cls.longitude
                    dict['open_type'] = cls.open_type
                    dict['like_count'] = cls.like_count
                    dict['create_time'] = cls.create_time.strftime('%F %X')
                    dict['address'] = cls.address
                    dict['labels'] = cls.labels
                    result.append(dict)
                else:
                    img = user.userimg_set.filter(img_type=1).first()

                    dict['img'] = img.img.name
                    dict['username'] = User.objects.get(id=cls.user_id).username
                    dict['id'] = cls.id
                    dict['user_id'] = cls.user_id
                    dict['content_text'] = cls.content_text
                    dict['images'] = []
                    dict['gauge_type'] = cls.gauge_type
                    dict['latitude'] = cls.latitude
                    dict['longitude'] = cls.longitude
                    dict['open_type'] = cls.open_type
                    dict['like_count'] = cls.like_count
                    dict['create_time'] = cls.create_time.strftime('%F %X')
                    dict['address'] = cls.address
                    dict['labels'] = cls.labels
                    result.append(dict)
            gauge_point_dict['result'] = result
            return JsonResponse(JsonRep().SUCCESS(msg='请求成功', data=gauge_point_dict))
        else:
            return JsonResponse(JsonRep().SUCCESS(msg='请求成功', data=gauge_point_dict))
Ejemplo n.º 21
0
def check_friend(request):
    if request.method == 'POST':
        sereen_type = int(request.POST.get('sereen_type', 0))
        page = request.POST.get('page')
        user = get_token(request)
        dynamictalk = DynamicTalk.objects.all().order_by('-id')
        pg = Paginator(dynamictalk, 10)
        dynamictalk = pg.page(page)
        # json_data = serializers.serialize("json", page, ensure_ascii=False)

        if sereen_type == 1:  # 1:喜欢我的
            like_users = MeetLike.objects.filter(friend_id=user.id)
            likeme_userid = [cls.id for cls in like_users]
            # 查喜欢我的用户动态
            dynamictalk = dynamictalk.filter(user_id__in=likeme_userid)

        elif sereen_type == 2:  # 2:我喜欢的
            user_likes = MeetLike.objects.filter(user=user)
            melike_userid = [cls.user_friend_id for cls in user_likes]
            # 查我喜欢的用户动态
            dynamictalk = dynamictalk.filter(user_id__in=melike_userid)

        elif sereen_type == 3:  # 3:相互喜欢的
            meetlike = user.meetlike_set.all()
            likeme_relationships = meetlike.filter(friend_id=user.id)
            likeme_userid = [cls.id for cls in meetlike]
            melike_relationships = meetlike.filter(user=user)
            melike_userid = [cls.user_friend_id for cls in meetlike]
            ships_userid = likeme_userid or melike_userid
            dynamictalk = dynamictalk.filter(user_id__in=ships_userid)
        else:
            pass
        cls_dict = {}
        result = []
        if dynamictalk:
            # label = DynamicTalk.objects.filter(user_id=user.id).first()
            # cls_dict['labels'] = label.labels
            # cls_dict['page'] = json_data
            for cls in dynamictalk:
                dict = {}
                pictures = UserImg.objects.filter(
                    Q(img_type=3) & Q(dynamictalk_id=cls.id)).all()
                if pictures:
                    images = []
                    for picture in pictures:
                        images.append(picture.img.name)
                    img = UserImg.objects.filter(img_type=1).first()

                    dict['img'] = img.img.name
                    dict['username'] = User.objects.get(
                        id=cls.user_id).username
                    dict['id'] = cls.id
                    dict['user_id'] = cls.user_id
                    dict['content_text'] = cls.content_text
                    dict['images'] = images
                    dict['gauge_type'] = cls.gauge_type
                    dict['latitude'] = cls.latitude
                    dict['longitude'] = cls.longitude
                    dict['open_type'] = cls.open_type

                    dict['like_count'] = cls.like_count
                    dict['create_time'] = cls.create_time.strftime('%F %X')
                    dict['address'] = cls.address
                    dict['labels'] = cls.labels
                    result.append(dict)
                else:
                    img = user.userimg_set.filter(img_type=1).first()

                    dict['img'] = img.img.name
                    dict['username'] = User.objects.get(
                        id=cls.user_id).username
                    dict['id'] = cls.id
                    dict['user_id'] = cls.user_id
                    dict['content_text'] = cls.content_text
                    dict['images'] = []
                    dict['gauge_type'] = cls.gauge_type
                    dict['latitude'] = cls.latitude
                    dict['longitude'] = cls.longitude
                    dict['open_type'] = cls.open_type
                    dict['like_count'] = cls.like_count
                    dict['create_time'] = cls.create_time.strftime('%F %X')
                    dict['address'] = cls.address
                    dict['labels'] = cls.labels
                    result.append(dict)
            cls_dict['result'] = result
            return JsonResponse(JsonRep().SUCCESS(
                msg='请求成功',
                data=cls_dict,
            ))
        else:
            return JsonResponse(JsonRep().SUCCESS(msg='请求成功', data=cls_dict))