def rows(self):
     rows = []
     for user in CouchUser.by_domain(self.config['domain']):
         if user.user_data.get('role') == 'In Charge' and hasattr(user, 'domain_membership') \
                 and user.domain_membership['location_id'] == self.config['location_id']:
                 rows.append([user.name])
     return rows if rows else [['No data']]
Esempio n. 2
0
def create_usercases(domain_name):
    from corehq.apps.callcenter.sync_usercase import sync_usercase
    if USH_USERCASES_FOR_WEB_USERS.enabled(domain_name):
        users = CouchUser.by_domain(domain_name)
    else:
        users = CommCareUser.by_domain(domain_name)
    for user in users:
        sync_usercase(user, domain_name)
 def rows(self):
     rows = []
     sms_users = FacilitySMSUsers(self.config).rows
     for user in CouchUser.by_domain(self.config['domain']):
         if user.name not in [u[0] for u in sms_users]:
             if hasattr(user, 'domain_membership') \
                     and user.domain_membership['location_id'] == self.config['location_id']:
                 rows.append([user.name, user.get_email()])
     return rows
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError('Usage is sync_couch_users_to_sql %s' % self.args)

        domain = args[0].strip()

        users = CouchUser.by_domain(domain)
        for user in users:
            user.save()
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError('Usage is sync_couch_users_to_sql %s' %
                               self.args)

        domain = args[0].strip()

        users = CouchUser.by_domain(domain)
        for user in users:
            user.save()
Esempio n. 6
0
 def get_rows(self, datespan):
     block = self.block
     q = {
         "query": {
             "filtered": {
                 "query": {"match_all": {}},
                 "filter": {
                     "bool": {
                         "must": [
                             {"term": {"domain.exact": self.domain}},
                             {"term": {"block_name.#value": block.lower()}},
                         ]
                     }
                 },
             }
         }
     }
     es_filters = q["query"]["filtered"]["filter"]
     if self.snapshot is None:
         awcs = self.request.GET.getlist("awcs")
         if awcs:
             awcs_lower = [awc.lower() for awc in awcs]
             awc_term = {
                 "or": [
                     {
                         "and": [
                             {"term": {"awc_name.#value": term}}
                             for term in re.split("\s", awc)
                             if not re.search(r"^\W+$", term) or re.search(r"^\w+", term)
                         ]
                     }
                     for awc in awcs_lower
                 ]
             }
             es_filters["bool"]["must"].append(awc_term)
         gp = self.request_params.get("gp", None)
         if gp:
             users = CouchUser.by_domain(self.domain)
             users_id = [
                 user._id
                 for user in users
                 if "user_data" in user and "gp" in user.user_data and user.user_data["gp"] == gp
             ]
             es_filters["bool"]["must"].append({"terms": {"owner_id": users_id}})
         is_open = self.request_params.get("is_open", None)
         if is_open:
             es_filters["bool"]["must"].append({"term": {"closed": is_open == "closed"}})
     if self.default_case_type:
         es_filters["bool"]["must"].append({"term": {"type.exact": self.default_case_type}})
     logging.info("ESlog: [%s.%s] ESquery: %s" % (self.__class__.__name__, self.domain, simplejson.dumps(q)))
     return es_query(q=q, es_url=REPORT_CASE_INDEX + "/_search", dict_only=False)["hits"].get("hits", [])
Esempio n. 7
0
 def filter(self, fn, filter_fields=None):
     if filter_fields is None:
         filter_fields = [('awc_name', 'awcs'), ('block_name', 'block'), ('owner_id', 'gp'), ('closed', 'is_open')]
     for key, field in filter_fields:
         case_key = fn(key)['#value'] if isinstance(fn(key), dict) else fn(key)
         keys = self.filter_data.get(field, [])
         if keys and field == 'is_open':
             if case_key != (keys == 'closed'):
                 raise InvalidRow
         else:
             if keys and field == 'gp':
                 gps = keys
                 users = CouchUser.by_domain(self.domain)
                 keys = [user._id for user in users if 'user_data' in user and 'gp' in user.user_data and user.user_data['gp'] in gps]
             if keys and case_key not in keys:
                 raise InvalidRow
Esempio n. 8
0
 def get_rows(self, datespan):
     block = self.block
     q = {
         "query": {
             "filtered": {
                 "query": {
                     "match_all": {},
                 },
                 "filter": {
                     "bool": {
                         "must": [
                             {"term": {"domain.exact": self.domain}}
                         ]
                     }
                 }
             }
         }
     }
     es_filters = q["query"]["filtered"]["filter"]
     if self.snapshot is None and hasattr(self, 'request'):
         if self.awcs:
             awcs_lower = [awc.lower() for awc in self.awcs]
             awc_term = {
                 "or":
                     [{"and": [{"term": {"awc_name.#value": term}} for term in re.split('\s', awc)
                                 if not re.search(r'^\W+$', term) or re.search(r'^\w+', term)]
                     } for awc in awcs_lower]
             }
             es_filters["bool"]["must"].append(awc_term)
         elif self.gp:
             users = CouchUser.by_domain(self.domain)
             users_id = [user._id for user in users if 'user_data' in user and 'gp' in user.user_data and user.user_data['gp'] == self.gp]
             es_filters["bool"]["must"].append({"terms": {"owner_id": users_id}})
         elif self.block:
             es_filters["bool"]["must"].append({"term": {"block_name.#value": block.lower()}})
         is_open = self.request_params.get('is_open', None)
         if is_open:
             es_filters["bool"]["must"].append({"term": {"closed": is_open == 'closed'}})
     else:
         es_filters["bool"]["must"].append({"term": {"block_name.#value": block.lower()}})
     if self.default_case_type:
         es_filters["bool"]["must"].append({"term": {"type.exact": self.default_case_type}})
     logging.info("ESlog: [%s.%s] ESquery: %s" % (self.__class__.__name__, self.domain, simplejson.dumps(q)))
     return es_query(q=q, es_url=REPORT_CASE_INDEX + '/_search', dict_only=False)['hits'].get('hits', [])
Esempio n. 9
0
 def get_rows(self, datespan):
     block = self.block
     q = {
         "query": {
             "filtered": {
                 "query": {
                     "match_all": {},
                 },
                 "filter": {
                     "bool": {
                         "must": [
                             {"term": {"domain.exact": self.domain}},
                             {"term": {"block_name.#value": block.lower()}}
                         ]
                     }
                 }
             }
         }
     }
     es_filters = q["query"]["filtered"]["filter"]
     if self.snapshot is None:
         awcs = self.request.GET.getlist('awcs')
         if awcs:
             awcs_lower = [awc.lower() for awc in awcs]
             awc_term = {
                 "or":
                     [{"and": [{"term": {"awc_name.#value": term}} for term in re.split('\s', awc)
                                 if not re.search(r'^\W+$', term) or re.search(r'^\w+', term)]
                     } for awc in awcs_lower]
             }
             es_filters["bool"]["must"].append(awc_term)
         gp = self.request_params.get('gp', None)
         if gp:
             users = CouchUser.by_domain(self.domain)
             users_id = [user._id for user in users if 'user_data' in user and 'gp' in user.user_data and user.user_data['gp'] == gp]
             es_filters["bool"]["must"].append({"terms": {"owner_id": users_id}})
         is_open = self.request_params.get('is_open', None)
         if is_open:
             es_filters["bool"]["must"].append({"term": {"closed": is_open == 'closed'}})
     if self.default_case_type:
         es_filters["bool"]["must"].append({"term": {"type.exact": self.default_case_type}})
     logging.info("ESlog: [%s.%s] ESquery: %s" % (self.__class__.__name__, self.domain, simplejson.dumps(q)))
     return es_query(q=q, es_url=REPORT_CASE_INDEX + '/_search', dict_only=False)['hits'].get('hits', [])
Esempio n. 10
0
 def users(self):
     return CouchUser.by_domain(self.domain) if self.filter_data.get(
         'gp', []) else []
Esempio n. 11
0
 def users(self):
     return CouchUser.by_domain(self.domain) if self.filter_data.get('gp', []) else []
Esempio n. 12
0
 def all_users(self):
     from corehq.apps.users.models import CouchUser
     return CouchUser.by_domain(self.name)
Esempio n. 13
0
 def all_users(self):
     from corehq.apps.users.models import CouchUser
     return CouchUser.by_domain(self.name)
Esempio n. 14
0
 def handle(self, domain, **options):
     users = CouchUser.by_domain(domain)
     for user in users:
         user.save()
 def handle(self, domain, **options):
     users = CouchUser.by_domain(domain)
     for user in users:
         user.save()