# Path: sitegeist/data/schools/models.py
# class School(models.Model):
# 
#     objects = models.GeoManager()
# 
#     nces_id = models.CharField(max_length=12)
#     name = models.CharField(max_length=128)
#     street = models.CharField(max_length=128, blank=True)
#     city = models.CharField(max_length=128, blank=True)
#     state = models.CharField(max_length=2, blank=True)
#     zipcode = models.CharField(max_length=5, blank=True)
#     enrollment = models.IntegerField(blank=True, null=True)
#     locale_code = models.CharField(max_length=2, choices=LOCALES, blank=True)
#     type_code = models.CharField(max_length=1, choices=TYPES, blank=True)
#     level_code = models.CharField(max_length=1, choices=LEVEL_CODES, blank=True)
#     level_low = models.CharField(max_length=2, choices=LEVELS, blank=True)
#     level_high = models.CharField(max_length=2, choices=LEVELS, blank=True)
#     status = models.CharField(max_length=1, choices=STATUSES, blank=True)
# 
#     lon = models.FloatField(blank=True, null=True)
#     lat = models.FloatField(blank=True, null=True)
# 
#     class Meta:
#         ordering = ('name',)
# 
#     def __unicode__(self):
#         return self.name


import csv
import os
import zipfile
import requests
from django.conf import settings
from sitegeist.data.schools.models import School

    School.objects.all().delete()

    for csv_filename in os.listdir(extract_path):

        csv_path = os.path.join(extract_path, csv_filename)

        with open(csv_path) as infile:

            print csv_path

            reader = csv.DictReader(infile)
            for record in reader:

                params = {
                    'nces_id': record['ncessch'],
                    'name': record['schnam09'],
                    'street': record['mstree09'],
                    'city': record['mcity09'],
                    'state': record['mstate09'],
                    'zipcode': record['mzip09'],
                    'enrollment': record['member09'],
                    'locale_code': record['ulocal09'],
                    'type_code': record['type09'],
                    'level_code': record['level09'],
                    'level_low': record['gslo09'],
                    'level_high': record['gshi09'],
                    'status': record['status09'],
                }


# Path: sitegeist/data/schools/models.py
# class School(models.Model):
# 
#     objects = models.GeoManager()
# 
#     nces_id = models.CharField(max_length=12)
#     name = models.CharField(max_length=128)
#     street = models.CharField(max_length=128, blank=True)
#     city = models.CharField(max_length=128, blank=True)
#     state = models.CharField(max_length=2, blank=True)
#     zipcode = models.CharField(max_length=5, blank=True)
#     enrollment = models.IntegerField(blank=True, null=True)
#     locale_code = models.CharField(max_length=2, choices=LOCALES, blank=True)
#     type_code = models.CharField(max_length=1, choices=TYPES, blank=True)
#     level_code = models.CharField(max_length=1, choices=LEVEL_CODES, blank=True)
#     level_low = models.CharField(max_length=2, choices=LEVELS, blank=True)
#     level_high = models.CharField(max_length=2, choices=LEVELS, blank=True)
#     status = models.CharField(max_length=1, choices=STATUSES, blank=True)
# 
#     lon = models.FloatField(blank=True, null=True)
#     lat = models.FloatField(blank=True, null=True)
# 
#     class Meta:
#         ordering = ('name',)
# 
#     def __unicode__(self):
#         return self.name


# Path: sitegeist/data/schools/loading.py
import csv
import os
import zipfile
import requests
from django.conf import settings
from sitegeist.data.schools.models import School


    School.objects.all().delete()

    for csv_filename in os.listdir(extract_path):

        csv_path = os.path.join(extract_path, csv_filename)

        with open(csv_path) as infile:

            print csv_path

            reader = csv.DictReader(infile)
            for record in reader:

                params = {
                    'nces_id': record['ncessch'],
                    'name': record['schnam09'],
                    'street': record['mstree09'],
                    'city': record['mcity09'],
                    'state': record['mstate09'],
                    'zipcode': record['mzip09'],
                    'enrollment': record['member09'],
                    'locale_code': record['ulocal09'],
                    'type_code': record['type09'],
                    'level_code': record['level09'],
                    'level_low': record['gslo09'],
                    'level_high': record['gshi09'],
                    'status': record['status09'],
                }


                School.objects.create(**params)