def insti_map(request, name=None): """Prerender for map thumbnails.""" # Filter with str_id location = Location.objects.filter(reusable=True, str_id=name).first() # Create dummy if we found nothing if not location: location = Location() location.id = 'default' location.name = "place" location.str_id = None location.short_name = "Map" # (Ugly) Add slash to start of str id to display in URL location.str_id = ('/%s' % location.str_id) if location.str_id else '' # Render the response rendered = render_to_string( 'map.html', { 'loc': location, 'image_url': '%s%smap/%s.jpg' % (settings.STATIC_BASE_URL, settings.STATIC_URL, location.id), 'settings': settings, }) return HttpResponse(rendered)
def generate_location(): location = Location() location.name = random.choice(location_names) addr = random.choice(location_addrs) location.address = addr[0] location.city = addr[1] location.state = addr[2] location.zip_code = addr[3] location.save() return location
def zapis(): hovno = find() print hovno for h in hovno: location = Location() location.name = h[0] location.lat = h[1] location.lng = h[2] location.address = h[3] location.category = '4d4b7105d754a06374d81259' location.save() print "Created"
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()
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()