示例#1
0
def load_towns(town_names=None):
	relocation_csv_file = os.path.join(BASE_DIR, "regions", "relocated_town_load.csv")
	with open(relocation_csv_file, 'r') as csv_open:
		csv_records = csv.DictReader(csv_open)

		for record in csv_records:
			if not record["name"]:  # basically, if we're at the end, on a blank line
				continue

			if town_names and not record["name"] in town_names:  # allows us to run this and specify a name of the town to load in order to go one by one
				processing_log.debug("Skipping town {0:s}".format(record["name"]))
				continue

			processing_log.info("Loading New Town: {0:s}".format(record["name"]))
			town = RelocatedTown()
			region = Region.objects.get(short_name=record["region_short_name"])  # get the region object

			for key in record.keys():
				record[key] = record[key].replace("{{BASE_DIR}}", BASE_DIR)  # replace the base directory in the paths

			try:
				town.relocation_setup(record["name"], record["short_name"], before=record["before_boundary"],
									  after=record["after_boundary"],before_structures=record["before_structures"],
									  after_structures=record["moved_structures"], unfilt_before=record["unfiltered_before_structures"],
									  unfilt_after=record["unfiltered_moved_structures"], region=region, make_boundaries_from_structures=True,
									  exclude_old_town=False)
				town.save()

				town.process_for_calibration()

			except:
				if town.id is not None:
					town.delete()  # if we have an exception, delete the town object in the database to reduce clutter
				six.reraise(*sys.exc_info())
def relocated_town_load():
	relocation_csv_file = os.path.join(BASE_DIR, "regions", "relocated_town_load.csv")
	with open(relocation_csv_file, 'r') as csv_open:
		csv_records = csv.DictReader(csv_open)

		for record in csv_records:
			town = RelocatedTown()
			region = Region.objects.get(short_name=record["region_short_name"])  # get the region object

			for key in record.keys():
				record[key] = record[key].replace("{{BASE_DIR}}", BASE_DIR)  # replace the base directory in the paths

			town.relocation_setup(record["name"], record["short_name"], record["before_structures"],
								  record["moved_structures"], region, make_boundaries_from_structures=True)
			town.save()

	return  # TODO: THIS IS TEMPORARY
示例#3
0
def relocated_town_load():
    relocation_csv_file = os.path.join(BASE_DIR, "regions",
                                       "relocated_town_load.csv")
    with open(relocation_csv_file, 'r') as csv_open:
        csv_records = csv.DictReader(csv_open)

        for record in csv_records:
            town = RelocatedTown()
            region = Region.objects.get(short_name=record["region_short_name"]
                                        )  # get the region object

            for key in record.keys():
                record[key] = record[key].replace(
                    "{{BASE_DIR}}",
                    BASE_DIR)  # replace the base directory in the paths

            town.relocation_setup(record["name"],
                                  record["short_name"],
                                  record["before_structures"],
                                  record["moved_structures"],
                                  region,
                                  make_boundaries_from_structures=True)
            town.save()

    return  # TODO: THIS IS TEMPORARY