當前位置: 首頁>>代碼示例>>Python>>正文


Python HQUserType.all方法代碼示例

本文整理匯總了Python中corehq.apps.reports.models.HQUserType.all方法的典型用法代碼示例。如果您正苦於以下問題:Python HQUserType.all方法的具體用法?Python HQUserType.all怎麽用?Python HQUserType.all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在corehq.apps.reports.models.HQUserType的用法示例。


在下文中一共展示了HQUserType.all方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_all_users_by_domain

# 需要導入模塊: from corehq.apps.reports.models import HQUserType [as 別名]
# 或者: from corehq.apps.reports.models.HQUserType import all [as 別名]
def get_all_users_by_domain(domain=None, group=None, user_ids=None,
                            user_filter=None, simplified=False, CommCareUser=None, include_inactive=False):
    """
        WHEN THERE ARE A LOT OF USERS, THIS IS AN EXPENSIVE OPERATION.
        Returns a list of CommCare Users based on domain, group, and user 
        filter (demo_user, admin, registered, unknown)
    """
    user_ids = user_ids if user_ids and user_ids[0] else None
    if not CommCareUser:
        from corehq.apps.users.models import CommCareUser

    if group:
        # get all the users only in this group and don't bother filtering.
        if not isinstance(group, Group):
            group = Group.get(group)
        users = group.get_users(is_active=(not include_inactive), only_commcare=True)
    elif user_ids is not None:
        try:
            users = [CommCareUser.get_by_user_id(id) for id in user_ids]
        except Exception:
            users = []
        if users and users[0] is None:
            raise Http404()
    else:
        if not user_filter:
            user_filter = HQUserType.all()
        users = []
        submitted_user_ids = get_all_userids_submitted(domain)
        registered_user_ids = dict([(user.user_id, user) for user in CommCareUser.by_domain(domain)])
        if include_inactive:
            registered_user_ids.update(dict([(u.user_id, u) for u in CommCareUser.by_domain(domain, is_active=False)]))
        for user_id in submitted_user_ids:
            if user_id in registered_user_ids and user_filter[HQUserType.REGISTERED].show:
                user = registered_user_ids[user_id]
                users.append(user)
            elif not user_id in registered_user_ids and \
                 (user_filter[HQUserType.ADMIN].show or
                  user_filter[HQUserType.DEMO_USER].show or
                  user_filter[HQUserType.UNKNOWN].show):
                username = get_username_from_forms(domain, user_id)
                temp_user = TempCommCareUser(domain, username, user_id)
                if user_filter[temp_user.filter_flag].show:
                    users.append(temp_user)
        if user_filter[HQUserType.UNKNOWN].show:
            users.append(TempCommCareUser(domain, '*', None))

        if user_filter[HQUserType.REGISTERED].show:
            # now add all the registered users who never submitted anything
            for user_id in registered_user_ids:
                if not user_id in submitted_user_ids:
                    user = CommCareUser.get_by_user_id(user_id)
                    users.append(user)

    if simplified:
        return [_report_user_dict(user) for user in users]
    return users
開發者ID:aristide,項目名稱:commcare-hq,代碼行數:58,代碼來源:util.py

示例2: report_context

# 需要導入模塊: from corehq.apps.reports.models import HQUserType [as 別名]
# 或者: from corehq.apps.reports.models.HQUserType import all [as 別名]
 def report_context(self):
     context = super(CaseReassignmentInterface, self).report_context
     active_users = self.get_all_users_by_domain(user_filter=tuple(HQUserType.all()), simplified=True)
     context.update(
         users=[dict(ownerid=user.user_id, name=user.username_in_report, type="user")
                for user in active_users],
         groups=[dict(ownerid=group.get_id, name=group.name, type="group")
                 for group in self.all_case_sharing_groups],
         user_ids=self.user_ids,
     )
     return context
開發者ID:saketkanth,項目名稱:commcare-hq,代碼行數:13,代碼來源:interfaces.py


注:本文中的corehq.apps.reports.models.HQUserType.all方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。