"""
Import Salford
"""
import sys
from django.contrib.gis.geos import Point

from data_collection.management.commands import BaseShpImporter

class Command(BaseShpImporter):
    """
    Imports the Polling Station data from Salford
    """
    council_id     = 'E08000006'
    districts_name = 'Salford_Polling_Districts'
    stations_name  = 'Polling_Stations.csv'

    def district_record_to_dict(self, record):
        return {
            'internal_council_id': record[0],
            'name': record[0],
        }

    def station_record_to_dict(self, record):
        try:
            location = Point(int(record.easting), int(record.northing), srid=self.srid)
        except ValueError:
            location = Point(float(record.easting), float(record.northing), srid=self.srid)
        return {
            'internal_council_id': record.id,
            'postcode'           : record.location.split(',')[-1],
            'address'            : "\n".join(record.location.split(',')[:-1]),
            'location'           : location,
            'polling_district_id': record.polling_district_code
        }
    

@@ -770,32 +770,278 @@
 srid=self.srid)%0A
+%0A        address_parts = %5Bx.strip() for x in record.location.split(' ')%5D%0A        postcode = %22%25s %25s%22 %25 (address_parts%5B-2%5D, address_parts%5B-1%5D)%0A        del(address_parts%5B-1%5D)%0A        del(address_parts%5B-1%5D)%0A        address = %22 %22.join(address_parts)%0A%0A
         return %7B
@@ -1126,38 +1126,16 @@
   : 
-record.location.split(',')%5B-1%5D
+postcode
 ,%0A  
@@ -1171,50 +1171,15 @@
   : 
-%22%5Cn%22.join(record.location.split(',')%5B:-1%5D)
+address
 ,%0A  
@@ -1299,9 +1299,4 @@
   %7D%0A
-    %0A

Fix address/postcode formatting