def handle(self, *groupnames, **options): self.all = options.get('all', False) if self.all: print "Enabling sharing for all groups..." enable_sharing() gs = Group.objects.all() for g in gs: enable_sharing(g) print " [DONE]", g.name return if len(groupnames) > 0: print "Enabling sharing for %s groups.." % len(groupnames) enable_sharing() for gname in groupnames: try: g = Group.objects.get(name=gname) enable_sharing(g) print " [DONE]", gname except Exception as e: print " [FAILED]", gname print " ", e return enable_sharing() print """
def setUp(self): kml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures/public_layers.kml') # Create 3 users self.password = '******' self.user1 = User.objects.create_user('user1', '*****@*****.**', password=self.password) self.user2 = User.objects.create_user('user2', '*****@*****.**', password=self.password) self.user3 = User.objects.create_user('user3', '*****@*****.**', password=self.password) # Create some groups # Group 1 has user1 and user2 and can share features self.group1 = Group.objects.create(name="Test Group 1") self.group1.save() self.user1.groups.add(self.group1) self.user2.groups.add(self.group1) enable_sharing(self.group1) path = os.path.dirname(os.path.abspath(__file__)) f = File(open(kml_path)) settings.MEDIA_URL = '' # User1 creates Layer1 and shares with Group1 self.layer1 = TestUserKml.objects.create(user=self.user1) self.layer1.save() self.layer1.kml_file.save('layer1.kml', f) self.layer1.save() self.layer1.share_with(self.group1) # User2 creates Layer2 and doesnt share (the selfish bastard) self.layer2 = TestUserKml.objects.create(user=self.user2) self.layer2.save() self.layer2.kml_file.save('layer2.kml', f) self.layer2.save()
def setUp(self): self.client = Client() self.user = User.objects.create_user("featuretest", "*****@*****.**", password="******") self.options = Stand.get_options() self.create_url = self.options.get_create_form() self.stand1 = Stand(user=self.user, name="My Stand", geometry_orig=g1) self.stand1.save() self.stand1_form_url = self.options.get_update_form(self.stand1.pk) self.stand1_url = self.stand1.get_absolute_url() enable_sharing()
def setUp(self): self.client = Client() self.user = User.objects.create_user( 'featuretest', '*****@*****.**', password='******') self.options = Stand.get_options() self.create_url = self.options.get_create_form() self.stand1 = Stand(user=self.user, name="My Stand", geometry_orig=g1) self.stand1.save() self.stand1_form_url = self.options.get_update_form(self.stand1.pk) self.stand1_url = self.stand1.get_absolute_url() enable_sharing()
def setUp(self): self.client = Client() import_rasters() self.user = User.objects.create_user("featuretest", "*****@*****.**", password="******") self.baduser = User.objects.create_user("baduser", "*****@*****.**", password="******") self.stand1 = Stand(user=self.user, name="My Stand", geometry_orig=g1) self.stand1.save() self.stand2 = Stand(user=self.user, name="My Stand2", geometry_orig=g1) self.stand2.save() self.prop1 = ForestProperty(user=self.user, name="My Property", geometry_final=p1) self.prop1.save() self.prop1.add(self.stand1) enable_sharing()
def setUp(self): self.client = Client() import_rasters() self.user = User.objects.create_user( 'featuretest', '*****@*****.**', password='******') self.baduser = User.objects.create_user( 'baduser', '*****@*****.**', password='******') self.stand1 = Stand(user=self.user, name="My Stand", geometry_orig=g1) self.stand1.save() self.stand2 = Stand(user=self.user, name="My Stand2", geometry_orig=g1) self.stand2.save() self.prop1 = ForestProperty(user=self.user, name="My Property", geometry_final=p1) self.prop1.save() self.prop1.add(self.stand1) enable_sharing()
def setUp(self): enable_sharing() self.user1 = User.objects.create_user( 'user1', '*****@*****.**', password='******') self.user2 = User.objects.create_user( 'user2', '*****@*****.**', password='******') self.mpa1 = TestMpa(user=self.user1, name="My Mpa") self.mpa1.save() self.folder1 = TestFolder(user=self.user1, name="My Folder") self.folder1.save() self.mpa1.add_to_collection(self.folder1) self.tif_url = reverse("heatmap-collection-geotiff", kwargs={'collection_uids': self.folder1.uid}) self.kmz_url = reverse("heatmap-collection-kmz", kwargs={'collection_uids': self.folder1.uid})
def setUp(self): self.client = Client() self.other_client = Client() self.password = '******' self.user = User.objects.create_user('kmltest', '*****@*****.**', password=self.password) self.user2 = User.objects.create_user('kmltest2', '*****@*****.**', password=self.password) g1 = GEOSGeometry('SRID=4326;POLYGON ((-120.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))') g2 = GEOSGeometry('SRID=4326;POLYGON ((-121.42 34.37, -120.64 34.32, -120.63 34.12, -121.44 34.15, -121.42 34.37))') g3 = GEOSGeometry('SRID=4326;POLYGON ((-122.42 34.37, -121.64 34.32, -121.63 34.12, -122.44 34.15, -122.42 34.37))') g1.transform(settings.GEOMETRY_DB_SRID) g2.transform(settings.GEOMETRY_DB_SRID) g3.transform(settings.GEOMETRY_DB_SRID) self.mpa1 = Mpa.objects.create(name='Test_MPA_1', user=self.user, geometry_final=g1) self.mpa2 = Mpa.objects.create(name=u'Test_MPA_2_with_some_uniçode', user=self.user, geometry_final=g2) self.mpa3 = Mpa.objects.create(name='Test_MPA_3', user=self.user, geometry_final=g3) self.mpa1.save() self.mpa2.save() self.mpa3.save() self.array1 = MpaArray.objects.create(name='Test_Array_1', user=self.user) self.array1.save() self.mpa1.add_to_collection(self.array1) self.mpa2.add_to_collection(self.array1) # Then make the group with permissions self.group1 = Group.objects.create(name="Test Group 1") self.group1.save() enable_sharing(self.group1) # Add users to group self.user.groups.add(self.group1) self.user2.groups.add(self.group1) # Share with common group self.array1.share_with(self.group1) # Share with public public_group = Group.objects.filter(name__in=settings.SHARING_TO_PUBLIC_GROUPS)[0] self.user.groups.add(public_group) self.array1.share_with(public_group)
def setUp(self): self.client = Client() # Create 3 users self.password = '******' self.user = User.objects.create_user('user1', '*****@*****.**', password=self.password) self.user2 = User.objects.create_user('user2', '*****@*****.**', password=self.password) self.group1 = Group.objects.create(name="Test Group 1") self.group1.save() self.user.groups.add(self.group1) self.user2.groups.add(self.group1) enable_sharing(self.group1) self.public = Group.objects.get(name=settings.SHARING_TO_PUBLIC_GROUPS[0]) self.user.groups.add(self.public) # Create some necessary objects g1 = GEOSGeometry('SRID=4326;POLYGON((-120.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))') g1.transform(settings.GEOMETRY_DB_SRID) # Create 3 Mpas by different users mpa1 = TestMpa.objects.create(name='Test_MPA_1', designation='R', user=self.user, geometry_orig=g1) mpa1.save() mpa2 = TestMpa.objects.create(name='Test_MPA_2', designation='P', user=self.user, geometry_orig=g1) mpa2.save() mpa3 = TestMpa.objects.create(name='Test_MPA_3', designation='C', user=self.user, geometry_orig=g1) mpa3.save() self.mpa_ids = [mpa1.pk, mpa2.pk, mpa3.pk] self.mpa_uids = ['%s_%s' % (mpa1.model_uid(), x) for x in self.mpa_ids] # User1 adds mpa to an array array1 = TestArray.objects.create(name='Test_Array_1', user=self.user) array1.save() array2 = TestArray.objects.create(name='Test_Array_2', user=self.user) array2.save() mpa1.add_to_collection(array1) mpa2.add_to_collection(array2) array1.share_with(self.group1) array2.share_with(self.public) self.array_ids = [array1.pk, array2.pk] self.array_uids = ['%s_%s' % (array1.model_uid(), x) for x in self.array_ids]
def setUp(self): enable_sharing() self.user1 = User.objects.create_user('user1', '*****@*****.**', password='******') self.user2 = User.objects.create_user('user2', '*****@*****.**', password='******') self.mpa1 = TestMpa(user=self.user1, name="My Mpa") self.mpa1.save() self.folder1 = TestFolder(user=self.user1, name="My Folder") self.folder1.save() self.mpa1.add_to_collection(self.folder1) self.tif_url = reverse("heatmap-collection-geotiff", kwargs={'collection_uids': self.folder1.uid}) self.kmz_url = reverse("heatmap-collection-kmz", kwargs={'collection_uids': self.folder1.uid})
def setUp(self): self.client = Client() import_rasters() self.user = User.objects.create_user("featuretest", "*****@*****.**", password="******") self.stand1 = Stand(user=self.user, name="My Stand 1", geometry_orig=g1) self.stand1.save() self.stand2 = Stand(user=self.user, name="My Stand 2", geometry_orig=g1) self.stand2.save() self.stand3 = Stand(user=self.user, name="My Stand 3 (not on property)", geometry_orig=g1) self.stand3.save() self.prop1 = ForestProperty(user=self.user, name="My Property", geometry_final=p1) self.prop1.save() self.prop1.add(self.stand1) self.prop1.add(self.stand2) self.options = Scenario.get_options() self.create_url = self.options.get_create_form() self.rx1 = Rx.objects.get(internal_name=self.prop1.variant.code + "1").id self.rx2 = Rx.objects.get(internal_name=self.prop1.variant.code + "2").id enable_sharing()
def setUp(self): self.client = Client() import_rasters() self.user = User.objects.create_user( 'featuretest', '*****@*****.**', password='******') self.stand1 = Stand(user=self.user, name="My Stand 1", geometry_orig=g1) self.stand1.save() self.stand2 = Stand(user=self.user, name="My Stand 2", geometry_orig=g1) self.stand2.save() self.stand3 = Stand(user=self.user, name="My Stand 3 (not on property)", geometry_orig=g1) self.stand3.save() self.prop1 = ForestProperty(user=self.user, name="My Property", geometry_final=p1) self.prop1.save() self.prop1.add(self.stand1) self.prop1.add(self.stand2) self.options = Scenario.get_options() self.create_url = self.options.get_create_form() self.rx1 = Rx.objects.get(internal_name=self.prop1.variant.code + "1").id self.rx2 = Rx.objects.get(internal_name=self.prop1.variant.code + "2").id enable_sharing()
def setUp(self): self.client = Client() self.user = User.objects.create_user("featuretest", "*****@*****.**", password="******") enable_sharing()
def setUp(self): self.client = Client() # Create 3 users self.password = '******' self.user = User.objects.create_user('user1', '*****@*****.**', password=self.password) self.user2 = User.objects.create_user('user2', '*****@*****.**', password=self.password) self.group1 = Group.objects.create(name="Test Group 1") self.group1.save() self.user.groups.add(self.group1) self.user2.groups.add(self.group1) enable_sharing(self.group1) self.public = Group.objects.get( name=settings.SHARING_TO_PUBLIC_GROUPS[0]) self.user.groups.add(self.public) # Create some necessary objects g1 = GEOSGeometry( 'SRID=4326;POLYGON((-120.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))' ) g1.transform(settings.GEOMETRY_DB_SRID) # Create 3 Mpas by different users mpa1 = TestMpa.objects.create(name='Test_MPA_1', designation='R', user=self.user, geometry_orig=g1) mpa1.save() mpa2 = TestMpa.objects.create(name='Test_MPA_2', designation='P', user=self.user, geometry_orig=g1) mpa2.save() mpa3 = TestMpa.objects.create(name='Test_MPA_3', designation='C', user=self.user, geometry_orig=g1) mpa3.save() self.mpa_ids = [mpa1.pk, mpa2.pk, mpa3.pk] self.mpa_uids = ['%s_%s' % (mpa1.model_uid(), x) for x in self.mpa_ids] # User1 adds mpa to an array array1 = TestArray.objects.create(name='Test_Array_1', user=self.user) array1.save() array2 = TestArray.objects.create(name='Test_Array_2', user=self.user) array2.save() mpa1.add_to_collection(array1) mpa2.add_to_collection(array2) array1.share_with(self.group1) array2.share_with(self.public) self.array_ids = [array1.pk, array2.pk] self.array_uids = [ '%s_%s' % (array1.model_uid(), x) for x in self.array_ids ]
def setUp(self): self.client = Client() self.user = User.objects.create_user( 'featuretest', '*****@*****.**', password='******') enable_sharing()
def main(): user = User.objects.get(username='******') for model in [Shipwreck, Pipeline, Mpa, Folder, Array]: a = model.objects.all() for i in a: i.delete() g3 = GEOSGeometry('SRID=4326;POINT(-120.45 34.32)') g3.transform(settings.GEOMETRY_DB_SRID) wreck1 = Shipwreck(user=user, name="Wreck 1", geometry_orig=g3) wreck1.save() g3 = GEOSGeometry('SRID=4326;POINT(-120.85 34.82)') g3.transform(settings.GEOMETRY_DB_SRID) wreck2 = Shipwreck(user=user, name="Wreck 2", geometry_orig=g3) wreck2.save() g2 = GEOSGeometry('SRID=4326;LINESTRING(-120.42 34.37, -121.42 33.37)') g2.transform(settings.GEOMETRY_DB_SRID) pipeline1 = Pipeline(user=user, name="Pipeline 1", geometry_orig=g2) pipeline1.save() g2 = GEOSGeometry('SRID=4326;LINESTRING(-121.42 34.37, -122.42 33.37)') g2.transform(settings.GEOMETRY_DB_SRID) pipeline2 = Pipeline(user=user, name="Pipeline 2", geometry_orig=g2) pipeline2.save() g1 = GEOSGeometry( 'SRID=4326;POLYGON((-120.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))' ) g1.transform(settings.GEOMETRY_DB_SRID) mpa1 = Mpa(user=user, name="Mpa1", geometry_orig=g1) # geometry_final will be set with manipulator mpa1.save() g1 = GEOSGeometry( 'SRID=4326;POLYGON((-121.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -121.42 34.37))' ) g1.transform(settings.GEOMETRY_DB_SRID) mpa2 = Mpa(user=user, name="Mpa2", geometry_orig=g1) # geometry_final will be set with manipulator mpa2.save() g1 = GEOSGeometry( 'SRID=4326;POLYGON((-120.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))' ) print dir(g1) g1.transform(settings.GEOMETRY_DB_SRID) mpa3 = Mpa(user=user, name="Mpa3", geometry_orig=g1) # geometry_final will be set with manipulator mpa3.save() folder1 = Folder(user=user, name="Folder1") folder1.save() folder2 = Folder(user=user, name="Folder2") folder2.save() folder3 = Folder(user=user, name="Folder3") folder3.save() array1 = Array(user=user, name="Array1") array1.save() array2 = Array(user=user, name="Array2") array2.save() mpa1.add_to_collection(array1) mpa2.add_to_collection(array2) array1.add_to_collection(folder1) wreck1.add_to_collection(folder1) pipeline1.add_to_collection(folder1) folder3.add_to_collection(folder2) #### try: user2 = User.objects.get(username="******") except: user2 = User.objects.create_user('user2', '*****@*****.**', password='******') try: group1 = Group.objects.get(name="Group1") except: group1 = Group.objects.create(name="Group1") group1.save() user.groups.add(group1) user2.groups.add(group1) enable_sharing(group1) group2 = Group.objects.get(name=settings.SHARING_TO_PUBLIC_GROUPS[0]) user.groups.add(group2) enable_sharing folder1.share_with(group2) #### g1 = GEOSGeometry( 'SRID=4326;POLYGON((-120.42 34.37, -119.24 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))' ) g1.transform(settings.GEOMETRY_DB_SRID) mpa4 = Mpa(user=user2, name="Mpa4", geometry_orig=g1) mpa4.save() folder4 = Folder(user=user2, name="Folder4") folder4.save() array4 = Array(user=user2, name="Array4") array4.save() mpa4.add_to_collection(array4) array4.add_to_collection(folder4) folder4.share_with(group1)
def main(): user = User.objects.get(username='******') for model in [Shipwreck, Pipeline, Mpa, Folder, Array]: a = model.objects.all() for i in a: i.delete() g3 = GEOSGeometry('SRID=4326;POINT(-120.45 34.32)') g3.transform(settings.GEOMETRY_DB_SRID) wreck1 = Shipwreck(user=user, name="Wreck 1", geometry_orig=g3) wreck1.save() g3 = GEOSGeometry('SRID=4326;POINT(-120.85 34.82)') g3.transform(settings.GEOMETRY_DB_SRID) wreck2 = Shipwreck(user=user, name="Wreck 2", geometry_orig=g3) wreck2.save() g2 = GEOSGeometry('SRID=4326;LINESTRING(-120.42 34.37, -121.42 33.37)') g2.transform(settings.GEOMETRY_DB_SRID) pipeline1 = Pipeline(user=user, name="Pipeline 1", geometry_orig=g2) pipeline1.save() g2 = GEOSGeometry('SRID=4326;LINESTRING(-121.42 34.37, -122.42 33.37)') g2.transform(settings.GEOMETRY_DB_SRID) pipeline2 = Pipeline(user=user, name="Pipeline 2", geometry_orig=g2) pipeline2.save() g1 = GEOSGeometry('SRID=4326;POLYGON((-120.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))') g1.transform(settings.GEOMETRY_DB_SRID) mpa1 = Mpa(user=user, name="Mpa1", geometry_orig=g1) # geometry_final will be set with manipulator mpa1.save() g1 = GEOSGeometry('SRID=4326;POLYGON((-121.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -121.42 34.37))') g1.transform(settings.GEOMETRY_DB_SRID) mpa2 = Mpa(user=user, name="Mpa2", geometry_orig=g1) # geometry_final will be set with manipulator mpa2.save() g1 = GEOSGeometry('SRID=4326;POLYGON((-120.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))') print dir(g1) g1.transform(settings.GEOMETRY_DB_SRID) mpa3 = Mpa(user=user, name="Mpa3", geometry_orig=g1) # geometry_final will be set with manipulator mpa3.save() folder1 = Folder(user=user, name="Folder1") folder1.save() folder2 = Folder(user=user, name="Folder2") folder2.save() folder3 = Folder(user=user, name="Folder3") folder3.save() array1 = Array(user=user, name="Array1") array1.save() array2 = Array(user=user, name="Array2") array2.save() mpa1.add_to_collection(array1) mpa2.add_to_collection(array2) array1.add_to_collection(folder1) wreck1.add_to_collection(folder1) pipeline1.add_to_collection(folder1) folder3.add_to_collection(folder2) #### try: user2 = User.objects.get(username="******") except: user2 = User.objects.create_user('user2', '*****@*****.**', password='******') try: group1 = Group.objects.get(name="Group1") except: group1 = Group.objects.create(name="Group1") group1.save() user.groups.add(group1) user2.groups.add(group1) enable_sharing(group1) group2 = Group.objects.get(name=settings.SHARING_TO_PUBLIC_GROUPS[0]) user.groups.add(group2) enable_sharing folder1.share_with(group2) #### g1 = GEOSGeometry('SRID=4326;POLYGON((-120.42 34.37, -119.24 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))') g1.transform(settings.GEOMETRY_DB_SRID) mpa4 = Mpa(user=user2, name="Mpa4", geometry_orig=g1) mpa4.save() folder4 = Folder(user=user2, name="Folder4") folder4.save() array4 = Array(user=user2, name="Array4") array4.save() mpa4.add_to_collection(array4) array4.add_to_collection(folder4) folder4.share_with(group1)