本文整理汇总了Python中accounts.models.Account._get_collection方法的典型用法代码示例。如果您正苦于以下问题:Python Account._get_collection方法的具体用法?Python Account._get_collection怎么用?Python Account._get_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.Account
的用法示例。
在下文中一共展示了Account._get_collection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getAccounts
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import _get_collection [as 别名]
def getAccounts(request, id):
try:
company_id = request.user.company_id
page_number = int(request.GET.get('page_number'))
items_per_page = int(request.GET.get('per_page'))
offset = (page_number - 1) * items_per_page
start_date = int(request.GET.get('start_date'))
end_date = int(request.GET.get('end_date'))
sub_view = request.GET.get('subview')
superfilters = request.GET.get('superfilters')
super_filters = json.loads(superfilters)
#print 'super filters are ' + str(super_filters)
date_field = None
if super_filters is not None:
if 'date_types' in super_filters: # need to filter by a certain type of date
date_field = super_filters['date_types']
if start_date is not None:
utc_day_start_epoch = datetime.fromtimestamp(float(start_date / 1000))
#utc_day_start_epoch = str('{0:f}'.format(utc_day_start_epoch).rstrip('0').rstrip('.'))
print 'utc start epoch is ' + str(utc_day_start_epoch)
#local_start_date = get_current_timezone().localize(local_start_date_naive, is_dst=None)
#print 'start2 is ' + str(time.time())
if end_date is not None:
utc_day_end_epoch = datetime.fromtimestamp(float(end_date / 1000))
#utc_day_end_epoch = str('{0:f}'.format(utc_day_end_epoch).rstrip('0').rstrip('.'))
print 'utc end epoch is ' + str(utc_day_end_epoch)
utc_day_start_string = datetime.strftime(utc_day_start_epoch, '%Y-%m-%dT%H-%M-%S.000+0000')
utc_day_end_string = datetime.strftime(utc_day_end_epoch, '%Y-%m-%dT%H-%M-%S.000+0000')
print 'utc start string is ' + str(utc_day_start_string)
print 'utc end string is ' + str(utc_day_end_string)
result = []
company_field_qry = 'company_id'
#print 'start time was ' + str(time.time())
collection = Account._get_collection()
if date_field is None:
total = collection.find({'company_id': int(company_id)}).count() #.hint('company_id_1')
else:
total = collection.find({'company_id': int(company_id), date_field: {'$gte':utc_day_start_string, '$lte':utc_day_end_string}}).count() #.hint('company_id_1')
if date_field is None:
queryset = Account.objects(company_id=company_id).skip(offset).limit(items_per_page)
else:
date_field_start_qry = date_field + '__gte'
date_field_end_qry = date_field + '__lte'
company_field_qry = 'company_id'
querydict = {company_field_qry: company_id, date_field_start_qry: utc_day_start_string, date_field_end_qry: utc_day_end_string}
queryset = Account.objects(**querydict).skip(offset).limit(items_per_page)
#qlist = list(queryset)
#print 'start time3 was ' + str(time.time())
#total = len(qlist)
#result = qlist[offset:offset+items_per_page]
#print 'start time4 was ' + str(time.time())
for account in queryset:
leadsTemp = []
leads = account['leads']
for lead in leads: # each 'lead' here is an object of type {lead_id_type: lead_id} e.g. {'sfdc_contact_id': 1234}
for k, v in lead.iteritems():
lead_field_qry = k
querydict = {lead_field_qry: v, company_field_qry: company_id}
qset = Lead.objects(**querydict).only('source_first_name').only('source_last_name').only('id').first()
#print 'qset ' + str(qset)
#qset_actual_lead_list_temp = [qset_lead.to_mongo().to_dict() for qset_lead in qset]
#for qset_actual_lead in qset_actual_lead_list_temp:
leadsTemp.append(qset)
account['leads'] = leadsTemp
result.append(account)
#result.sort(key=lambda account:len(account.leads))
#print 'qset is ' + str(qlist)
#print 'start time5 was ' + str(time.time())
serializer = AccountSerializer(result, many=True)
#print 'start time6 was ' + str(time.time())
type = 'accounts'
return JsonResponse({'count' : total, 'results': serializer.data, 'type': type})
except Exception as e:
print 'exception while getting all accounts ' + str(e)
return JsonResponse({'Error' : str(e)})