Esempio n. 1
0
def update_user_groups(request, domain, couch_user_id):
    form = MultipleSelectionForm(request.POST)
    form.fields['selected_ids'].choices = [(id, 'throwaway') for id in Group.ids_by_domain(domain)]
    if form.is_valid():
        user = CommCareUser.get(couch_user_id)
        assert user.doc_type == "CommCareUser"
        assert user.domain == domain
        user.set_groups(form.cleaned_data['selected_ids'])
        messages.success(request, _("User groups updated!"))
    else:
        messages.error(request, _("Form not valid. A group may have been deleted while you were viewing this page"
                                  "Please try again."))
    return HttpResponseRedirect(reverse(EditCommCareUserView.urlname, args=[domain, couch_user_id]))
Esempio n. 2
0
def update_user_groups(request, domain, couch_user_id):
    form = MultipleSelectionForm(request.POST)
    form.fields['selected_ids'].choices = [(id, 'throwaway') for id in Group.ids_by_domain(domain)]
    if form.is_valid():
        user = CommCareUser.get(couch_user_id)
        assert user.doc_type == "CommCareUser"
        assert user.domain == domain
        user.set_groups(form.cleaned_data['selected_ids'])
        messages.success(request, _("User groups updated!"))
    else:
        messages.error(request, _("Form not valid. A group may have been deleted while you were viewing this page"
                                  "Please try again."))
    return HttpResponseRedirect(reverse(EditCommCareUserView.urlname, args=[domain, couch_user_id]))
Esempio n. 3
0
def update_group_membership(request, domain, group_id):
    group = Group.get(group_id)
    if group.domain != domain:
        return HttpResponseForbidden()

    form = MultipleSelectionForm(request.POST)
    form.fields['selected_ids'].choices = [(id, 'throwaway') for id in CommCareUser.ids_by_domain(domain)]
    if form.is_valid():
        group.users = form.cleaned_data['selected_ids']
        group.save()
        messages.success(request, _("Group %s updated!") % group.name)
    else:
        messages.error(request, _("Form not valid. A user may have been deleted while you were viewing this page"
                                  "Please try again."))
    return HttpResponseRedirect(reverse("group_members", args=[domain, group_id]))
Esempio n. 4
0
def update_group_membership(request, domain, group_id):
    group = Group.get(group_id)
    if group.domain != domain:
        return HttpResponseForbidden()

    form = MultipleSelectionForm(request.POST)
    form.fields['selected_ids'].choices = [(id, 'throwaway') for id in CommCareUser.ids_by_domain(domain)]
    if form.is_valid():
        group.users = form.cleaned_data['selected_ids']
        group.save()
        messages.success(request, _("Group %s updated!") % group.name)
    else:
        messages.error(request, _("Form not valid. A user may have been deleted while you were viewing this page"
                                  "Please try again."))
    return HttpResponseRedirect(reverse("group_members", args=[domain, group_id]))
Esempio n. 5
0
 def group_form(self):
     form = MultipleSelectionForm(initial={
         'selected_ids': [g._id for g in self.groups],
     })
     form.fields['selected_ids'].choices = [(g._id, g.name)
                                            for g in self.all_groups]
     return form
Esempio n. 6
0
 def user_selection_form(self):
     form = MultipleSelectionForm(initial={
         'selected_ids': list(self.member_ids),
     })
     form.fields['selected_ids'].choices = [
         (u['user_id'], u['username_in_report']) for u in self.all_users
     ]
     return form
Esempio n. 7
0
    def products_form(self):
        if (self.location.location_type_object.administrative
                or not toggles.PRODUCTS_PER_LOCATION.enabled(
                    self.request.domain)):
            return None

        form = MultipleSelectionForm(
            initial={'selected_ids': self.products_at_location},
            submit_label=_("Update Product List"),
            prefix="products",
        )
        form.fields['selected_ids'].choices = self.all_products
        return form