def forwards(self, orm): "Import lots from HPD file" owner = orm.Owner.objects.get(name='Housing Preservation and Development') for lot in csv.DictReader(open(self.file, 'r')): if lot['Vacant'] != 'yes': continue bbl = load.make_bbl(3, int(lot['Block']), int(lot['Lot'])) if orm.Lot.objects.filter(bbl=bbl).count() > 0: print "Lot %s already exists. Skipping." % bbl continue saved_lot = orm.Lot( address=lot['Address'], borough='Brooklyn', bbl=bbl, block=lot['Block'], lot=lot['Lot'], zipcode=lot['ZipCode'], owner=owner, area=lot['Lot Area'], area_acres=str(load.convert_sq_ft_to_acres(int(lot['Lot Area']))), centroid_source=lot['point source'], centroid=self._get_centroid(lot), school_district=lot['School District'], council=lot['City Council District'], council_district=lot['Community District'], police_precinct=lot['Police Precinct'], ) saved_lot.save()
def backwards(self, orm): "Remove lots from HPD file" for lot in csv.DictReader(open(self.file, 'r')): bbl = load.make_bbl(3, int(lot['Block']), int(lot['Lot'])) orm.Lot.objects.filter(bbl=bbl).delete()