Example #1
0
def display_users(request, obj_ref):
    obj, ctx = get_generic_data(request, "Group", obj_ref)
    if request.method == "POST":
        formset = forms.get_user_formset(obj, request.POST)
        if formset.is_valid():
            obj.update_users(formset)
            return HttpResponseRedirect(".")
    else:
        formset = forms.get_user_formset(obj)
    ctx["user_formset"] = formset
    ctx["pending_invitations"] = obj.invitation_set.filter(
            state=models.Invitation.PENDING)
    ctx['current_page'] = 'users' 
    ctx['in_group'] = bool(request.user.groups.filter(id=obj.id))
    return r2r("groups/users.htm", ctx, request)
Example #2
0
 def test_update_users(self):
     controller = self.CONTROLLER.create("Grp1", "a", self.user, self.DATA)
     user = User.objects.create(username="******", email="dede@test")
     user.groups.add(controller.object)
     user2 = User.objects.create(username="******", email="dede2@test")
     user2.groups.add(controller.object)
     controller.save()
     for u in (self.user, user, user2):
         u.save()
         self.assertTrue(u.groups.filter(id=controller.id))
     data = {
         "form-0-group": controller.id,
         "form-0-user": user.id,
         "form-0-delete": "on",
         "form-0-ORDER": "0",
         "form-1-group": controller.id,
         "form-1-user": user2.id,
         "form-1-ORDER": "1",
         "form-MAX_NUM_FORMS": "",
         "form-TOTAL_FORMS": 2,
         "form-INITIAL_FORMS": 2,
     }
     formset = get_user_formset(controller, data)
     controller.update_users(formset)
     self.assertFalse(user.groups.filter(id=controller.id))
     self.assertTrue(user2.groups.filter(id=controller.id))
     self.assertTrue(self.user.groups.filter(id=controller.id))
Example #3
0
 def test_update_users(self):
     controller = self.CONTROLLER.create("Grp1", "a", self.user, self.DATA)
     user = User.objects.create(username="******", email="dede@test")
     user.groups.add(controller.object)
     user2 = User.objects.create(username="******", email="dede2@test")
     user2.groups.add(controller.object)
     controller.save()
     for u in (self.user, user, user2):
         u.save()
         self.assertTrue(u.groups.filter(id=controller.id))
     data = {
         'form-0-group': controller.id,
         'form-0-user': user.id,
         'form-0-delete': 'on',
         'form-0-ORDER': '0',
         'form-1-group': controller.id,
         'form-1-user': user2.id,
         'form-1-ORDER': '1',
         'form-MAX_NUM_FORMS': '',
         'form-TOTAL_FORMS': 2,
         'form-INITIAL_FORMS': 2,
     }
     formset = get_user_formset(controller, data)
     controller.update_users(formset)
     self.assertFalse(user.groups.filter(id=controller.id))
     self.assertTrue(user2.groups.filter(id=controller.id))
     self.assertTrue(self.user.groups.filter(id=controller.id))
Example #4
0
def display_users(request, obj_ref):
    """
    View of the *user* page of a group.

    """
    obj, ctx = get_generic_data(request, "Group", obj_ref)
    if request.method == "POST":
        formset = forms.get_user_formset(obj, request.POST)
        if formset.is_valid():
            obj.update_users(formset)
            return HttpResponseRedirect(".")
    else:
        formset = forms.get_user_formset(obj)
    ctx["user_formset"] = formset
    ctx["pending_invitations"] = obj.invitation_set.filter(
        state=models.Invitation.PENDING).select_related("guest", "owner")
    ctx['current_page'] = 'users'
    ctx['in_group'] = bool(request.user.groups.filter(id=obj.id))
    return r2r("groups/users.html", ctx, request)