Exemplo n.º 1
0
    def post(self, request):

        school_id = request.POST.get('school_id')
        user_id = request.POST.get('user_id')

        if school_id and user_id:
            user = User.objects.get(id=user_id)

            # 判断是否学生认证
            if user.is_school_auth == 1:
                content = request.POST.get('content')
                price = int(request.POST.get('price'))
                is_online = request.POST.get('is_type')
                is_all_school = request.POST.get('is_all_school')

                img_list = request.FILES.getlist('img_list')

                school = School.objects.get(id=school_id)
                # 判断积分是否比价格大
                if user.integral >= price:
                    # 剩余积分更新
                    left_integral = user.integral - price
                    User.objects.filter(id=user_id).update(
                        integral=left_integral)
                    # 保存数据
                    help_create = Help.objects.create(
                        content=content,
                        price=price,
                        is_online=is_online,
                        is_all_school=is_all_school,
                        user=user,
                        school=school)
                else:
                    return JsonResponse({'errmsg': '积分不足,请充值!'})

                if img_list and help_create:
                    for img in img_list:
                        # 先保存到本地 不保存七牛 因为直接用七牛的put_data提示报错 期望不是InMemoryUploadedFile类型
                        # 不怕图片名称重复 django处理了
                        save_img = HelpImage.objects.create(local_img=img,
                                                            myhelp=help_create)

                        # 下面做七牛保存
                        myhelp_local_img = str(MEDIA_ROOT) + '/' + str(
                            save_img.local_img)  # 拼接本地绝对路径
                        myhelp_img_id = save_img.id  # 获取当前本地图片的id
                        qi_local_img = qi_local_upload(
                            myhelp_local_img)  # 七牛上传
                        HelpImage.objects.filter(id=myhelp_img_id).update(
                            qiniu_img=qi_local_img)  # 更新七牛数据

                return JsonResponse({'code': 200})
            else:
                return JsonResponse({'errmsg': '该学生未认证,不能发布'})
        else:
            return JsonResponse({'errmsg': '尚未选择学校或该用户不存在'})
Exemplo n.º 2
0
    def post(self, request):
        school_id = request.POST.get('school_id')
        user_id = request.POST.get('user_id')

        if school_id and user_id:
            content = request.POST.get('content')
            price = int(request.POST.get('price'))
            is_online = request.POST.get('is_type')
            is_all_school = request.POST.get('is_all_school')
            img_list = request.FILES.getlist('img_list')

            user = User.objects.get(id=user_id)
            school = School.objects.get(id=school_id)
            # 保存数据
            help_create = Help.objects.create(content=content,
                                              price=price,
                                              is_online=is_online,
                                              is_all_school=is_all_school,
                                              user=user,
                                              school=school)
            # 说说发表数量 +1
            help_total = user.help_total + 1
            # 用户增加 2积分
            integral = user.integral + 2
            User.objects.filter(id=user_id).update(help_total=help_total,
                                                   integral=integral)

            if help_create:
                for img in img_list:
                    # 先保存到本地 不保存七牛 因为直接用七牛的put_data提示报错 期望不是InMemoryUploadedFile类型
                    # 不怕图片名称重复 django处理了
                    save_img = HelpImage.objects.create(local_img=img,
                                                        myhelp=help_create)

                    # 下面做七牛保存
                    myhelp_local_img = str(MEDIA_ROOT) + '/' + str(
                        save_img.local_img)  # 拼接本地绝对路径
                    myhelp_img_id = save_img.id  # 获取当前本地图片的id
                    qi_local_img = qi_local_upload(myhelp_local_img)  # 七牛上传
                    HelpImage.objects.filter(id=myhelp_img_id).update(
                        qiniu_img=qi_local_img)  # 更新七牛数据

                return JsonResponse({'code': 200})
            else:
                return JsonResponse({'errmsg': '未能保存图片'})
        else:
            return JsonResponse({'errmsg': '尚未选择学校或该用户不存在'})
Exemplo n.º 3
0
    def post(self, request):
        myhelp_id = request.POST.get('help_id')
        commentator_id = request.POST.get('user_id')
        content = request.POST.get('content')
        # 获取图片
        local_image = request.FILES.getlist('img_list')

        if myhelp_id and commentator_id:

            user_ins = User.objects.get(id=commentator_id)
            myhelp_ins = Help.objects.get(id=myhelp_id)
            # 只有文本
            comment_create = HelpComment.objects.create(content=content,
                                                        user=user_ins,
                                                        myhelp=myhelp_ins)

            # 发布该help的人  2019/2/24
            publisher_id = myhelp_ins.user_id
            # 保存信息到推送表里 2019/2/24
            Push.objects.create(push_content=content,
                                push_type=1,
                                publish_id=myhelp_id,
                                publisher_id=publisher_id,
                                commentator=user_ins)
            # 如果有图片
            if local_image and comment_create:
                for item in local_image:
                    comment_image = HelpCommentImage.objects.create(
                        local_img=item, comment=comment_create)
                    # 保存 图到七牛云
                    # 获取本地保存路径
                    save_image = comment_image.local_img
                    # 拼接本地绝对路径
                    comment_image_one = str(MEDIA_ROOT) + '/' + str(save_image)
                    # 上传本地图、音到七牛服务器
                    qiniu_image = qi_local_upload(comment_image_one)
                    # 更新七牛数据
                    HelpCommentImage.objects.filter(
                        id=comment_image.id).update(qiniu_img=qiniu_image)

            if comment_create:
                return JsonResponse({'code': 200})
            else:
                return JsonResponse({'msg': '数据未保存成功!'})
        else:
            return JsonResponse({'msg': '数据未保存成功!'})
Exemplo n.º 4
0
    def post(self, request):
        # 获取ajax数据
        school_id = request.POST.get('school_id')
        creator_id = request.POST.get('creator_id')
        content = request.POST.get('content')
        price = int(request.POST.get('price'))
        is_type = int(request.POST.get('is_type'))

        # 获取ajax图片
        img_list = request.FILES.getlist('img_list')

        if school_id and creator_id:
            # 保存文本数据
            user_ins = User.objects.get(id=creator_id)
            school_ins = School.objects.get(id=school_id)
            second_create = Second.objects.create(content=content,
                                                  is_type=is_type,
                                                  price=price,
                                                  school=school_ins,
                                                  creator=user_ins)

            # 保存 外键的 图片数据
            # 这一块 写的 绝望  这次再看看 还好 总感觉不是最优写法
            if img_list and second_create:
                for img in img_list:
                    # 先保存到本地 不保存七牛 因为直接用七牛的put_data提示报错 期望不是InMemoryUploadedFile类型
                    # 不怕图片名称重复 django处理了
                    save_img = SecondImg.objects.create(local_img=img,
                                                        second=second_create)

                    # 下面做七牛保存
                    second_local_img = str(MEDIA_ROOT) + '/' + str(
                        save_img.local_img)  # 拼接本地绝对路径
                    second_img_id = save_img.id  # 获取当前本地图片的id
                    qi_local_img = qi_local_upload(second_local_img)  # 七牛上传
                    SecondImg.objects.filter(id=second_img_id).update(
                        qiniu_img=qi_local_img)  # 更新七牛数据

            return JsonResponse({'code': 200})
        else:
            return JsonResponse({'errmsg': '尚未选择学校'})
Exemplo n.º 5
0
def lose_add(request):
    # 获取ajax数据
    school_id = request.POST.get('school_id')
    content = request.POST.get('content')
    creator_id = request.POST.get('creator_id')
    is_type = request.POST.get('is_type')
    # 获取ajax图片
    img_list = request.FILES.getlist('img_list')

    if school_id and creator_id:
        # 保存文本数据
        user_ins = User.objects.get(id=creator_id)
        school_ins = School.objects.get(id=school_id)
        lose_create = Lose.objects.create(content=content,
                                          is_type=is_type,
                                          school=school_ins,
                                          creator=user_ins)

        # 保存 外键的 图片数据
        # 这一块 写的 绝望
        if img_list:
            for img in img_list:
                # 先保存到本地 不保存七牛 因为直接用七牛的put_data提示报错 期望不是InMemoryUploadedFile类型
                # 不怕图片名称重复 django处理了
                save_img = LoseImg.objects.create(local_img=img,
                                                  lose=lose_create)

                # 下面做七牛保存
                lose_local_img = str(MEDIA_ROOT) + '/' + str(
                    save_img.local_img)  # 拼接本地绝对路径
                lose_img_id = save_img.id  # 获取当前本地图片的id
                qi_local_img = qi_local_upload(lose_local_img)  # 七牛上传
                LoseImg.objects.filter(id=lose_img_id).update(
                    qiniu_img=qi_local_img)  # 更新七牛数据

        return JsonResponse({'code': 200})
    else:
        return JsonResponse({'errmsg': '上传保存失败'})
Exemplo n.º 6
0
    def post(self,request):
        user_id = request.POST.get('user_id')
        head_image = request.FILES.get('head_image')
        if user_id and head_image:
            # 修改本地图片
            pic = User.objects.get(id=user_id)
            pic.head_image = head_image
            pic.save()

            # 先保存到本地 不保存七牛 因为直接用七牛的put_data提示报错 期望不是InMemoryUploadedFile类型
            # 下面做七牛保存
            user_local_img = str(MEDIA_ROOT) + '/' + str(pic.head_image)  # 拼接本地绝对路径
            qi_local_img = qi_local_upload(user_local_img)  # 七牛上传
            User.objects.filter(id=user_id).update(head_qn_url=qi_local_img)  # 更新七牛数据
            my_msg = User.objects.filter(id=user_id).values('nick','head_qn_url')

            data = {}
            data['code'] = 200
            data['my_msg'] = list(my_msg)

            return JsonResponse(data)
        else:
            return JsonResponse({'errmsg':'该用户不存在'})
Exemplo n.º 7
0
def register_msg(request):
    if request.method == 'POST':
        phone_num = request.POST.get('phone_num')
        password = request.POST.get('password')

        nick = request.POST.get('nick')
        gender = request.POST.get('gender')
        school_id = request.POST.get('school_id')
        school_name = request.POST.get('school_name')

        device_num = request.POST.get('device_num')
        device_model = request.POST.get('device_model')
        device_name = request.POST.get('device_name')
        operator = request.POST.get('operator')
        reg_ip = request.POST.get('reg_ip')        # 注册IP
        system_type = request.POST.get('system_type')        # 手机系统类型
        channel = request.POST.get('channel')        # 下载渠道

        head_image = request.FILES.get('head_image')

        # 等号+1
        ac_num = list(User.objects.values('account_num').order_by('-id')[0:1])
        account_num = int(ac_num[0].get('account_num')) + 1

        # 测试为什么update不行 不能更新图片
        # head_image = request.FILES.get('head_image')
        # pic = User.objects.get(id=13)
        # pic.head_image = head_image
        # pic.save()

        # 先判断是否重名
        have_name = User.objects.filter(nick=nick).exists()
        if have_name:
            # 用户名已经存在
            return JsonResponse({'code': 400})

        # 先更新用户信息
        if phone_num and password and nick and head_image and school_id:
            # 加密
            password_md5 = hashlib.md5(password.encode(encoding='UTF-8')).hexdigest()
            # 创建
            user_create = User.objects.create(
                phone_num=phone_num,
                password=password_md5,
                nick=nick,
                gender=gender,
                school_id=school_id,
                account_num=account_num,
                school_name=school_name,
                device_num=device_num,
                device_model=device_model,
                device_name=device_name,
                operator=operator,
                head_image=head_image,
                reg_ip=reg_ip,
                system_type=system_type,
                channel=channel,
            )
            data = {}
            if user_create:
                # 先保存到本地 不保存七牛 因为直接用七牛的put_data提示报错 期望不是InMemoryUploadedFile类型
                # 下面做七牛保存
                user_local_img = str(MEDIA_ROOT) + '/' + str(user_create.head_image)  # 拼接本地绝对路径
                qi_local_img = qi_local_upload(user_local_img)  # 七牛上传
                User.objects.filter(id=user_create.id).update(head_qn_url=qi_local_img)  # 更新七牛数据
                # 查询用户信息返回
                user_msg = User.objects.filter(id=user_create.id).values('id','nick','head_image','head_qn_url','school__id','school__name')

                # 返回用户信息
                data['code'] = 200
                data['user_msg'] = list(user_msg)

                return JsonResponse(data)
        else:
            return JsonResponse({'errmsg': '注册信息不全!'})
    else:
        return JsonResponse({'errmsg':'发生未知错误!'})
Exemplo n.º 8
0
    def post(self, request):
        moment_id = request.POST.get('moment_id')
        commentator_id = request.POST.get('user_id')
        content = request.POST.get('content')
        his_id = request.POST.get('his_id')
        # 获取图片
        local_image = request.FILES.getlist('img_list')
        # 获取音频
        local_voice = request.FILES.get('voice_url')
        voice_time = request.POST.get('voice_time')  # 语音时长 S
        # 视频
        local_video = request.FILES.get('video_url')
        video_size = request.POST.get('video_size')  # 视频大小
        if moment_id and commentator_id:
            user_ins = User.objects.get(id=commentator_id)
            moment_ins = Moment.objects.get(id=moment_id)

            # 先存到推送
            # 发布该说说的人的id 2019/2/24  他的id
            publisher_id = moment_ins.user_id
            # 保存信息到推送表里 2019/2/24
            Push.objects.create(push_content=content,
                                push_type=0,
                                publish_id=moment_id,
                                publisher_id=publisher_id,
                                commentator=user_ins)

            # 只有文本
            comment_create = Comment.objects.create(content=content,
                                                    user=user_ins,
                                                    moment=moment_ins)
            # 如果有图片
            if local_image and comment_create:
                for item in local_image:

                    comment_image = CommentImage.objects.create(
                        local_img=item, comment=comment_create)
                    # 保存 图到七牛云
                    # 获取本地保存路径
                    save_image = comment_image.local_img
                    # 拼接本地绝对路径
                    comment_image_one = str(MEDIA_ROOT) + '/' + str(save_image)
                    # 上传本地图、音到七牛服务器
                    qiniu_image = qi_local_upload(comment_image_one)
                    # 更新七牛数据
                    CommentImage.objects.filter(id=comment_image.id).update(
                        qiniu_img=qiniu_image)

            # 如果有音频
            if local_voice and comment_create:
                comment_voice = CommentVoice.objects.create(
                    local_voice=local_voice,
                    voice_time=voice_time,
                    comment=comment_create)

                # 保存语音到七牛云
                # 获取本地保存路径
                save_voice = comment_voice.local_voice
                # 拼接本地绝对路径
                comment_voice_one = str(MEDIA_ROOT) + '/' + str(save_voice)
                # 上传本地图、音到七牛服务器
                qiniu_voice = qi_local_upload(comment_voice_one)
                # 更新七牛数据
                comment = CommentVoice.objects.filter(
                    id=comment_voice.id).update(qiniu_voice=qiniu_voice)

            # 如果有视频
            if local_video and comment_create:
                comment_video = CommentVideo.objects.create(
                    local_video=local_video,
                    video_size=video_size,
                    comment=comment_create)

                # 保存到七牛云
                # 获取本地保存路径
                save_video = comment_video.local_video
                # 拼接本地绝对路径
                comment_video_one = str(MEDIA_ROOT) + '/' + str(save_video)
                # 上传本地图、音到七牛服务器
                qiniu_video = qi_local_upload(comment_video_one)
                # 更新七牛数据
                comment = CommentVideo.objects.filter(
                    id=comment_video.id).update(qiniu_video=qiniu_video)

            if comment_create:
                # 评论数量+1
                moment = Moment.objects.get(id=moment_id)
                comment_num = moment.comment_num + 1
                Moment.objects.filter(id=moment_id).update(
                    comment_num=comment_num)

                # 个人获得评论总数
                his_ins = User.objects.get(id=his_id)
                comment_total = his_ins.comment_total + 1
                User.objects.filter(id=his_id).update(
                    comment_total=comment_total)

                return JsonResponse({'code': 200})
            else:
                return JsonResponse({'msg': '数据未保存成功!'})
        else:
            return JsonResponse({'msg': '数据未保存成功!'})
Exemplo n.º 9
0
    def post(self, request):
        # 获取ajax数据
        school_id = request.POST.get('school_id')
        creator_id = request.POST.get('creator_id')
        content = request.POST.get('content')
        tag = request.POST.get('tag')
        voice_time = request.POST.get('voice_time')  # 语音时长 S
        video_size = request.POST.get('video_size')  # 视频大小 M

        # 获取ajax图片
        img_list = request.FILES.getlist('img_list')
        voice_one = request.FILES.get('voice_url')
        video_one = request.FILES.get('video_url')

        if school_id and creator_id:
            # 保存文本数据
            user_ins = User.objects.get(id=creator_id)
            school_ins = School.objects.get(id=school_id)
            moment_create = Moment.objects.create(content=content,
                                                  tag=tag,
                                                  school=school_ins,
                                                  user=user_ins)

            find_this = User.objects.get(id=creator_id)
            # 说说发表数量 +1
            find_total = find_this.find_total + 1
            # 用户增加 1积分
            integral = find_this.integral + 1
            User.objects.filter(id=creator_id).update(find_total=find_total,
                                                      integral=integral)

            # 保存 外键的 图片数据
            # 这一块 写的 绝望  这次再看看 还好 总感觉不是最优写法
            if img_list and moment_create:
                for img in img_list:
                    # 先保存到本地 不保存七牛 因为直接用七牛的put_data提示报错 期望不是InMemoryUploadedFile类型
                    # 不怕图片名称重复 django处理了
                    save_img = Image.objects.create(local_img=img,
                                                    moment=moment_create)
                    # 下面做七牛保存
                    moment_local_img = str(MEDIA_ROOT) + '/' + str(
                        save_img.local_img)  # 拼接本地绝对路径
                    moment_img_id = save_img.id  # 获取当前本地图片的id
                    qi_local_img = qi_local_upload(moment_local_img)  # 七牛上传
                    Image.objects.filter(id=moment_img_id).update(
                        qiniu_img=qi_local_img)  # 更新七牛数据

            # 保存 外键音频
            if voice_one and moment_create:
                # django 文件上传
                save_voice = Voice.objects.create(local_voice=voice_one,
                                                  voice_time=voice_time,
                                                  moment=moment_create)
                # 下面做七牛保存录音
                moment_voice_one = str(MEDIA_ROOT) + '/' + str(
                    save_voice.local_voice)  # 拼接本地绝对路径
                moment_voice_id = save_voice.id  # 获取当前本地图片的id
                qi_local_voice = qi_local_upload(
                    moment_voice_one)  # 上传本地录音到七牛服务器
                Voice.objects.filter(id=moment_voice_id).update(
                    qiniu_voice=qi_local_voice)  # 更新七牛数据

            # 保存 外键视频
            if video_one and moment_create:
                # django 文件上传
                save_video = Video.objects.create(local_video=video_one,
                                                  video_size=video_size,
                                                  moment=moment_create)

                # 下面做七牛保存视频
                moment_video_one = str(MEDIA_ROOT) + '/' + str(
                    save_video.local_video)  # 拼接本地绝对路径
                moment_video_id = save_video.id  # 获取当前本地图片的id
                qi_local_video = qi_local_upload(
                    moment_video_one)  # 上传本地视频到七牛服务器
                Video.objects.filter(id=moment_video_id).update(
                    qiniu_video=qi_local_video)  # 更新七牛数据

            return JsonResponse({'code': 200})
        else:
            return JsonResponse({'errmsg': '尚未选择学校'})