from django.contrib.gis.geos import Point
from data_collection.management.commands import BaseCsvStationsJsonDistrictsImporter

class Command(BaseCsvStationsJsonDistrictsImporter):
    srid = 27700
    districts_srid = 27700
    council_id = 'E07000089'
    districts_name = 'Hart Polling Districts-fixed.geojson'
    stations_name = 'Hart Polling Stations 2017 v2 070417-fixed.csv'
    elections = [
        'local.hampshire.2017-05-04',
        'parl.2017-06-08'
    ]

    def district_record_to_dict(self, record):
        name = str(record['properties']['Name']).strip()
        code = name.split(' ')[1]
        return {
            'internal_council_id': code,
            'name': name,
        }

    def station_record_to_dict(self, record):
        location = Point(float(record.easting), float(record.northing), srid=self.srid)
        stations = []
        district_ids = record.districts.split(',')
        district_ids = [d.strip() for d in district_ids]
        for district_id in district_ids:
            stations.append({
                'internal_council_id': district_id,
                'address' : record.polling_place,
                'postcode': record.postcode,
                'polling_district_id': district_id,
                'location': location,
            })
        return stations

@@ -1,46 +1,4 @@
-from django.contrib.gis.geos import Point%0A
 from
@@ -49,32 +49,30 @@
 Base
-CsvStationsJsonDistricts
+XpressDemocracyClubCsv
 Impo
@@ -99,86 +99,40 @@
 Base
-CsvStationsJsonDistrictsImporter):%0A    srid = 27700%0A    districts_srid = 27700
+XpressDemocracyClubCsvImporter):
 %0A   
@@ -161,24 +161,24 @@
 89'%0A    
-district
+addresse
 s_name =
@@ -183,1044 +183,240 @@
  = '
-Hart Polling Districts-fixed.geojson'%0A    stations_name = 'Hart Polling Stations 2017 v2 070417-fixed.csv
+parl.2017-06-08/Version 1/Hart DC General Election polling place 120517.TSV
 '%0A    
-elec
+sta
 tions
- = %5B%0A        'local.hampshire.2017-05-04',%0A        'parl.2017-06-08'%0A    %5D%0A%0A    def district_record_to_dict(self, record):%0A        name = str(record%5B'properties'%5D%5B'Name'%5D).strip()%0A        code = name.split(' ')%5B1%5D%0A        return %7B%0A            'int
+_name = 'parl.2017-06-08/Version 1/Hart DC Gen
 er
-n
 al
-_council_id': code,%0A            'name': name,%0A        %7D%0A%0A    def station_record_to_dict(self, record):%0A        location = Point(float(record.easting), float(record.northing), srid=self.srid)%0A        stations = %5B%5D%0A        district_ids = record.districts.split(',')%0A        district_ids = %5Bd.strip() for d in district_ids%5D%0A        for district_id in district_ids:%0A            stations.append(%7B%0A                'internal_council_id': district_id,%0A                'address' : record.polling_place,%0A                'postcode': record.postcode,%0A                'polling_district_id': district_id,%0A                'location': location,%0A            %7D)%0A        return stations
+ Election polling place 120517.TSV'%0A    elections = %5B'parl.2017-06-08'%5D%0A    csv_delimiter = '%5Ct'
 %0A

update import script for Hart for parl.2017-06-08