コード例 #1
0
 def get(self, request):
     """
     获取用户的所有接收单
     :param request:
     :return:
     """
     try:
         user = getUser(request.session.get('login'))
         ago = request.GET.get('ago')
         page = request.GET.get('page')
         three_month_ago = get_three_month_ago()
         if ago:
             tailwindTake = TailwindTakeOrder.objects.filter(
                 Q(mandatory=user)
                 & Q(create_time__lte=three_month_ago)  # 小于等于这个时间
             )
         else:
             tailwindTake = TailwindTakeOrder.objects.filter(
                 Q(mandatory=user)
                 & Q(create_time__gte=three_month_ago)  # 大于等于这个时间
             )
         takeList = paginator(tailwindTake, page)
         tailwindTakeOrder = [model_to_dict(tl, exclude='end_time') for tl in takeList]
         return JsonResponse({
             'status': True,
             'takeOrder': tailwindTakeOrder,
             'has_next': takeList.has_next(),
             'has_previous': takeList.has_previous()
         })
     except Exception as ex:
         return JsonResponse({
             'status': False,
             'errMsg': '错误信息:' + str(ex)
         }, status=403)
コード例 #2
0
 def get(self, request, rid):
     """
     获取聊天室的内容
     :param request:
     :param rid:
     :return:
     """
     try:
         chatRoom = ChatRoom.objects.filter(chatRoomID=rid)
         if not chatRoom.exists():
             return JsonResponse({
                 'status': False,
                 'errMsg': '聊天室不存在'
             }, status=404)
         chatRoom = chatRoom[0]
         chat_room_chat_log = ChatLog.objects.filter(related_chat_room=chatRoom)
         log_result = [model_to_dict(cl) for cl in chat_room_chat_log]
         return JsonResponse({
             'status': True,
             'log': log_result
         })
     except Exception as ex:
         return JsonResponse({
             'status': False,
             'errMsg': '错误信息:' + str(ex)
         }, status=403)
コード例 #3
0
ファイル: requestInfo.py プロジェクト: DICKQI/UTime_BackEnd
 def get(self, request, tid):
     """
     获取请求单详情
     :param request:
     :param tid:
     :return:
     """
     try:
         tailwind_request = TailwindRequest.objects.filter(requestID=tid)
         if not tailwind_request.exists():
             return JsonResponse({
                 'status': False,
                 'errMsg': '请求单不存在'
             }, status=404)
         tailwind_request = tailwind_request[0]
         result = model_to_dict(tailwind_request)
         return JsonResponse({
             'status': True,
             'detail': result
         })
     except Exception as ex:
         return JsonResponse({
             'status': False,
             'errMsg': '错误信息:' + str(ex)
         })
コード例 #4
0
ファイル: requestInfo.py プロジェクト: DICKQI/UTime_BackEnd
    def post(self, request):
        """
        搜索发起单
        :param request:
        :return:
        """
        try:
            jsonParams = json.loads((request.body).decode('utf-8'))
            search_field = jsonParams.get('search_field')

            search_field = commonWordsTranslate(search_field)
            print(search_field)

            result = TailwindRequest.objects.filter(
                (Q(beginPlace__contains=search_field) |
                 Q(endPlace__contains=search_field))
                # & Q(beginTime__day=datetime.datetime.now())  # 只筛选今天的
            )
            searchResult = [model_to_dict(re, fields=self.INCLUDE_FIELDS) for re in result if re.status == 'paid']
            return JsonResponse({
                'status': True,
                # 'count': result.count,
                'searchResult': searchResult
            })
        except Exception as ex:
            return JsonResponse({
                'status': False,
                'errMsg': '错误信息:' + str(ex)
            })
コード例 #5
0
    def get(self, request):
        '''
        获取发起单列表
        :param request:
        :return:
        '''
        try:
            page = request.GET.get('page')
            requestObj = TailwindRequest.objects.filter(status='paid')
            requestList = paginator(requestObj, page)

            requestOrder = [
                model_to_dict(re, fields=self.INCLUDE_FIELDS)
                for re in requestList
            ]
            if request.session.get('login'):
                '''用户已登录,个性化设置'''
                requestOrder = priority_list(requestOrder, request)

            return JsonResponse({
                'status': True,
                'TailwindRequest': requestOrder,
                'has_previous': requestList.has_previous(),
                'has_next': requestList.has_next()
            })

        except Exception as ex:
            return JsonResponse({
                'status': False,
                'errMsg': str(ex)
            },
                                status=403)
コード例 #6
0
 def get(self, request):
     """
     获得用户发起的订单
     :param request:
     :return:
     """
     try:
         user = getUser(email=request.session.get('login'))
         page = request.GET.get('page')
         ago = request.GET.get('ago')
         types = request.GET.get('type')
         three_month_ago = get_three_month_ago()
         type_list = [
             'unpaid', 'paid', 'orderT', 'waitR', 'accomplish', 'cancel'
         ]
         if not types:  # 没有对应的url参数,查询全部类型的
             types = type_list
         elif types not in type_list:  # 参数不合法
             types = ['unpaid']
         else:  # 参数合法,查询对应类型
             types = [types]
         if ago:
             # 获取三个月前的订单
             tailwindObj = TailwindRequest.objects.filter(
                 Q(initiator=user)
                 & Q(beginTime__lte=three_month_ago)
                 & Q(status__in=types))
         else:
             # 获取三个月内的
             tailwindObj = TailwindRequest.objects.filter(
                 Q(initiator=user)
                 & Q(beginTime__gte=three_month_ago)
                 & Q(status__in=types))
         tailwindList = paginator(tailwindObj, page)
         tailwind = [
             model_to_dict(t, fields=self.COMMON_FIELDS)
             for t in tailwindList
         ]
         return JsonResponse({
             'status': True,
             'tailwind': tailwind,
             'has_next': tailwindList.has_next(),
             'has_previous': tailwindList.has_previous()
         })
     except Exception as ex:
         return JsonResponse({
             'status': False,
             'errMsg': '错误信息:' + str(ex)
         },
                             status=403)
コード例 #7
0
 def get(self, request, uid=0):
     '''
     用户主页(用户详细信息)
     :param request:
     :param uid:
     :return:
     '''
     if uid == 0:
         # 查看自己的信息
         user = getUser(request.session.get('login'))
         MYSELF_FIELDS = [
             'RealName', 'age', 'joined_date', 'TimesOfTake', 'TimesOfRequest'
         ]
         self.INCLUDE_FIELDS += MYSELF_FIELDS
     else:
         # 查看他人的信息(同时获取发起订单的列表)
         user = UserInfo.objects.filter(id=uid)
         if not user.exists():
             return JsonResponse({
                 'status': False,
                 'errMsg': '用户不存在'
             }, status=404)
         user = user[0]
     userInformation = model_to_dict(user, fields=self.INCLUDE_FIELDS)
     for i in user.roles:
         if i[0] == user.user_role:
             userInformation['role'] = i[1]
             break
     if user.head_portrait:
         userInformation['head_portrait'] = 'https://freetime-oss.oss-cn-shenzhen.aliyuncs.com/media/' + str(
             user.head_portrait)
     else:
         userInformation['head_portrait'] = False
     return JsonResponse({
         'status': True,
         'information': userInformation
     })