def add_danhmuc_dantoc(): try: SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) json_url_dantoc = os.path.join(SITE_ROOT, "application/data", "DanTocEnum.json") data_dantoc = json.load(open(json_url_dantoc)) for item_dantoc in data_dantoc: check_dantoc = db.session.query(DanToc).filter(DanToc.ma == str(item_dantoc["value"])).first() if check_dantoc is None: dantoc = DanToc(ma = str(item_dantoc["value"]), ten = item_dantoc["text"]) dantoc.tenkhongdau = convert_text_khongdau(dantoc.ten) db.session.add(dantoc) db.session.commit() except Exception as e: print("DAN TOC ERROR", e)
def add_danhmuc_quanhuyen(): try: SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) json_url_dsquanhuyen = os.path.join(SITE_ROOT, "application/data", "ThongTinTinhThanh.json") data_dsquanhuyen = json.load(open(json_url_dsquanhuyen)) for item_dsquanhuyen in data_dsquanhuyen: quanhuyen_filter = db.session.query(QuanHuyen).filter(QuanHuyen.ma == item_dsquanhuyen["maquanhuyen"]).first() if quanhuyen_filter is None: tinhthanh_filter = db.session.query(TinhThanh).filter(TinhThanh.ma == item_dsquanhuyen["matinhthanh"]).first() quanhuyen_filter = QuanHuyen(ten = item_dsquanhuyen["tenquanhuyen"], ma = item_dsquanhuyen["maquanhuyen"], tinhthanh_id = tinhthanh_filter.id) quanhuyen_filter.tenkhongdau = convert_text_khongdau(quanhuyen_filter.ten) db.session.add(quanhuyen_filter) db.session.commit() except Exception as e: print("QUAN HUYEN ERROR", e)
def add_danhmuc_xaphuong(): try: SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) json_url_dsxaphuong = os.path.join(SITE_ROOT, "application/data", "ThongTinTinhThanh.json") data_dsxaphuong = json.load(open(json_url_dsxaphuong)) for item_dsxaphuong in data_dsxaphuong: xaphuong_filter = db.session.query(XaPhuong).filter(XaPhuong.ma == item_dsxaphuong["maxaphuong"]).first() if xaphuong_filter is None: quanhuyen_filter = db.session.query(QuanHuyen).filter(QuanHuyen.ma == item_dsxaphuong["maquanhuyen"]).first() xaphuong_filter = XaPhuong(ten = item_dsxaphuong["tenxaphuong"], ma = item_dsxaphuong["maxaphuong"], quanhuyen_id = quanhuyen_filter.id) xaphuong_filter.tenkhongdau = convert_text_khongdau(xaphuong_filter.ten) db.session.add(xaphuong_filter) db.session.commit() except Exception as e: print("XA PHUONG ERROR", e)
def add_danhmuc_tinhthanh(): try: SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) json_url_dstinhthanh = os.path.join(SITE_ROOT, "application/data", "ThongTinTinhThanh.json") data_dstinhthanh = json.load(open(json_url_dstinhthanh)) for item_dstinhthanh in data_dstinhthanh: tinhthanh_filter = db.session.query(TinhThanh).filter(TinhThanh.ma == item_dstinhthanh["matinhthanh"]).first() if tinhthanh_filter is None: quocgia_filter = db.session.query(QuocGia).filter(QuocGia.ma == 'VN').first() tinhthanh_filter = TinhThanh(ten = item_dstinhthanh["tentinhthanh"], ma = item_dstinhthanh["matinhthanh"], quocgia_id = quocgia_filter.id) tinhthanh_filter.tenkhongdau = convert_text_khongdau(tinhthanh_filter.ten) db.session.add(tinhthanh_filter) db.session.commit() except Exception as e: print("TINH THANH ERROR",e)
def add_tuyendonvi(): #add tuyen don vi from application.config.development import Config app.config.from_object(Config) init_database(app) try: SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) json_url_tuyendonvi = os.path.join(SITE_ROOT, "application/data", "TuyenDonViEnum.json") data_tuyendonvi = json.load(open(json_url_tuyendonvi)) for item_tuyendonvi in data_tuyendonvi: print("tuyendonvi>>>",item_tuyendonvi) tuyendonvi_filter = db.session.query(TuyenDonVi).filter(TuyenDonVi.ma == item_tuyendonvi["value"]).first() if tuyendonvi_filter is None: tuyendonvi = TuyenDonVi() tuyendonvi.id = item_tuyendonvi["value"] tuyendonvi.ma = item_tuyendonvi["value"] tuyendonvi.ten = item_tuyendonvi.get('text', None) tuyendonvi.tenkhongdau = convert_text_khongdau(tuyendonvi.ten) db.session.add(tuyendonvi) db.session.commit() except Exception as e: print("TUYEN DON VI ERROR",e)