示例#1
0
 def test_species_thumbprint(self):
     instance = make_instance()
     add_species_to_instance(instance)
     thumbprint1 = instance.species_thumbprint
     s = Species.objects.get(instance=instance, common_name='Afghan pine')
     s.common_name = 'Afghan pony'
     s.save_with_system_user_bypass_auth()
     thumbprint2 = instance.species_thumbprint
     self.assertNotEqual(thumbprint1, thumbprint2)
示例#2
0
 def test_species_thumbprint(self):
     instance = make_instance()
     add_species_to_instance(instance)
     thumbprint1 = instance.species_thumbprint
     s = Species.objects.get(instance=instance, common_name='Afghan pine')
     s.common_name = 'Afghan pony'
     s.save_with_system_user_bypass_auth()
     thumbprint2 = instance.species_thumbprint
     self.assertNotEqual(thumbprint1, thumbprint2)
示例#3
0
 def test_all_species_added_when_no_itree_region(self):
     instance = make_instance()
     add_species_to_instance(instance)
     self.assertEqual(len(SPECIES), len(instance.species_set.all()))
示例#4
0
 def _assert_right_species_for_region(self, instance):
     add_species_to_instance(instance)
     self.assertNotEqual(len(SPECIES), len(instance.species_set.all()))
     otm_codes = species_codes_for_regions(['NoEastXXX'])
     self.assertEqual(len(otm_codes), len(instance.species_set.all()))
示例#5
0
 def test_all_species_added_when_no_itree_region(self):
     instance = make_instance()
     add_species_to_instance(instance)
     self.assertEqual(len(SPECIES), len(instance.species_set.all()))
示例#6
0
 def _assert_right_species_for_region(self, instance):
     add_species_to_instance(instance)
     self.assertNotEqual(len(SPECIES),
                         len(instance.species_set.all()))
     otm_codes = species_codes_for_regions(['NoEastXXX'])
     self.assertEqual(len(otm_codes), len(instance.species_set.all()))
示例#7
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise Exception(
                'Expected instance name as the first argument')

        name = args[0]

        if not options['user']:
            raise Exception('An admin user must be specified. with "--user"')

        if options.get('center', None) and options.get('geojson', None):
            raise Exception('You must specifiy only one of '
                            '"center" and "geojson"')
        elif (not options.get('center', None) and
              not options.get('geojson', None)):
            raise Exception('You must specifiy at least one of '
                            '"center" and "geojson"')

        if options['center']:
            center = options['center'].split(',')
            if len(center) != 2:
                raise Exception('Center should be a lon,lat pair')

            center_pt = Point(float(center[0]), float(center[1]), srid=4326)

            # Bounding box built in web mercator to have units in meters
            center_pt.transform(3857)
            x = center_pt.x
            y = center_pt.y
            instance_bounds = InstanceBounds.create_from_point(x, y)
        else:
            geom = GEOSGeometry(open(options['geojson'], srid=4326).read())
            instance_bounds = InstanceBounds.objects.create(geom=geom)

        if not options.get('url_name', None):
            raise Exception('You must specify a "url_name" starting with a '
                            'lowercase letter and containing lowercase '
                            'letters, numbers, and dashes ("-")')
        url_name = options.get('url_name')

        instance = Instance(
            config={},
            name=name,
            bounds=instance_bounds,
            is_public=True,
            url_name=url_name)

        instance.seed_with_dummy_default_role()
        instance.full_clean()
        instance.save()

        instance.boundaries = Boundary.objects.filter(
            geom__intersects=instance_bounds.geom)

        role = Role.objects.create(
            name='user', instance=instance, rep_thresh=0,
            default_permission=FieldPermission.WRITE_DIRECTLY)

        create_stewardship_udfs(instance)

        add_species_to_instance(instance)

        add_default_permissions(instance, roles=[role])

        eco_benefits_conversion = \
            BenefitCurrencyConversion.get_default_for_point(Point(x, y))
        if eco_benefits_conversion:
            eco_benefits_conversion.save()

        instance.eco_benefits_conversion = eco_benefits_conversion

        instance.default_role = role
        instance.save()

        user = User.objects.get(username=options['user'])
        InstanceUser(
            instance=instance,
            user=user,
            role=role,
            admin=True).save_with_user(user)
    def handle(self, *args, **options):
        if len(args) != 1:
            raise Exception('Expected instance name as the first argument')

        name = args[0]

        if not options['user']:
            raise Exception('An admin user must be specified. with "--user"')

        if options.get('center', None) and options.get('geojson', None):
            raise Exception('You must specifiy only one of '
                            '"center" and "geojson"')
        elif (not options.get('center', None)
              and not options.get('geojson', None)):
            raise Exception('You must specifiy at least one of '
                            '"center" and "geojson"')

        if options['center']:
            center = options['center'].split(',')
            if len(center) != 2:
                raise Exception('Center should be a lon,lat pair')

            center_pt = Point(float(center[0]), float(center[1]), srid=4326)

            # Bounding box built in web mercator to have units in meters
            center_pt.transform(3857)
            x = center_pt.x
            y = center_pt.y
            instance_bounds = InstanceBounds.create_from_point(x, y)
        else:
            geom = GEOSGeometry(open(options['geojson'], srid=4326).read())
            instance_bounds = InstanceBounds.objects.create(geom=geom)

        if not options.get('url_name', None):
            raise Exception('You must specify a "url_name" starting with a '
                            'lowercase letter and containing lowercase '
                            'letters, numbers, and dashes ("-")')
        url_name = options.get('url_name')

        instance = Instance(config={},
                            name=name,
                            bounds=instance_bounds,
                            is_public=True,
                            url_name=url_name)

        instance.seed_with_dummy_default_role()
        instance.full_clean()
        instance.save()

        instance.boundaries = Boundary.objects.filter(
            geom__intersects=instance_bounds.geom)

        role = Role.objects.create(
            name='user',
            instance=instance,
            rep_thresh=0,
            default_permission_level=FieldPermission.WRITE_DIRECTLY)

        create_stewardship_udfs(instance)

        add_species_to_instance(instance)

        add_default_permissions(instance, roles=[role])
        add_instance_permissions([role])

        eco_benefits_conversion = \
            BenefitCurrencyConversion.get_default_for_instance(instance)
        if eco_benefits_conversion:
            eco_benefits_conversion.save()
            instance.eco_benefits_conversion = eco_benefits_conversion

        instance.default_role = role
        instance.save()

        user = User.objects.get(username=options['user'])
        InstanceUser(instance=instance, user=user, role=role,
                     admin=True).save_with_user(user)