当前位置: 首页>>代码示例>>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;未经允许,请勿转载。