Esempio n. 1
0
 def rows(self):
     def numcell(text, value=None):
         if value is None:
             try:
                 value = int(text)
                 if math.isnan(value):
                     text = '---'
             except ValueError:
                 value = text
         return util.format_datatables_data(text=text, sort_key=value)
     all_stats = _all_domain_stats()
     domains = self.get_domains()
     for domain in domains:
         dom = getattr(domain, 'name', domain) # get the domain name if domains is a list of domain objects
         yield [
             getattr(domain, 'hr_name', dom), # get the hr_name if domain is a domain object
             numcell(dom_calc("mobile_users", dom)),
             numcell(all_stats["commcare_users"][dom]),
             numcell(dom_calc("cases_in_last", dom, 120)),
             numcell(all_stats["cases"][dom]),
             numcell(all_stats["forms"][dom]),
             dom_calc("first_form_submission", dom),
             dom_calc("last_form_submission", dom),
             numcell(all_stats["web_users"][dom]),
         ]
Esempio n. 2
0
def calculated_properties(request, domain):
    calc_tag = request.GET.get("calc_tag", '').split('--')
    extra_arg = calc_tag[1] if len(calc_tag) > 1 else ''
    calc_tag = calc_tag[0]

    if not calc_tag or calc_tag not in CALC_FNS.keys():
        data = {"error": 'This tag does not exist'}
    else:
        data = {"value": dom_calc(calc_tag, domain, extra_arg)}
    return json_response(data)
Esempio n. 3
0
def calculated_properties(request, domain):
    calc_tag = request.GET.get("calc_tag", '').split('--')
    extra_arg = calc_tag[1] if len(calc_tag) > 1 else ''
    calc_tag = calc_tag[0]

    if not calc_tag or calc_tag not in list(CALC_FNS):
        data = {"error": 'This tag does not exist'}
    else:
        data = {"value": dom_calc(calc_tag, domain, extra_arg)}
    return json_response(data)