def cb(count,ds): school = None try: school = School.objects.get(gsid=ds["universal-id"]) except: school = School() # print "called for num:" + str(count) + "val: " + str(ds) school.name = ds["name"] school.gsid = ds["universal-id"] school.city = ds["city"] if len(ds["zip"]) > 6: ds["zip"] = ds["zip"][:6] school.zip = ds["zip"] school.state = ds["state"] school.lat = ds["lat"] school.lon = ds["lon"] school.gsurl = ds["url"] if len(ds["street"]) > 50: ds["street"] = ds["street"][:49] school.street = ds["street"] if len(ds["level"]) > 20: ds["level"] = ds["level"][:19] school.level = ds["level"] if len(ds["phone"]) > 20: ds["phone"] = ds["phone"][:19] school.phone = ds["phone"] if len(ds["subtype"]) > 50: ds["subtype"] = 'special' school.type = ds["subtype"] if len(ds["district-name"]) > 50: ds["district-name"] = ds["district-name"][:49] school.district_name = ds["district-name"] # try: print school.gsurl school.save()
def add(request): if request.method == "POST": form = request.POST # print(form) # for testing school = School() school.name = form['name'] school.code = form['code'] school.address = form['address'] school.no_of_students = form['no_of_students'] school.save() return redirect('schools:school_detail', school.pk) context = {} return render(request, 'schools/add.html', context)
def cb(count, ds): school = None try: school = School.objects.get(gsid=ds["universal-id"]) except: school = School() # print "called for num:" + str(count) + "val: " + str(ds) school.name = ds["name"] school.gsid = ds["universal-id"] school.city = ds["city"] if len(ds["zip"]) > 6: ds["zip"] = ds["zip"][:6] school.zip = ds["zip"] school.state = ds["state"] school.lat = ds["lat"] school.lon = ds["lon"] school.gsurl = ds["url"] if len(ds["street"]) > 50: ds["street"] = ds["street"][:49] school.street = ds["street"] if len(ds["level"]) > 20: ds["level"] = ds["level"][:19] school.level = ds["level"] if len(ds["phone"]) > 20: ds["phone"] = ds["phone"][:19] school.phone = ds["phone"] if len(ds["subtype"]) > 50: ds["subtype"] = 'special' school.type = ds["subtype"] if len(ds["district-name"]) > 50: ds["district-name"] = ds["district-name"][:49] school.district_name = ds["district-name"] # try: print school.gsurl school.save()
def cb(count,ds): school = School() school.name = ds["name"] school.gsid = ds["universal-id"] school.city = ds["city"] if len(ds["zip"]) > 6: ds["zip"] = ds["zip"][:6] school.zip = ds["zip"] school.state = ds["state"] school.lat = ds["lat"] school.lon = ds["lon"] if len(ds["subtype"]) > 50: ds["subtype"] = 'special' school.type = ds["subtype"] sql = 'insert into schools_school values ("'+ds["universal-id"]+'","'+ ds["name"] + '","' + ds["subtype"] + '","' + ds["city"] + '","' + ds["state"] + '","' + ds["zip"] + '","' + ds["lat"] + '","' + ds["lon"] + '",0);' print sql
def cb(count, ds): school = School() school.name = ds["name"] school.gsid = ds["universal-id"] school.city = ds["city"] if len(ds["zip"]) > 6: ds["zip"] = ds["zip"][:6] school.zip = ds["zip"] school.state = ds["state"] school.lat = ds["lat"] school.lon = ds["lon"] if len(ds["subtype"]) > 50: ds["subtype"] = 'special' school.type = ds["subtype"] sql = 'insert into schools_school values ("' + ds[ "universal-id"] + '","' + ds["name"] + '","' + ds[ "subtype"] + '","' + ds["city"] + '","' + ds["state"] + '","' + ds[ "zip"] + '","' + ds["lat"] + '","' + ds["lon"] + '",0);' print sql
def import_primary_schools(): period = datetime.datetime(day=31, month=12, year=2007) filename = "%s/documentation/data/2007/primary.csv" % settings.BASE_DIR n = 1 with open(filename, "rb") as ifile: reader = csv.reader(ifile) for row in reader: if n > 1: school = School() school.name = row[0].strip() school.level = School.PRIMARY school.ownership = get_ownership(row[2].strip()) school.sponsor = get_sponsor(row[3].strip()) school.student_gender = get_student_gender(row[4].strip()) school.school_type = get_school_type(row[5].strip()) school.student_needs = get_student_needs(row[6].strip()) # location if row[29]: county, created = County.objects.get_or_create(name=row[29].strip().upper()) school.county = county province, created = Province.objects.get_or_create(name=row[28].strip().upper()) school.province = province if row[33]: constituency = Constituency.objects.filter(name=row[33].strip().upper()).first() if not constituency: constituency, created = Constituency.objects.get_or_create( name=row[33].strip().upper(), county=county) school.constituency = constituency if row[30]: district = District.objects.filter(name=row[30].strip().upper()).first() if not district: district, created = District.objects.get_or_create( name=row[30].strip().upper(), province=province) school.district = district if row[31]: division, created = Division.objects.get_or_create( name=row[31].strip().upper(), district=district) school.division = division if row[32]: location, created = Location.objects.get_or_create( name=row[32].strip().upper(), division=division) school.location = location if row[34]: coord = row[34].split(",") x = float(coord[0][1:]) y = float(coord[1][1:-2]) school.coordinates = Point(y, x) school.save() # facilities facility1, created = Facility.objects.get_or_create(name="Toilets") facility2, created = Facility.objects.get_or_create(name="Classrooms") facility3, created = Facility.objects.get_or_create(name="Enrollment") facility_record1, created = FacilityRecord.objects.get_or_create(facility=facility1, school=school, period=period, boys=row[11].strip(), girls=row[12].strip(), total=row[13].strip()) facility_record3, created = FacilityRecord.objects.get_or_create(facility=facility3, school=school, period=period, boys=row[15].strip(), girls=row[16].strip(), total=row[17].strip()) # staff if row[18]: staff1, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.TSC_MALE, number=row[18].strip(), is_teacher=True) if row[19]: staff2, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.TSC_FEMALE, number=row[19].strip(), is_teacher=True) if row[20]: staff3, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.LOCAL_MALE, number=row[20].strip(), is_teacher=True) if row[21]: staff4, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.LOCAL_FEMALE, number=row[21].strip(), is_teacher=True) if row[22]: staff5, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.PTA_MALE, number=row[22].strip(), is_teacher=True) if row[23]: staff6, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.PTA_FEMALE, number=row[23].strip(), is_teacher=True) if row[24]: staff7, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.OTHER_MALE, number=row[24].strip(), is_teacher=True) if row[25]: staff8, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.OTHER_FEMALE, number=row[25].strip(), is_teacher=True) if row[26]: staff9, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.NON_TEACHING_MALE, number=row[26].strip(), is_teacher=False) if row[27]: staff10, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.NON_TEACHING_FEMALE, number=row[27].strip(), is_teacher=False) # facts if row[7]: fact2, created = Fact.objects.get_or_create(name="Pupil Teacher Ratio", period=period, school=school, value=row[7].strip()) if row[8]: fact1, created = Fact.objects.get_or_create(name="Pupil Classroom Ratio", period=period, school=school, facility=facility2, value=row[8].strip()) if row[9]: fact4, created = Fact.objects.get_or_create(name="Pupil Toilet Ratio", period=period, school=school, facility=facility1, value=row[9].strip()) if row[10]: fact5, created = Fact.objects.get_or_create(name="Total Number of Classrooms", period=period, school=school, facility=facility2, value=row[10].strip()) if row[14]: fact5, created = Fact.objects.get_or_create(name="Teachers Toilets", period=period, school=school, facility=facility1, value=row[14].strip()) n += 1
def import_secondary_schools(): period = datetime.datetime(day=31, month=12, year=2007) filename = "%s/documentation/data/2007/secondary.csv" % settings.BASE_DIR n = 1 with open(filename, "rb") as ifile: reader = csv.reader(ifile) for row in reader: if n > 1: school = School() school.code = row[0].strip() school.name = row[1].strip() school.address = row[2].strip() school.level = School.SECONDARY school.ownership = get_ownership(row[3].strip()) school.sponsor = get_sponsor(row[4].strip()) school.student_gender = get_student_gender(row[5].strip()) school.school_type = get_school_type(row[6].strip()) school.student_needs = get_student_needs(row[6].strip()) # location province, created = Province.objects.get_or_create(name=row[23].strip().upper()) school.province = province county, created = County.objects.get_or_create(name=row[24].strip().upper()) school.county = county if row[30]: constituency = Constituency.objects.filter(name=row[30].strip().upper()).first() if not constituency: constituency, created = Constituency.objects.get_or_create(name=row[30].strip().upper(), county=county) school.constituency = constituency if row[25]: district = District.objects.filter(name=row[25].strip().upper()).first() if not district: district, created = District.objects.get_or_create(name=row[25].strip().upper(), province=province) school.district = district if row[26]: division, created = Division.objects.get_or_create(name=row[26].strip().upper(), district=district) school.division = division if row[27]: location, created = Location.objects.get_or_create(name=row[27].strip().upper(), division=division) school.location = location if row[28]: sub_location, created = SubLocation.objects.get_or_create(name=row[28].strip().upper(), location=location) school.sub_location = sub_location if row[29]: school_zone, created = SchoolZone.objects.get_or_create(name=row[29].strip().upper(), county=county) school.school_zone = school_zone if row[31]: coord = row[31].split(",") x = float(coord[0][1:]) y = float(coord[1][1:-2]) school.coordinates = Point(y, x) school.save() # staff if row[12]: staff1, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.TSC_MALE, number=row[12].strip(), is_teacher=True) if row[13]: staff2, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.TSC_FEMALE, number=row[13].strip(), is_teacher=True) if row[14]: staff3, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.LOCAL_MALE, number=row[14].strip(), is_teacher=True) if row[15]: staff4, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.LOCAL_FEMALE, number=row[15].strip(), is_teacher=True) if row[16]: staff5, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.PTA_MALE, number=row[16].strip(), is_teacher=True) if row[17]: staff6, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.PTA_FEMALE, number=row[17].strip(), is_teacher=True) if row[18]: staff7, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.OTHER_MALE, number=row[18].strip(), is_teacher=True) if row[19]: staff8, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.OTHER_FEMALE, number=row[19].strip(), is_teacher=True) if row[20]: staff9, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.NON_TEACHING_MALE, number=row[20].strip(), is_teacher=False) if row[21]: staff10, created = Staff.objects.get_or_create(period=period, school=school, staff_type=Staff.NON_TEACHING_FEMALE, number=row[21].strip(), is_teacher=False) # facts if row[8]: fact1, created = Fact.objects.get_or_create(name="Total Enrolment", period=period, school=school, value=row[8].strip()) if row[9]: fact2, created = Fact.objects.get_or_create(name="Pupil Teacher Ratio", period=period, school=school, value=row[9].strip()) if row[10]: fact3, created = Fact.objects.get_or_create(name="Total Teaching staff", period=period, school=school, value=row[10].strip()) if row[11]: fact4, created = Fact.objects.get_or_create(name="Acreage per enrolment", period=period, school=school, value=row[11].strip()) if row[22]: fact5, created = Fact.objects.get_or_create(name="Acreage", period=period, school=school, value=row[22].strip()) n += 1