def get(self): jsonResponse = {"status":"failed"} all_districts = District.all().fetch(100) all_districts_json = [] for district in all_districts: all_districts_json.append({ "id": str(district.key()), "district_name" : str(district.district_name) }) all_schools = School.all().fetch(100) all_schools_json = [] for school in all_schools: all_schools_json.append({"id" : str(school.key()), "school_name" : str(school.school_name) }) all_teachers = Teacher.all().fetch(100) all_teachers_json = [] for teacher in all_teachers: all_teachers_json.append({"id" : str(teacher.key()), "teacher_name" : str(teacher.teacher_name) }) all_ngo_partners = NGOPartner.all().fetch(100) all_ngo_partners_json = [] for ngo_partner in all_ngo_partners: all_ngo_partners_json.append({"id" : str(ngo_partner.key()), "ngo_partner_name" : str(ngo_partner.ngo_partner_name) }) jsonResponse['all_districts_json'] = all_districts_json jsonResponse['all_schools_json'] = all_schools_json jsonResponse['all_teachers_json'] = all_teachers_json jsonResponse['all_ngo_partners_json'] = all_ngo_partners_json jsonResponse['status'] = 'success' response_str = json.dumps(jsonResponse) logging.info(response_str); self.response.out.write(response_str)
def get(self): batch_id = self.request.get('batch_id') response_str = "Failure" try: resource_name = self.request.get('resource_name') _res = HTTPClient_GAE().doGET("http://localhost:8082/data/"+resource_name) _data_json_str = _res.content _data_json = json.loads(_data_json_str) batch_data = _data_json[batch_id] data_processed = 0 total_data = 0 if( batch_data != None ): total_data = batch_data.__len__() for data in batch_data: try: model_class = import_class("db.Models."+batch_id)() logging.info("data : "+str(data)) for k in data : v = data[k] if( k == "school_district"): v = District.all().filter("district_name = ", v).get() elif( k == "school"): v = School.all().filter("school_name = ", v).get() elif( k == "ngo_partner"): v = NGOPartner.all().filter("ngo_partner_name = ", v).get() elif( k == "teacher"): v = Teacher.all().filter("teacher_name = ", v).get() elif ( k == "related_chapter" ): v = Chapters.all().filter("chapter_id = ", v).get() elif ( k == "related_class"): v = ClassIndicator.all().filter("class_name = ", v).get() setattr(model_class, k, v) model_class.put() data_processed = data_processed + 1 except: logging.error("Some Exception in LoadStaticDataHandler user_route_id: "+str(sys.exc_type)+" | "+str(sys.exc_info())+" | "+str(formatException())); response_str = "Done with LoadStaticDataHandler Result: batch id: %s | total : %s | Success: %s " %(batch_id, total_data, data_processed) except: logging.error("Some Exception in LoadStaticDataHandler: "+str(sys.exc_type)+" | "+str(sys.exc_info())+" | "+str(formatException())); logging.info(response_str); self.response.out.write(response_str)