示例#1
0
    def follow_user(self, request):
        """
        关注用户
        :param request: 请求
        :return:
        """

        # 验证权限
        users = Auth.get_authenticated_user(request)
        if not users:
            return HttpResponse(json.dumps(Auth.get_no_permission_msg()))

        # 获取参数
        follow_id = request.POST.get('id', 0)

        if follow_id == 0:
            return HttpResponse(json.dumps(
                self._error_msg['follow_uid_error']))

        # 处理请求
        if not self._on_follow(users, follow_id):
            return self._follow_error_response

        # 返回正确响应
        return HttpResponse(json.dumps(self._success_msg))
示例#2
0
文件: views.py 项目: sufay3/Backend
    def digg_post(self, request):
        """
        赞贴子
        :param request: 请求
        :return:
        """

        # 验证权限
        users = Auth.get_authenticated_user(request)
        if not users:
            return HttpResponse(json.dumps(Auth.get_no_permission_msg()))

        # 获取参数
        post_type = request.POST.get('type', 0)
        post_id = request.POST.get('id', 0)

        if post_type not in [0, 1]:
            return HttpResponse(json.dumps(self._error_msg['post_type_error']))

        if post_id <= 0:
            return HttpResponse(json.dumps(self._error_msg['post_id_error']))

        # 处理请求
        if not self._on_digg(post_type, post_id):
            return HttpResponse(json.dumps(self._error_msg['post_id_error']))

        # 返回正确响应
        return HttpResponse(json.dumps(self._success_msg))
示例#3
0
    def uncollect_market(self, request):
        """
        从收藏的市场中删除目标市场
        :param request 请求
        :return:
        """

        # 验证权限
        user = Auth.get_user(request)
        if not user:
            return HttpResponse(json.dumps(Auth.get_no_permission_msg()))

        # 获取参数
        market_id = request.POST.get('id', 0)
        if market_id == 0:
            return HttpResponse(json.dumps(self._error_msg['market_id_error']))

        # 查询是否已收藏过目标市场
        if market_id not in user.collected_markets:
            return HttpResponse(
                json.dumps(self._error_msg['market_none_error']))

        # 处理请求
        if not user.update(pull__collected_markets=market_id,
                           dec__collected_market_num=1):
            return HttpResponse(json.dumps(self._error_msg['general_error']))

        # 返回正确响应
        return HttpResponse(json.dumps(self._success_msg))
示例#4
0
文件: views.py 项目: sufay3/Backend
    def read_notify(self, request):
        """
        通知被读取时的处理程序
        :param request: 请求
        :return:
        """

        # 验证权限
        user = Auth.get_user(request)
        if not user:
            return HttpResponse(json.dumps(Auth.get_no_permission_msg()))

        # 返回正确响应
        return HttpResponse(json.dumps(self._success_msg))
示例#5
0
文件: views.py 项目: sufay3/Backend
    def get_notify(self, request):
        """
        获取通知
        :param request: 请求
        :return:
        """

        # 验证权限
        users = Auth.get_authenticated_user(request)
        if not users:
            return HttpResponse(json.dumps(Auth.get_no_permission_msg()))


        # 返回正确响应
        return HttpResponse(json.dumps(self._success_msg))
示例#6
0
文件: views.py 项目: sufay3/Backend
    def publish_topic(self, request):
        """
        发表主题
        :param request: 请求
        :return:
        """

        # 验证权限
        users = Auth.get_authenticated_user(request)
        if not users:
            return HttpResponse(json.dumps(Auth.get_no_permission_msg()))

        # 获取参数
        title = request.POST.get('title', '')
        content = request.POST.get('content', '')

        # 验证标题
        if len(title) > 50:
            return HttpResponse(json.dumps(self._error_msg['title_len_error']))

        for w in self._forbidden_words:
            if title.find(w) >= 0:
                return HttpResponse(
                    json.dumps(self._error_msg['title_words_error']))

        # 验证内容
        if len(content) > 10000:
            return HttpResponse(
                json.dumps(self._error_msg['content_len_error']))

        for w in self._forbidden_words:
            if content.find(w) >= 0:
                return HttpResponse(
                    json.dumps(self._error_msg['content_words_error']))

        # 处理请求
        if not self._on_publish_topic(title, content, users):
            return HttpResponse(json.dumps(self._error_msg['general_error']))

        # 返回正确响应
        return HttpResponse(json.dumps(self._success_msg))
示例#7
0
文件: views.py 项目: sufay3/Backend
    def publish_comment(self, request):
        """
        发表评论
        :param request: 请求
        """

        # 验证权限
        users = Auth.get_authenticated_user(request)
        if not users:
            return HttpResponse(json.dumps(Auth.get_no_permission_msg()))

        # 获取参数
        content = request.POST.get('content', '')
        post_type = request.POST.get('type', 0)
        post_id = request.POST.get('id', 0)

        if post_type not in [0, 1]:
            return HttpResponse(json.dumps(self._error_msg['post_type_error']))
        if post_id == 0:
            return HttpResponse(json.dumps(self._error_msg['post_id_error']))

        # 验证内容
        if len(content) > 10000:
            return HttpResponse(
                json.dumps(self._error_msg['content_len_error']))

        for w in self._forbidden_words:
            if content.find(w) >= 0:
                return HttpResponse(
                    json.dumps(self._error_msg['content_words_error']))

        # 处理请求
        if not self._on_publish_comment(post_id, post_type, content, users):
            return HttpResponse(json.dumps(self._error_msg['general_error']))

        # 返回正确响应
        return HttpResponse(json.dumps(self._success_msg))
示例#8
0
    def unfollow_user(self, request):
        """
        取消关注用户
        :param request 请求
        :return:
        """

        # 验证权限
        users = Auth.get_authenticated_user(request)
        if not users:
            return HttpResponse(json.dumps(Auth.get_no_permission_msg()))

        # 获取参数
        follow_id = request.POST.get('id', 0)

        if follow_id == 0:
            return HttpResponse(json.dumps(
                self._error_msg['follow_uid_error']))

        # 查询是否已关注过目标用户
        follow = FollowMongo.objects(uid=user.id, follow_id=follow_id).first()
        if not follow:
            return HttpResponse(
                json.dumps(self._error_msg['follow_none_error']))

        # 处理请求
        if not user.update(pull__followings=follow_id,
                           dec__following_num=1) or not UserMongo.objects(
                               id=follow_id).update(pull__followers=user.id,
                                                    dec__follower_num=1):
            return HttpResponse(json.dumps(self._error_msg['general_error']))

        follow.delete()

        # 返回正确响应
        return HttpResponse(json.dumps(self._success_msg))