Exemple #1
0
def commcare_users(request, domain, template="users/commcare_users.html"):
    show_inactive = json.loads(request.GET.get('show_inactive', 'false'))
    sort_by = request.GET.get('sortBy', 'abc')
    cannot_share = json.loads(request.GET.get('cannot_share', 'false'))
    show_more_columns = request.GET.get('show_more_columns') is not None
    context = _users_context(request, domain)
    if cannot_share:
        users = CommCareUser.cannot_share(domain)
    else:
        users = CommCareUser.by_domain(domain)
        if show_inactive:
            users.extend(CommCareUser.by_domain(domain, is_active=False))

    if sort_by == 'forms':
        users.sort(key=lambda user: -user.form_count)

    context.update({
        'commcare_users': users,
        'groups': Group.get_case_sharing_groups(domain),
        'show_case_sharing': request.project.case_sharing_included(),
        'show_inactive': show_inactive,
        'cannot_share': cannot_share,
        'show_more_columns': show_more_columns or cannot_share,
    })
    return render_to_response(request, template, context)
Exemple #2
0
    def users(self):
        if self.query:
            return self.users_from_es

        if self.cannot_share:
            users = CommCareUser.cannot_share(self.domain, limit=self.users_list_limit, skip=self.users_list_skip)
        else:
            users = CommCareUser.by_domain(
                self.domain, is_active=not self.show_inactive, limit=self.users_list_limit, skip=self.users_list_skip
            )
        if self.sort_by == "forms":
            users.sort(key=lambda user: -user.form_count)
        return users
Exemple #3
0
    def users(self):
        if self.query:
            return self.users_from_es

        if self.cannot_share:
            users = CommCareUser.cannot_share(self.domain,
                                              limit=self.users_list_limit,
                                              skip=self.users_list_skip)
        else:
            users = CommCareUser.by_domain(self.domain,
                                           is_active=not self.show_inactive,
                                           limit=self.users_list_limit,
                                           skip=self.users_list_skip)
        if self.sort_by == 'forms':
            users.sort(key=lambda user: -user.form_count)
        return users
Exemple #4
0
def user_list(request, domain):
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', DEFAULT_USER_LIST_LIMIT))
    skip = (page-1)*limit

    sort_by = request.GET.get('sortBy', 'abc')

    more_columns = json.loads(request.GET.get('more_columns', 'false'))
    cannot_share = json.loads(request.GET.get('cannot_share', 'false'))
    show_inactive = json.loads(request.GET.get('show_inactive', 'false'))

    if cannot_share:
        users = CommCareUser.cannot_share(domain, limit=limit, skip=skip)
    else:
        users = CommCareUser.by_domain(domain, is_active=not show_inactive, limit=limit, skip=skip)

    if sort_by == 'forms':
        users.sort(key=lambda user: -user.form_count)

    users_list = []
    for user in users:
        user_data = dict(
            user_id=user.user_id,
            status="" if user.is_active else "Archived",
            edit_url=reverse('commcare_user_account', args=[domain, user.user_id]),
            username=user.raw_username,
            full_name=user.full_name,
            joined_on=user.date_joined.strftime("%d %b %Y"),
            phone_numbers=user.phone_numbers,
            form_count="--",
            case_count="--",
            case_sharing_groups=[],
        )
        if more_columns:
            user_data.update(
                form_count=user.form_count,
                case_count=user.case_count,
            )
            if request.project.case_sharing_included():
                user_data.update(
                    case_sharing_groups=[g.name for g in user.get_case_sharing_groups()]
                )
        if request.couch_user.can_edit_commcare_user:
            if user.is_active:
                archive_action_desc = "As a result of archiving, this user will no longer " \
                                      "appear in reports. This action is reversable; you can " \
                                      "reactivate this user by viewing Show Archived Mobile Workers and " \
                                      "clicking 'Unarchive'."
            else:
                archive_action_desc = "This will re-activate the user, and the user will show up in reports again."
            user_data.update(
                archive_action_text="Archive" if user.is_active else "Un-Archive",
                archive_action_url=reverse('%s_commcare_user' % ('archive' if user.is_active else 'unarchive'),
                    args=[domain, user.user_id]),
                archive_action_desc=archive_action_desc,
                archive_action_complete=False,
            )
        users_list.append(user_data)

    return HttpResponse(json.dumps(dict(
        success=True,
        current_page=page,
        users_list=users_list,
    )))