import csv

import petl as etl

def remove_dash_lines(value):
    """Some social media values are '---------'"""
    return None if value[:2] == '--' else value

def expand_party(party):
    return 'Democratic' if party == 'D' else 'Republican' if party == 'R' else None

def expand_gender(gender):
    return 'Male' if gender == 'M' else 'Female' if gender == 'F' else None

def empty_to_none(value):
    return None if value == '' else value

def process_leaders(filepath):
    table = etl.fromcsv(filepath) \
        .rename({'Name':        'fullName',
                 'Ward':        'ward',
                 'Sub-Ward':    'subWard',
                 'Party':       'party',
                 'Nickname':    'nickname',
                 'Phones':      'phone',
                 'Address':     'address',
                 'Gender':      'gender',
                 'Ward of Residence':   'wardOfResidence',
                 'Year of Birth':       'yearOfBirth',
                 'Occupation':          'occupation',
                 'LinkedIn':    'linkedin',
                 'Facebook':    'facebook',
                 'Twitter':     'twitter',
                 'Email':       'email',
                 'Photo':       'photoUrl',
                 'Divisions':   'divisionCount',
                 'Committee People':    'committeePersonCount',
                 'Party Registered':    'registeredVotersParty',
                 'Total Registered':    'registeredVotersTotal',
                 'Party Turnout':       'turnoutParty',
                 'Total Turnout':       'turnoutTotal'}) \
        .cutout('Lat', 'Lng', 'Last Voted', 'Photo Offset',
                '2014 General Party Turnout', '2014 General Total Turnout') \
        .convert(('ward', 'wardOfResidence', 'yearOfBirth',
                  'divisionCount', 'committeePersonCount',
                  'registeredVotersParty', 'registeredVotersTotal',
                  'turnoutParty', 'turnoutTotal'), int) \
        .convert(('linkedin', 'facebook', 'twitter'), remove_dash_lines) \
        .convert('party', expand_party) \
        .convert('gender', expand_gender) \
        .convertall(empty_to_none)

    return table

@@ -23,16 +23,44 @@
 l as etl
+%0Afrom slugify import slugify
 %0A%0Adef re
@@ -220,17 +220,17 @@
 return '
-D
+d
 emocrati
@@ -254,17 +254,17 @@
 ' else '
-R
+r
 epublica
@@ -393,24 +393,140 @@
  else None%0A%0A
+def create_slug(row):%0A    url_string = '%7B%7D %7B%7D'.format(row%5B'ward'%5D, row%5B'fullName'%5D)%0A    return slugify(url_string)%0A%0A
 def empty_to
@@ -2269,24 +2269,65 @@
 d_gender) %5C%0A
+        .addfield('slug', create_slug) %5C%0A
         .con

Add slug to leaders data script. Also use lowercase party names for leaders. #108 & #103