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


class Command(BaseXpressDemocracyClubCsvImporter):
    council_id = 'E09000023'
    addresses_name = 'local.2018-05-03/Version 1/Democracy_Club__03May2018. LEWISHAM.TSV'
    stations_name = 'local.2018-05-03/Version 1/Democracy_Club__03May2018. LEWISHAM.TSV'
    elections = ['local.2018-05-03']
    csv_delimiter = '\t'

    def address_record_to_dict(self, record):

        uprn = record.property_urn.strip().lstrip('0')

        if uprn == '10070773494':
            rec = super().address_record_to_dict(record)
            rec['postcode'] = 'SE23 3HN'
            return rec

        if uprn in ['100022832947', '100022832948', '100022832949']:
            rec = super().address_record_to_dict(record)
            rec['postcode'] = 'SE6 4PL'
            return rec

        return super().address_record_to_dict(record)

    def station_record_to_dict(self, record):
        rec = super().station_record_to_dict(record)
        if record.polling_place_id == '14384':
            rec['location'] = Point(-0.041439, 51.485670, srid=4326)
        return rec

@@ -1,46 +1,4 @@
-from django.contrib.gis.geos import Point%0A
 from
@@ -180,32 +180,48 @@
 name = '
-local
+parl.lewisham-east.by
 .2018-0
-5-03
+6-14
 /Version
@@ -239,39 +239,30 @@
 y_Club__
-03May2018. LEWISHAM.TSV
+14June2018.tsv
 '%0A    st
@@ -276,32 +276,48 @@
 name = '
-local
+parl.lewisham-east.by
 .2018-0
-5-03
+6-14
 /Version
@@ -339,830 +339,98 @@
 ub__
-03May2018. LEWISHAM.TSV'%0A    elections = %5B'local.2018-05-03'%5D%0A    csv_delimiter = '%5Ct'%0A%0A    def address_record_to_dict(self, record):%0A%0A        uprn = record.property_urn.strip().lstrip('0')%0A%0A        if uprn == '10070773494':%0A            rec = super().address_record_to_dict(record)%0A            rec%5B'postcode'%5D = 'SE23 3HN'%0A            return rec%0A%0A        if uprn in %5B'100022832947', '100022832948', '100022832949'%5D:%0A            rec = super().address_record_to_dict(record)%0A            rec%5B'postcode'%5D = 'SE6 4PL'%0A            return rec%0A%0A        return super().address_record_to_dict(record)%0A%0A    def station_record_to_dict(self, record):%0A        rec = super().station_record_to_dict(record)%0A        if record.polling_place_id == '14384':%0A            rec%5B'location'%5D = Point(-0.041439, 51.485670, srid=4326)%0A        return rec
+14June2018.tsv'%0A    elections = %5B'parl.lewisham-east.by.2018-06-14'%5D%0A    csv_delimiter = '%5Ct'
 %0A

add import script for Lewisham East by-election