Ejemplo n.º 1
0
    def handle(self, *args, **options):
        fake = Faker("he_IL")
        images = glob.glob(f"{IMG_PATH}/image*.jpeg")

        try:
            User.objects.create_superuser('sysop', '', 'sysop')
        except IntegrityError:
            pass

        with SAMPLE_PROJECTS_FILE.open(encoding="utf-8") as f:
            for i, proj in enumerate(load_projects(json.load(f))):
                with transaction.atomic():
                    print(proj['slug'])
                    project = Project()
                    project.name = proj['name']
                    project.slug = proj['slug']
                    project.geom = proj['polygon']
                    project.center = proj['polygon'].centroid
                    f = (IMG_PATH / f"logo_{i + 1:04d}.jpeg").open("rb")
                    project.logo_file.save(f"logo{i + 1}.jpeg", File(f))
                    project.save()

                    for _ in range(
                            self.LOCATIONS_PER_PROJECT):
                        location = Location()
                        location.project = project
                        location.name = fake.street_name() + " " + fake.street_name()
                        x0, y0, x1, y1 = project.geom.extent
                        x = random.uniform(x0, x1)
                        y = random.uniform(y0, y1)
                        location.point = Point(x, y)
                        location.information = silly.sentence()
                        location.save()

                        for _ in range(
                                random.randint(0,
                                               self.PHOTOS_PER_LOCATION)):
                            photo = Photo()
                            photo.name = fake.street_name()
                            photo.location = location
                            photo.date_taken = silly.datetime().date()
                            photo.lond_desc = fake.paragraphs(nb=3,
                                                              ext_word_list=None)
                            with open(random.choice(images), "rb") as f:
                                photo.photo_file.save("random.jpg", File(f))
                            photo.save()
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        images = glob.glob(f"{IMG_PATH}/image*.jpeg")

        try:
            User.objects.create_superuser('sysop', '', 'sysop')
        except IntegrityError:
            pass

        with SAMPLE_PROJECTS_FILE.open() as f:
            for i, proj in enumerate(load_projects(json.load(f))):
                with transaction.atomic():
                    print(proj['slug'])
                    project = Project()
                    project.name = proj['name']
                    project.slug = proj['slug']
                    project.geom = proj['polygon']
                    project.center = proj['polygon'].centroid
                    f = (IMG_PATH / f"logo_{i + 1:04d}.jpeg").open("rb")
                    project.logo_file.save(f"logo{i + 1}.jpeg", File(f))
                    project.save()

                    for location_id in range(
                            self.num_of_locations_per_project):
                        location = Location()
                        location.project = project
                        location.name = silly.a_thing()
                        x0, y0, x1, y1 = project.geom.extent
                        x = random.uniform(x0, x1)
                        y = random.uniform(y0, y1)
                        location.point = Point(x, y)
                        location.information = silly.sentence()
                        location.save()

                        for photo_id in range(
                                random.randint(
                                    0, self.num_of_photos_per_location)):
                            photo = Photo()
                            photo.name = silly.a_thing()
                            photo.location = location
                            photo.date_taken = silly.datetime().date()
                            photo.lond_desc = silly.paragraph()
                            with open(random.choice(images), "rb") as f:
                                photo.photo_file.save("random.jpg", File(f))
                            photo.save()