from data_collection.management.commands import BaseShpShpImporter

class Command(BaseShpShpImporter):
    """
    Imports the Polling Station data from Sheffield
    """
    council_id     = 'E08000019'
    districts_name = 'SCCPollingDistricts2015'
    stations_name  = 'SCCPollingStations2015.shp'

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

    def station_record_to_dict(self, record):

        address = record[1]

        # remove postcode from end of address if present
        postcode_offset = -len(record[2])
        if address[postcode_offset:] == record[2]:
            address = address[:postcode_offset].strip()

        # remove trailing comma if present
        if address[-1:] == ',':
            address = address[:-1]

        # replace commas with \n
        address = "\n".join(map(lambda x: x.strip(), address.split(',')))

        return {
            'internal_council_id': record[0],
            'postcode'           : record[2],
            'address'            : address
        }

from data_collection.management.commands import BaseShpShpImporter

class Command(BaseShpShpImporter):
    """
    Imports the Polling Station data from Sheffield
    """
    council_id     = 'E08000019'
    districts_name = 'SCCPollingDistricts2015'
    stations_name  = 'SCCPollingStations2015.shp'

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

    def station_record_to_dict(self, record):

        address = record[1]

        # remove postcode from end of address if present
        postcode_offset = -len(record[2])
        if address[postcode_offset:] == record[2]:
            address = address[:postcode_offset].strip()

        # remove trailing comma if present
        if address[-1:] == ',':
            address = address[:-1]

        # replace commas with \n
        address = "\n".join(map(lambda x: x.strip(), address.split(',')))

        return {
            'internal_council_id': record[0],
            'postcode'           : record[2],
            'address'            : address,
            'polling_district_id': record[-1]
        }

Add polling_district_id in Sheffield import script
Add polling_district_id in Sheffield import script

  from data_collection.management.commands import BaseShpShpImporter
  
  class Command(BaseShpShpImporter):
      """
      Imports the Polling Station data from Sheffield
      """
      council_id     = 'E08000019'
      districts_name = 'SCCPollingDistricts2015'
      stations_name  = 'SCCPollingStations2015.shp'
  
      def district_record_to_dict(self, record):
          return {
-             'internal_council_id': record[0],
+             'internal_council_id': record[1],
+             'extra_id':            record[0],
-             'name': record[1],
+             'name':                record[1],
          }
  
      def station_record_to_dict(self, record):
  
          address = record[1]
  
          # remove postcode from end of address if present
          postcode_offset = -len(record[2])
          if address[postcode_offset:] == record[2]:
              address = address[:postcode_offset].strip()
  
          # remove trailing comma if present
          if address[-1:] == ',':
              address = address[:-1]
  
          # replace commas with \n
          address = "\n".join(map(lambda x: x.strip(), address.split(',')))
  
          return {
              'internal_council_id': record[0],
              'postcode'           : record[2],
-             'address'            : address
+             'address'            : address,
+             'polling_district_id': record[-1]
          }
  
Add polling_district_id in Sheffield import script
## Code Before:
from data_collection.management.commands import BaseShpShpImporter

class Command(BaseShpShpImporter):
    """
    Imports the Polling Station data from Sheffield
    """
    council_id     = 'E08000019'
    districts_name = 'SCCPollingDistricts2015'
    stations_name  = 'SCCPollingStations2015.shp'

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

    def station_record_to_dict(self, record):

        address = record[1]

        # remove postcode from end of address if present
        postcode_offset = -len(record[2])
        if address[postcode_offset:] == record[2]:
            address = address[:postcode_offset].strip()

        # remove trailing comma if present
        if address[-1:] == ',':
            address = address[:-1]

        # replace commas with \n
        address = "\n".join(map(lambda x: x.strip(), address.split(',')))

        return {
            'internal_council_id': record[0],
            'postcode'           : record[2],
            'address'            : address
        }

## Instruction:
Add polling_district_id in Sheffield import script
## Code After:
from data_collection.management.commands import BaseShpShpImporter

class Command(BaseShpShpImporter):
    """
    Imports the Polling Station data from Sheffield
    """
    council_id     = 'E08000019'
    districts_name = 'SCCPollingDistricts2015'
    stations_name  = 'SCCPollingStations2015.shp'

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

    def station_record_to_dict(self, record):

        address = record[1]

        # remove postcode from end of address if present
        postcode_offset = -len(record[2])
        if address[postcode_offset:] == record[2]:
            address = address[:postcode_offset].strip()

        # remove trailing comma if present
        if address[-1:] == ',':
            address = address[:-1]

        # replace commas with \n
        address = "\n".join(map(lambda x: x.strip(), address.split(',')))

        return {
            'internal_council_id': record[0],
            'postcode'           : record[2],
            'address'            : address,
            'polling_district_id': record[-1]
        }
