Exemplo n.º 1
0
def add_commcare_account(request,
                         domain,
                         template="users/add_commcare_account.html"):
    """
    Create a new commcare account
    """
    context = _users_context(request, domain)
    if request.method == "POST":
        form = CommCareAccountForm(request.POST)
        form.password_format = request.project.password_format()
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]

            couch_user = CommCareUser.create(domain,
                                             username,
                                             password,
                                             device_id='Generated from HQ')
            couch_user.save()
            return HttpResponseRedirect(
                reverse("user_account", args=[domain, couch_user.userID]))
    else:
        form = CommCareAccountForm()
    context.update(form=form)
    context.update(only_numeric=(request.project.password_format() == 'n'))
    return render(request, template, context)
Exemplo n.º 2
0
def group_membership(request,
                     domain,
                     couch_user_id,
                     template="groups/groups.html"):
    context = _users_context(request, domain)
    couch_user = CouchUser.get_by_user_id(couch_user_id, domain)
    if request.method == "POST" and 'group' in request.POST:
        group = request.POST['group']
        group.add_user(couch_user)
        group.save()
        #messages.success(request, '%s joined group %s' % (couch_user.username, group.name))

    my_groups = Group.by_user(couch_user_id)
    all_groups = _get_sorted_groups(domain)
    other_groups = []
    for group in all_groups:
        if group.get_id not in [g.get_id for g in my_groups]:
            other_groups.append(group)
            #other_groups = [group for group in all_groups if group not in my_groups]
    context.update({
        "domain": domain,
        "groups": my_groups,
        "other_groups": other_groups,
        "couch_user": couch_user
    })
    return render(request, template, context)
Exemplo n.º 3
0
def group_members(request,
                  domain,
                  group_id,
                  template="groups/group_members.html"):
    context = _users_context(request, domain)
    all_groups = _get_sorted_groups(domain)
    try:
        group = Group.get(group_id)
    except ResourceNotFound:
        raise Http404("Group %s does not exist" % group_id)
    member_ids = group.get_user_ids()
    members = CouchUser.view("_all_docs", keys=member_ids,
                             include_docs=True).all()
    members.sort(key=lambda user: user.username)
    all_users = CommCareUser.by_domain(domain)
    member_ids = set(member_ids)
    nonmembers = [user for user in all_users if user.user_id not in member_ids]

    context.update({
        "domain": domain,
        "group": group,
        "all_groups": all_groups,
        "members": members,
        "nonmembers": nonmembers,
    })
    return render(request, template, context)
Exemplo n.º 4
0
def all_groups(request, domain, template="groups/all_groups.html"):
    context = _users_context(request, domain)
    all_groups = _get_sorted_groups(domain)
    context.update({
        'domain': domain,
        'all_groups': all_groups
    })
    return render(request, template, context)
Exemplo n.º 5
0
def add_commcare_account(request, domain, template="users/add_commcare_account.html"):
    """
    Create a new commcare account
    """
    context = _users_context(request, domain)
    if request.method == "POST":
        form = CommCareAccountForm(request.POST)
        form.password_format = request.project.password_format()
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]

            couch_user = CommCareUser.create(domain, username, password, device_id='Generated from HQ')
            couch_user.save()
            return HttpResponseRedirect(reverse("user_account", args=[domain, couch_user.userID]))
    else:
        form = CommCareAccountForm()
    context.update(form=form)
    context.update(only_numeric=(request.project.password_format() == 'n'))
    return render(request, template, context)
Exemplo n.º 6
0
def group_members(request, domain, group_id, template="groups/group_members.html"):
    context = _users_context(request, domain)
    all_groups = _get_sorted_groups(domain)
    group = Group.get(group_id)
    if group is None:
        raise Http404("Group %s does not exist" % group_id)
    member_ids = group.get_user_ids()
    members = CouchUser.view("_all_docs", keys=member_ids, include_docs=True).all()
    members.sort(key=lambda user: user.username)
    all_users = CommCareUser.by_domain(domain)
    member_ids = set(member_ids)
    nonmembers = [user for user in all_users if user.user_id not in member_ids]

    context.update({"domain": domain,
                    "group": group,
                    "all_groups": all_groups,
                    "members": members,
                    "nonmembers": nonmembers,
                    })
    return render(request, template, context)
Exemplo n.º 7
0
def group_membership(request, domain, couch_user_id, template="groups/groups.html"):
    context = _users_context(request, domain)
    couch_user = CouchUser.get_by_user_id(couch_user_id, domain)
    if request.method == "POST" and 'group' in request.POST:
        group = request.POST['group']
        group.add_user(couch_user)
        group.save()
        #messages.success(request, '%s joined group %s' % (couch_user.username, group.name))
    
    my_groups = Group.by_user(couch_user_id)
    all_groups = _get_sorted_groups(domain)
    other_groups = []
    for group in all_groups:
        if group.get_id not in [g.get_id for g in my_groups]:
            other_groups.append(group)
            #other_groups = [group for group in all_groups if group not in my_groups]
    context.update({"domain": domain,
                    "groups": my_groups,
                    "other_groups": other_groups,
                    "couch_user":couch_user })
    return render(request, template, context)
Exemplo n.º 8
0
def base_view(request, domain, template="users/mobile/users_list.html"):
    page = request.GET.get('page', 1)
    limit = request.GET.get('limit', DEFAULT_USER_LIST_LIMIT)

    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'))

    total = CommCareUser.total_by_domain(domain, is_active=not show_inactive)

    context = _users_context(request, domain)
    context.update(users_list=dict(
        page=page,
        limit=limit,
        total=total,
    ),
                   cannot_share=cannot_share,
                   show_inactive=show_inactive,
                   more_columns=more_columns,
                   show_case_sharing=request.project.case_sharing_included(),
                   pagination_limit_options=range(DEFAULT_USER_LIST_LIMIT, 51,
                                                  DEFAULT_USER_LIST_LIMIT))
    return render(request, template, context)
Exemplo n.º 9
0
def base_view(request, domain, template="users/mobile/users_list.html"):
    page = request.GET.get('page', 1)
    limit = request.GET.get('limit', DEFAULT_USER_LIST_LIMIT)

    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'))

    total = CommCareUser.total_by_domain(domain, is_active=not show_inactive)

    context = _users_context(request, domain)
    context.update(
        users_list=dict(
            page=page,
            limit=limit,
            total=total,
        ),
        cannot_share=cannot_share,
        show_inactive=show_inactive,
        more_columns=more_columns,
        show_case_sharing=request.project.case_sharing_included(),
        pagination_limit_options=range(DEFAULT_USER_LIST_LIMIT, 51, DEFAULT_USER_LIST_LIMIT)
    )
    return render(request, template, context)
Exemplo n.º 10
0
 def get_context_data(self, **kwargs):
     """TemplateView automatically calls this to render the view (on a get)"""
     context = _users_context(self.request, self.domain)
     context["show_secret_settings"] = self.request.REQUEST.get("secret", False)
     return context
Exemplo n.º 11
0
def all_groups(request, domain, template="groups/all_groups.html"):
    context = _users_context(request, domain)
    all_groups = _get_sorted_groups(domain)
    context.update({'domain': domain, 'all_groups': all_groups})
    return render(request, template, context)