def handler_function(self): args = self.get_request_data() userId = AuthenticationUtil.getUserIdByToken(self.request) startDate, endDate, searchParams = self.getSearchParams(args['search']) orders = None if args['orderListType'] == 'self': searchParams.update({'userId': userId}) orders = DBOps.getSomeDoc(DBCollonfig.orders, searchParams) elif args['orderListType'] == 'company': company = DBOps.getOneDoc( DBCollonfig.users, {'_id': userId}, {'company': 1} )['company'] searchParams.update({'company': company}) orders = DBOps.getSomeDoc(DBCollonfig.orders, searchParams) elif args['orderListType'] == 'summary': orders = DBOps.getSomeDoc(DBCollonfig.orders, searchParams) self.result['result'] = { 'orders': list(orders.sort('createTimeStamp', -1)), 'searchDate': [startDate.split(' ')[0], endDate.split(' ')[0]], 'totalCount': orders.count() } return self.response_success()
def handler_download(self): tableData = self.get_argument('tableDate') tableType = self.get_argument('tableType') filename = tableType + '_' + \ datetime.now().strftime('%Y-%m-%d') + '.csv' searchParams = {} if tableData: startDate = time.strptime(tableData, DATE_FORMAT) endDateList = tableData.split('-') if int(endDateList[1]) + 1 > 12: endDateList[0] = '{0:02}'.format(int(endDateList[0]) + 1) endDateList[1] = '01' else: endDateList[1] = '{0:02}'.format(int(endDateList[1]) + 1) endDate = time.strptime('-'.join(endDateList), DATE_FORMAT) searchParams.update({ 'createTimeStamp': { '$gte': TimeUtil.time_conversion(startDate, 3), '$lte': TimeUtil.time_conversion(endDate, 3) } }) if tableType == 'summaryExpect': searchParams.update({'status': {'$in': [1, 2]}}) elif tableType == 'summaryPayment': searchParams.update({'status': 3}) orders = DBOps.getSomeDoc(DBCollonfig.orders, searchParams) self.initContactsData() self.createToDownload(orders, filename)
def handler_function(self): total = DBOps.getSomeDoc(DBCollonfig.users, {}, {'orders': 0}) userList = [] for user in total: user.update({ 'userId': user['_id'], 'pmsListName': [ UserConfig.permissions[k] for k, v in user['permissions'].iteritems() if v == 1 ] }) userList.append(user) self.result['result'] = OrderUtil.orderListByTime(userList, reverse=False) return self.response_success()