def get(self, request, *args, **kwargs): org = request.org partner_id = request.GET.get("partner") non_partner = str_to_bool(self.request.GET.get("non_partner", "")) with_activity = str_to_bool( self.request.GET.get("with_activity", "")) if non_partner: users = org.administrators.all() elif partner_id: users = Partner.objects.get(org=org, pk=partner_id).get_users() else: users = org.get_users() users = list(users.order_by("profile__full_name")) # get reply statistics if with_activity: replies_total = TotalCount.get_by_user( org, users, DailyCount.TYPE_REPLIES).scope_totals() replies_this_month = DailyCount.get_by_user( org, users, DailyCount.TYPE_REPLIES, *month_range(0)).scope_totals() replies_last_month = DailyCount.get_by_user( org, users, DailyCount.TYPE_REPLIES, *month_range(-1)).scope_totals() cases_total = TotalCount.get_by_user( org, users, DailyCount.TYPE_CASE_OPENED).scope_totals() cases_opened_this_month = DailyCount.get_by_user( org, users, DailyCount.TYPE_CASE_OPENED, *month_range(0)).scope_totals() cases_closed_this_month = DailyCount.get_by_user( org, users, DailyCount.TYPE_CASE_CLOSED, *month_range(0)).scope_totals() def as_json(user): obj = user.as_json(full=True, org=org) if with_activity: obj.update({ "replies": { "this_month": replies_this_month.get(user, 0), "last_month": replies_last_month.get(user, 0), "total": replies_total.get(user, 0), }, "cases": { "opened_this_month": cases_opened_this_month.get(user, 0), "closed_this_month": cases_closed_this_month.get(user, 0), "total": cases_total.get(user, 0), }, }) return obj return JsonResponse({"results": [as_json(u) for u in users]})
def get_summary(self, org, user): return { "total_replies": DailyCount.get_by_user(org, [user], DailyCount.TYPE_REPLIES, None, None).total() }
def get(self, request, *args, **kwargs): org = request.org partner_id = request.GET.get('partner') non_partner = str_to_bool(self.request.GET.get('non_partner', '')) with_activity = str_to_bool( self.request.GET.get('with_activity', '')) if non_partner: users = org.administrators.all() elif partner_id: users = Partner.objects.get(org=org, pk=partner_id).get_users() else: users = org.get_users() users = list(users.order_by('profile__full_name')) # get reply statistics if with_activity: replies_total = DailyCount.get_by_user(org, users, DailyCount.TYPE_REPLIES, None, None).scope_totals() replies_this_month = DailyCount.get_by_user( org, users, DailyCount.TYPE_REPLIES, *month_range(0)).scope_totals() replies_last_month = DailyCount.get_by_user( org, users, DailyCount.TYPE_REPLIES, *month_range(-1)).scope_totals() cases_total = DailyCount.get_by_user( org, users, DailyCount.TYPE_CASE_OPENED, None, None).scope_totals() cases_opened_this_month = DailyCount.get_by_user( org, users, DailyCount.TYPE_CASE_OPENED, *month_range(0)).scope_totals() cases_closed_this_month = DailyCount.get_by_user( org, users, DailyCount.TYPE_CASE_CLOSED, *month_range(0)).scope_totals() def as_json(user): obj = user.as_json(full=True, org=org) if with_activity: obj.update({ 'replies': { 'this_month': replies_this_month.get(user, 0), 'last_month': replies_last_month.get(user, 0), 'total': replies_total.get(user, 0) }, 'cases': { 'opened_this_month': cases_opened_this_month.get(user, 0), 'closed_this_month': cases_closed_this_month.get(user, 0), 'total': cases_total.get(user, 0) }, }) return obj return JsonResponse({'results': [as_json(u) for u in users]})