def get_active_asc_report(request): '''get city and state from parameter''' data = request.GET.copy() if data.has_key('month') and data.has_key('month') : month = MONTHS.index(data['month']) + 1 year = data['year'] else: now = datetime.datetime.now() year = now.year month = now.month data_list = [] asc_details = utils.get_asc_data(data) active_asc_list = asc_details.filter(~Q(date_joined=F('last_login'))) active_ascs = active_asc_list.values_list('username', flat=True) asc_obj = models.AuthorizedServiceCenter.objects.filter(asc_id__in=active_ascs) for asc_data in asc_obj: active_ascs = OrderedDict(); active_ascs['id'] = asc_data.asc_id active_ascs['address'] = asc_data.address active_ascs = utils.get_state_city(active_ascs, asc_data.address) active_ascs['coupon_closed'] = utils.asc_cuopon_details(asc_data, 2, year, month) active_ascs['total_coupon_closed'] = utils.total_coupon_closed(active_ascs['coupon_closed']) data_list.append(active_ascs) no_of_days = utils.get_number_of_days(year, month) years = utils.gernate_years() return render(request, 'portal/asc_report.html',\ {"data": data_list, "range": range(1, no_of_days), "month": MONTHS, "years": years, "mon": MONTHS[month-1], "cyear": str(year), })
def get_active_asc_report(request, role=None): '''get number of tickets closed by ASC''' if request.method != 'GET': return HttpResponse(json.dumps({"message":"method not allowed"}), content_type="application/json",status=401) try: role = request.path.split('/')[3] data = request.GET.copy() if data.has_key('month'): month = MONTHS.index(data['month']) + 1 year = data['year'] else: now = datetime.datetime.now() year = now.year month = now.month no_of_days = utils.get_number_of_days(year, month) coupon_resource = CouponDataResource() asc_query=coupon_resource.closed_ticket(year, month, role) asc_list = [] for asc in asc_query: active = filter(lambda active: active['id']==asc['asc_id'], asc_list) if not active: temp= {} temp['id'] = asc['asc_id'] temp['name'] = asc['first_name'] temp['address'] = asc['address'] temp['coupon_closed'] = {} for day in range(1, no_of_days): temp['coupon_closed'][day] = 0 day = int(asc['day']) temp['total_coupon_closed'] = 0 temp['coupon_closed'][day]= asc['cnt'] temp['total_coupon_closed'] = temp['total_coupon_closed'] + asc['cnt'] asc_list.append(temp) else: day = int(asc['day']) active[0]['coupon_closed'][day]= asc['cnt'] active[0]['total_coupon_closed'] = active[0]['total_coupon_closed'] + asc['cnt'] except Exception as ex: logger.error('Exception while counting data : {0}'.format(ex)) return HttpResponseBadRequest() years = utils.gernate_years() return render(request, 'portal/asc_report.html',\ {"data": asc_list, "range": range(1, no_of_days), "month": MONTHS, "years": years, "mon": MONTHS[int(month)-1], "cyear": str(year), "role": role })