示例#1
0
def process_site(site, next_version):
    """ Create an entry in the database for a federal site."""

    # Some rows in the CSV don't represent sites. This is indicative by them
    # missing the city name.
    if site['city'] != '':
        phone, phone_extension = phone_number(site['phone'])
        annual = site['annual'].upper() == 'YES'
        senior = site['senior'].upper() == 'YES'
        access = site['access'].upper() == 'YES'
        site_type = determine_site_type(site['name'], site['website'])

        sites = FederalSite.objects.filter(name=site['name'], city=site['city'])

        if len(sites) > 0:
            # If we encounter a duplicate, let's update instead of inserting.
            fs = sites[0]
        else:
            fs = FederalSite()

        fs.name = site['name']
        fs.site_type = site_type
        fs.phone = phone
        fs.phone_extension = phone_extension
        fs.city = site['city']
        fs.state = site['state']
        fs.website = site['website']
        fs.annual_pass = annual
        fs.senior_pass = senior
        fs.access_pass = access
        fs.version = next_version
        fs.save()
示例#2
0
def process_site(row):
    """ Create an entry in the database for a federal site."""

    # Some rows in the CSV don't represent sites. This is indicative by them
    # missing the city name.
    if row[2] != '':
        name = row[0]
        phone, phone_extension = phone_number(row[1])
        city = row[2]
        state = row[3]
        website = row[4]
        annual = row[5] == 'YES'
        senior = row[6] == 'YES'
        access = row[7] == 'YES'
        site_type = determine_site_type(name, website)

        sites = FederalSite.objects.filter(name=name, city=city)

        if len(sites) > 0:
            # If we encounter a duplicate, let's update instead of inserting.
            fs = sites[0]
        else:
            fs = FederalSite()

        fs.name = name
        fs.site_type = site_type
        fs.phone = phone
        fs.phone_extension = phone_extension
        fs.city = city
        fs.state = state
        fs.website = website
        fs.annual_pass = annual
        fs.senior_pass = senior
        fs.access_pass = access
        fs.save()
示例#3
0
def process_site(site, next_version):
    """ Create an entry in the database for a federal site."""

    # Some rows in the CSV don't represent sites. This is indicative by them
    # missing the city name.
    if site['city'] != '':
        phone, phone_extension = phone_number(site['phone'])
        annual = site['annual_senior'].upper() == 'YES'
        # As of June, 2016 'annual', and 'senior' were merged into the same field.
        # So to maintain backwards compatability, we set senior to the same value.
        senior = annual
        access = site['access'].upper() == 'YES'
        site_type = determine_site_type(site['name'], site['website'])

        sites = FederalSite.objects.filter(name=site['name'], city=site['city'])

        if len(sites) > 0:
            # If we encounter a duplicate, let's update instead of inserting.
            fs = sites[0]
        else:
            fs = FederalSite()

        fs.name = site['name']
        fs.site_type = site_type
        fs.phone = phone
        fs.phone_extension = phone_extension
        fs.city = site['city']
        fs.state = site['state']
        fs.website = site['website']
        fs.annual_pass = annual
        # All sites that have annual passes, also have senior passes. 
        fs.senior_pass = annual
        fs.access_pass = access
        fs.version = next_version
        fs.save()
示例#4
0
def process_site(site, next_version):
    """ Create an entry in the database for a federal site."""

    # Some rows in the CSV don't represent sites. This is indicative by them
    # missing the city name.
    if site['city'] != '':
        phone, phone_extension = phone_number(site['phone'])
        annual = site['annual'].upper() == 'YES'
        senior = site['senior'].upper() == 'YES'
        access = site['access'].upper() == 'YES'
        site_type = determine_site_type(site['name'], site['website'])

        sites = FederalSite.objects.filter(name=site['name'],
                                           city=site['city'])

        if len(sites) > 0:
            # If we encounter a duplicate, let's update instead of inserting.
            fs = sites[0]
        else:
            fs = FederalSite()

        fs.name = site['name']
        fs.site_type = site_type
        fs.phone = phone
        fs.phone_extension = phone_extension
        fs.city = site['city']
        fs.state = site['state']
        fs.website = site['website']
        fs.annual_pass = annual
        fs.senior_pass = senior
        fs.access_pass = access
        fs.version = next_version
        fs.save()