Example #1
0
 def delete(self, request, *args, **kwargs):
     with transaction.atomic():
         comment = self.get_object()
         comment.is_del = True
         comment.save()
         comment.moment.modify_comment_total(-1)
     return Response(Tool.format_data(msg=messages.DELETE_COMMENT_OK))
Example #2
0
 def post(self, request, *args, **kwargs):
     data = request.data.dict()
     data['customer_id'] = request.session['customer_id']
     serializer = self.get_serializer_class()(data=data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(Tool.format_data(serializer.data, msg=messages.ADD_OK))
Example #3
0
 def get(self, request, format=None):
     Tool.param_in_options(request, 'file_type', ['image'])
     file_type = request.query_params.get('file_type', 'image')
     bucket_name = QiniuServe.get_bucket_name(file_type)
     token = QiniuServe.gen_app_upload_token(bucket_name)
     data = {'token': token}
     return Response(Tool.format_data(data))
Example #4
0
 def get(self, request, format=None):
     data = IMServe.gen_token(request.user.customer.id,
                              request.user.customer.name,
                              request.user.customer.avatar_url)
     request.user.customer.im_token = data['token']
     request.user.customer.save()
     return Response(Tool.format_data(data))
Example #5
0
 def post(self, request):
     """登录"""
     required_params = ['account', 'password']
     Tool.required_params(request, required_params)
     username = request.data.get('account')
     password = request.data.get('password')
     try:
         user = authenticate(self.request,
                             username=username,
                             password=password)
         if user:
             customer_login.login(request, user)
             data = {
                 'id': user.customer.id,
                 'user_id': user.id,
                 'name': user.customer.name,
                 'im_token': user.customer.im_token,
             }
             mm_CustomerPoint.add_action(request.session['customer_id'],
                                         mm_CustomerPoint.Action_Login)
             return Response(Tool.format_data(data))
         else:
             raise LoginException('账号或密码错误')
     except User.DoesNotExist:
         raise LoginException('账号不存在')
Example #6
0
    def post(self, request, format=None):
        _name = request.user.customer.name
        _avatar_url = request.user.customer.avatar_url
        if 'condition' in request.data:
            required_fields = [
                'age_range', 'height_range', 'profession', 'education',
                'income', 'marital_status', 'child_status', 'years_to_marry'
            ]
            for key in required_fields:
                if key not in json.loads(request.data.get('condition')):
                    return Response(data={'detail': 'condition缺少字段或格式错误'},
                                    status=status.HTTP_400_BAD_REQUEST)

        serializer = CustomerSerializer(request.user.customer,
                                        data=request.data,
                                        partial=True)
        if serializer.is_valid(raise_exception=True):
            if 'avatar_url' in serializer.validated_data:
                serializer.validated_data[
                    'avatar_url'] = serializer.validated_data['avatar_url']
                avatar_url = serializer.validated_data.pop('avatar_url')
                serializer.validated_data['avatar_status'] = 0
                mm_Picture.add_picture(request.user.customer.id, avatar_url)
            serializer.save()
            if any([
                    not _name == serializer.data['name'],
                    not _avatar_url == serializer.data['avatar_url']
            ]):
                IMServe.refresh_token(request.user.customer.id,
                                      request.user.customer.name,
                                      request.user.customer.avatar_url)
            return Response(Tool.format_data(serializer.data))
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Example #7
0
    def get(self, request):

        BASE_USER_COUNT = 1000
        user_total = cache.get(CacheKey.user_total)
        if user_total is None:
            user_total = mm_Customer.all().count()
            cache.set(CacheKey.user_total, user_total, 60 * 5)
        user_total += BASE_USER_COUNT
        app_config = {
            'version': '1.0.3',
            'url': 'http://pkqiei3s2.bkt.clouddn.com/app-release-xueqiu',
            'desc': '修复图片显示问题,更换雪球logo',
            'music': 'http://oys4026ng.bkt.clouddn.com/musiclight.mp3',
            'user_total': user_total,
            'image_domain': QiNiuSettings.BUCKET_DOMAIN_DICT['image'],
            'chat_times_limit':
            settings.NORNAML_CUSTOMER_CHAT_TIMES_LIMIT_PER_DAY,
            'kefuid': mm_Customer.get_kefu_id(),
            'isNeedVerified': handan_global_config.IsNeedVerified,
            'next_app_version': handan_global_config.Next_APP_Version,
            'version_ios': handan_global_config.CURRENT_APP_VERSION_IOS,
            'version_android':
            handan_global_config.CURRENT_APP_VERSION_ANDROID,
        }
        return Response(Tool.format_data(app_config))
Example #8
0
 def post(self, request, *args, **kwargs):
     topic = mm_Topic.get_toptics(request.data.get('name'),
                                  request.session['customer_id'],
                                  request.user.id,
                                  request.data.get('logo_url'))
     serializer = self.serializer_class(topic)
     return Response(Tool.format_data(serializer.data))
Example #9
0
 def post(self, request, format=None):
     customer_id = request.data['customer_id']
     relationship_status = int(
         request.data.get('status', RELATIONSHIP_FOLLOWING))
     relationship = request.user.customer.add_relationship(
         customer_id, relationship_status)
     serializer = BaseRelationShipSerializer(relationship)
     return Response(Tool.format_data(serializer.data))
Example #10
0
 def post(self, request):
     required_params = ['code', 'account', 'password']
     Tool.required_params(request, required_params)
     code = request.data.get('code')
     account = request.data.get('account')
     password = request.data.get('password')
     mm_SMSCode.is_effective(account, code)
     customer = mm_Customer.add(account, password)
     customer_login.login(request, customer.user)
     data = dict(account=account, id=customer.id, user_id=customer.user.id)
     return Response(Tool.format_data(data), status=status.HTTP_200_OK)
Example #11
0
 def create(self, request, *args, **kwargs):
     Tool.required_params(request, ['account'])
     account = request.data.get('account')
     code = gen_code()
     if not mm_SMSCode.can_get_new_code(tel=account):
         raise SMSExcecption('请过几分钟尝试')
     response = send_simple_code(account, code)
     if response['Code'] == 'OK':
         mm_SMSCode.add(account, code)
         return Response(Tool.format_data())
     else:
         raise SMSExcecption(response['Message'])
Example #12
0
 def update(self, request, *args, **kwargs):
     certification = self.get_object()
     if certification.status == mm_Certification.Status_Verified:
         data = {'detail': '已通过审核禁止修改'}
         return Response(data=data, status=status.HTTP_400_BAD_REQUEST)
     else:
         serializers = self.serializer_class(certification,
                                             data=request.data,
                                             partial=True)
         serializers.is_valid(raise_exception=True)
         serializers.save()
         return Response(Tool.format_data(data=serializers.data))
Example #13
0
 def post(self, request, *args, **kwargs):
     data = request.data.dict()
     data['customer_id'] = self.request.session['customer_id']
     serializer = self.serializer_class(data=data)
     serializer.is_valid(raise_exception=True)
     try:
         serializer.save()
         return Response(Tool.format_data(msg=messages.ADD_OK))
     except IntegrityError:
         raise DBException('请勿重复提交')
     except:
         msg = traceback.format_exc()
         raise DBException(msg)
Example #14
0
 def post(self, request, *args, **kwargs):
     with transaction.atomic():
         like, created = mm_Likes.get_or_create(
             customer_id=request.session['customer_id'],
             moment_id=kwargs['pk'])
         if created:
             like.moment.modify_like_total()
             mm_Notice.add_notice(like.moment, like,
                                  Action.ACTION_TYPE_ADD_LIKE)
             mm_CustomerPoint.add_action(request.session['customer_id'],
                                         mm_CustomerPoint.Action_Add_Like)
         serializer = LikeCreateSerializer(like)
         return Response(
             Tool.format_data(serializer.data, msg=messages.ADD_LIKE_OK))
Example #15
0
 def post(self, request):
     """密码重置"""
     if request.user.is_authenticated:
         Tool.required_params(request, ['raw_password', 'new_password'])
         raw_password = request.data['raw_password']
         new_password = request.data['new_password']
         user = mm_Customer.reset_password_by_login(request.user.id,
                                                    raw_password,
                                                    new_password)
     else:
         account = request.data.get('account')
         password = request.data.get('password')
         code = request.data.get('code')
         user = mm_Customer.reset_password_by_sms(account, password, code)
     return Response(Tool.format_data(), status=status.HTTP_200_OK)
Example #16
0
 def post(self, request, *args, **kwargs):
     data = request.data.dict()
     data['moment_id'] = kwargs['pk']
     data['from_customer_id'] = request.session['customer_id']
     serializer = CommentSerializer(data=data)
     if serializer.is_valid(raise_exception=True):
         with transaction.atomic():
             comment = serializer.save()
             comment.moment.comment.add(comment)
             comment.moment.modify_comment_total()
             mm_Notice.add_notice(comment.moment, comment,
                                  Action.ACTION_TYPE_ADD_COMMENT)
             mm_CustomerPoint.add_action(
                 request.session['customer_id'],
                 mm_CustomerPoint.Action_Add_Comment)
         return Response(Tool.format_data(msg=messages.ADD_COMMENT_OK))
Example #17
0
    def post(self, request, *args, **kwargs):
        data = request.data.dict()
        comment = self.get_object()
        data['moment_id'] = comment.moment_id
        data['from_customer_id'] = request.session['customer_id']
        data['to_customer_id'] = comment.from_customer_id
        if comment.from_customer_id == data['from_customer_id']:  # 自己回复自己当做新评论
            data['reply_to_id'] = None
        else:
            data['reply_to_id'] = kwargs['pk']

        serializer = CommentSerializer(data=data)
        if serializer.is_valid(raise_exception=True):
            with transaction.atomic():
                comment = serializer.save()
                comment.moment.comment.add(comment)
                comment.moment.modify_comment_total()
                mm_Notice.add_notice(comment.moment, comment,
                                     Action.ACTION_TYPE_ADD_REPLY)
            return Response(Tool.format_data(msg=messages.REPLY_COMMENT_OK))
Example #18
0
 def create(self, request, *args, **kwargs):
     data = request.data.dict()
     topics_str = data.pop('topics', '')
     topic_list = []
     if topics_str:
         topic_tags = re.findall(r'#.*?#', topics_str)
         for tag in topic_tags:
             name = tag.replace('#', '')
             topic = mm_Topic.get_toptics(name, request.user.customer.id,
                                          request.user.id)
             topic_list.append(topic)
         data['topic'] = topic_list
     data['customer_id'] = request.user.customer.id
     serializer = MomentsCreateSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     moment = serializer.save()
     mm_CustomerPoint.add_action(request.session['customer_id'],
                                 mm_CustomerPoint.Action_Add_Moment)
     for t in topic_list:
         moment.topic.add(t)
     return Response(Tool.format_data(serializer.data))
Example #19
0
 def get(self, request):
     data = {'unread_count': self._get_unread_count()}
     return Response(Tool.format_data(data))
Example #20
0
 def update(self, request, *args, **kwargs):
     notice = self.get_object()
     notice.status = NoticeStatus.STATUS_READ
     notice.save()
     return Response(Tool.format_data())
Example #21
0
 def get(self, request):
     logout(request)
     return Response(Tool.format_data(), status=status.HTTP_200_OK)
Example #22
0
 def delete(self, request, format=None):
     customer_id = request.query_params.get('customer_id', 0)
     request.user.customer.remove_relationship(customer_id)
     return Response(Tool.format_data())
Example #23
0
 def delete(self, request, *args, **kwargs):
     with transaction.atomic():
         like = self.get_object()
         like.moment.modify_like_total(-1)
         like.delete()
         return Response(Tool.format_data(msg=messages.DELETE_LIKE_OK))
Example #24
0
 def destroy(self, request, *args, **kwargs):
     obj = self.get_object()
     IMServe.leave_group(request.user.customer.id, obj.id)
     return Response(Tool.format_data(msg=messages.LEAVE_GROUP_OK))
Example #25
0
 def retrieve(self, request, *args, **kwargs):
     obj = self.get_object()
     IMServe.join_group(request.user.customer.id, obj.id, obj.name)
     return Response(Tool.format_data(msg=messages.JOIN_GROUP_OK))