def new_space(request): """ Display form for space **Context** space form **Template:** :template:`form_new_space.html` """ if request.method == 'POST': spaceUid = Space.objects.get(uid=request.POST.get('space')) space = Space(uid=uuid1(), name=request.POST.get('name'), description=request.POST.get('description'), type=request.POST.get('type'), status=1, parent=spaceUid) space.save() spaceUser = SpaceUser(uid=uuid1(), rights=owner_default_rights(), space=space, user=request.user) spaceUser.save() new_space_users_id = request.POST.get('new_space_users_id') if new_space_users_id: for user_id in new_space_users_id: spaceUser = SpaceUser(uid=uuid1(), rights=user_default_rights(), space=space, user=User.objects.get(id=user_id)) spaceUser.save() context = {'result': 'Success', 'space': str(space.uid)} else: context = None return HttpResponse(json.dumps(context), content_type="application/json")
def test_user_see_child_01(self): user = User() user.save() child = Space() child.save() space_user = SpaceUser() self.assertFalse(user_see_child(user, space_user, child))
def create_embigo_space(): emgibo_space = Space( uid='00000000-0000-0000-0000-000000000000', name='embigo', type=1, status=1, ) emgibo_space.save()
def test_get_space_user_or_none(self): space = Space() space.save() user = User() user.save() self.assertEqual(get_space_user_or_none(user, space), None) space_user = SpaceUser(user=user, space=space) space_user.save() self.assertEqual(get_space_user_or_none(user, space), space_user)
def test_get_space_user(self): space = Space() space.save() user = User() user.save() with self.assertRaises(SpaceUser.DoesNotExist): get_space_user(user, space) space_user = SpaceUser(user=user, space=space) space_user.save() self.assertEqual(get_space_user_or_none(user, space), space_user)
def test_user_see_child_02(self): user = User() user.save() parent = Space() parent.save() child = Space(type=1) child.parent = parent child.save() space_user = SpaceUser() space_user.user = user space_user.space = parent space_user.save() self.assertTrue(user_see_child(user, space_user, child))