def make_null(r, locs, meta):
    """iterate through each value and see if any values are Nones, set to None (Null in db)"""
    for col in meta.columns:
        if col.description != 'pk' and etl.xstr(r[locs[col.description] - 1].value) == 'None':
            r[locs[col.description] - 1].value = None

    return r
def check_zero_entries(r, locs, meta):
    """iterate through each value and see if any ints are Nones, set to 0"""
    for col in meta.columns:
        if (isinstance(col.type, Integer) or isinstance(col.type, Float)) and col.description != 'pk' \
                and etl.xstr(r[locs[col.description] - 1].value) == 'None':
            r[locs[col.description] - 1].value = '0'

    return r
 def test_xstr_null(self):
     self.assertEqual(etl.xstr('None', setnull=True), None)
 def test_xstr_no_null(self):
     self.assertEqual(etl.xstr('string!'), 'string!')
def gen_pk(r, locs):
    return etl.xstr(r[locs["imp_agency"]-1].value)+etl.xstr(r[locs["local_partner"]-1].value)+etl.xstr(r[locs["district"]-1].value)+etl.xstr(r[locs["vdc"]-1].value)+etl.xstr(r[locs["ward"]-1].value)+etl.xstr(r[locs["act_type"]-1].value)+etl.xstr(r[locs["act_desc"]-1].value)+etl.xstr(r[locs["quantity"]-1].value)+etl.xstr(r[locs["total_hh"]-1].value)
def prep_row(r, locs):
    #check to see if numeric rows are None - if so, make 0
    r = etl.get_values(r, setnull=True)

    return Distributions(
    priority=etl.xstr(r[locs["priority"]-1], setnull=True),
    access_method=etl.xstr(r[locs["access_method"]-1], setnull=True),
    hub=etl.xstr(r[locs["hub"]-1], setnull=True),
    as_of=etl.xstr(r[locs["as_of"]-1], setnull=True),
    dist_code=etl.xstr(r[locs["dist_code"]-1], setnull=True),
    vdc_code=etl.xstr(r[locs["vdc_code"]-1], setnull=True),
    act_cat=etl.xstr(r[locs["act_cat"]-1], setnull=True),

    imp_agency=etl.xstr(r[locs["imp_agency"]-1], setnull=True),
    source_agency=etl.xstr(r[locs["source_agency"]-1], setnull=True),
    local_partner=etl.xstr(r[locs["local_partner"]-1], setnull=True),
    contact_name=etl.xstr(r[locs["contact_name"]-1], setnull=True),
    contact_email=etl.xstr(r[locs["contact_email"]-1], setnull=True),
    contact_phone=etl.xstr(r[locs["contact_phone"]-1], setnull=True),

    district=etl.xstr(r[locs["district"]-1], setnull=True),
    vdc=etl.xstr(r[locs["vdc"]-1], setnull=True),
    ward=etl.xstr(r[locs["ward"]-1], setnull=True),

    act_type=etl.xstr(r[locs["act_type"]-1], setnull=True),
    act_desc=etl.xstr(r[locs["act_desc"]-1], setnull=True),
    targeting=etl.xstr(r[locs["targeting"]-1], setnull=True),
    quantity=etl.xstr(r[locs["quantity"]-1], setnull=True),
    total_hh=etl.xstr(r[locs["total_hh"]-1], setnull=True),
    avg_hh_cost=etl.xstr(r[locs["avg_hh_cost"]-1], setnull=True),
    fem_hh=etl.xstr(r[locs["fem_hh"]-1], setnull=True),
    vuln_hh=etl.xstr(r[locs["vuln_hh"]-1], setnull=True),

    act_status=etl.xstr(r[locs["act_status"]-1], setnull=True),
    #start_dt=etl.xstr(r[locs["start_dt"]-1], setnull=True),
    start_day=etl.xstr(r[locs["start_day"]-1], setnull=True),
    start_month=etl.xstr(r[locs["start_month"]-1], setnull=True),
    start_year=etl.xstr(r[locs["start_year"]-1], setnull=True),
    #comp_dt=etl.xstr(r[locs["comp_dt"]-1], setnull=True),
    comp_day=etl.xstr(r[locs["comp_day"]-1], setnull=True),
    comp_month=etl.xstr(r[locs["comp_month"]-1], setnull=True),
    comp_year=etl.xstr(r[locs["comp_year"]-1], setnull=True),
    comments=etl.xstr(r[locs["comments"]-1], setnull=True))
 def test_xstr_null(self):
         self.assertEqual(etl.xstr('None', setnull=True), None)
 def test_xstr_no_null(self):
     self.assertEqual(etl.xstr('string!'), 'string!')
def prep_row(r, locs):
    # check to see if numeric rows are None - if so, make 0
    r = etl.get_values(r, setnull=True)

    return Trainings(
    priority=etl.xstr(r[locs["priority"]-1], setnull=True),
    access_method=etl.xstr(r[locs["access_method"]-1], setnull=True),
    hub=etl.xstr(r[locs["hub"]-1], setnull=True),
    as_of=etl.xstr(r[locs["as_of"]-1], setnull=True),
    dist_code=etl.xstr(r[locs["dist_code"]-1], setnull=True),
    vdc_code=etl.xstr(r[locs["vdc_code"]-1], setnull=True),
    uid=etl.xstr(r[locs["uid"]-1], setnull=True),

    imp_agency=etl.xstr(r[locs["imp_agency"]-1], setnull=True),
    source_agency=etl.xstr(r[locs["source_agency"]-1], setnull=True),
    local_partner=etl.xstr(r[locs["local_partner"]-1], setnull=True),
    contact_name=etl.xstr(r[locs["contact_name"]-1], setnull=True),
    contact_email=etl.xstr(r[locs["contact_email"]-1], setnull=True),
    contact_phone=etl.xstr(r[locs["contact_phone"]-1], setnull=True),

    district=etl.xstr(r[locs["district"]-1], setnull=True),
    vdc=etl.xstr(r[locs["vdc"]-1], setnull=True),
    ward=etl.xstr(r[locs["ward"]-1], setnull=True),

    train_sub=etl.xstr(r[locs["train_sub"]-1], setnull=True),
    audience=etl.xstr(r[locs["audience"]-1], setnull=True),
    train_title=etl.xstr(r[locs["train_title"]-1], setnull=True),
    demo_inc=etl.xstr(r[locs["demo_inc"]-1], setnull=True),
    iec_dist=etl.xstr(r[locs["iec_dist"]-1], setnull=True),
    dur_session=etl.xstr(r[locs["dur_session"]-1], setnull=True),
    amt_parti=etl.xstr(r[locs["amt_parti"]-1], setnull=True),
    total_cost=etl.xstr(r[locs["total_cost"]-1], setnull=True),
    total_parti=etl.xstr(r[locs["total_parti"]-1], setnull=True),
    males=etl.xstr(r[locs["males"]-1], setnull=True),
    females=etl.xstr(r[locs["females"]-1], setnull=True),
    third_gen=etl.xstr(r[locs["third_gen"]-1], setnull=True),
    elderly=etl.xstr(r[locs["elderly"]-1], setnull=True),
    children=etl.xstr(r[locs["children"]-1], setnull=True),
    person_dis=etl.xstr(r[locs["person_dis"]-1], setnull=True),
    fem_hh=etl.xstr(r[locs["fem_hh"]-1], setnull=True),
    vuln_hh=etl.xstr(r[locs["vuln_hh"]-1], setnull=True),

    act_status=etl.xstr(r[locs["act_status"]-1], setnull=True),
    #start_dt=etl.xstr(r[locs["start_dt"]-1], setnull=True),
    start_day=etl.xstr(r[locs["start_day"]-1], setnull=True),
    start_month=etl.xstr(r[locs["start_month"]-1], setnull=True),
    start_year=etl.xstr(r[locs["start_year"]-1], setnull=True),
    #comp_dt=etl.xstr(r[locs["comp_dt"]-1], setnull=True),
    comp_day=etl.xstr(r[locs["comp_day"]-1], setnull=True),
    comp_month=etl.xstr(r[locs["comp_month"]-1], setnull=True),
    comp_year=etl.xstr(r[locs["comp_year"]-1], setnull=True),

    comments=etl.xstr(r[locs["comments"]-1], setnull=True))