Пример #1
0
    def handle(self, *args, **options):
        self.stdin = options.get('stdin', sys.stdin)  # Used for testing
        start_time = time.time()
        self.stdout.write("Loading Health Facilities...")
        data = json.load(self.stdin)

        if data:
            hfModel.objects.all().delete()
        instances = []

        for d in data["features"]:
            try:
                if d["properties"]["statename"] == 'Kano':
                    a = hfModel(
                        id=int(d["properties"]["id"]),
                        wardname=d["properties"]["wardname"],
                        wardcode=d["properties"]["wardcode"],
                        lganame=d["properties"]["lganame"],
                        lgacode=int(d["properties"]["lgacode"]),
                        zonename=d["properties"]["zone"],
                        statename=d["properties"]["statename"],
                        source=d["properties"]["source"],
                        ownership=d["properties"]["ownership"],
                        category=d["properties"]["category"],
                        primary_name=d["properties"]["primary_name"],
                        hthfa_code=d["properties"]["hthfa_code"],
                        hthfa_code_slug=slugify(d["properties"]["hthfa_code"]),
                        masterlist_type=d["properties"]["masterlist_type"],
                        point=Point(d["geometry"]["coordinates"])
                    )
                    instances.append(a)
            except KeyError as keyErrDesc:
                AppExceptionsModel.objects.create(modelName='1', exceptionText=str(keyErrDesc)+str(d["properties"]["id"]), )
        hfModel.objects.bulk_create(instances)
        # using bulk_create have one minus. In case of IntegrityError happen whole data set will be rollback.
        # catching this should go via logs for custom command tasks
        self.stdout.write("Health Facilities loaded in %s seconds." % (time.time() - start_time))
Пример #2
0
def hfs_load():
    from cycu.models_cycu import hfModel
    hm = hfModel()
    hm.createHfs()
Пример #3
0
def bulk_hfs_load():
    from cycu.models_cycu import hfModel
    hm = hfModel()
    hm.bulkCreateHfs()