def load_data(data):
    """
    Loads data from each yaml file into the database.
    """

    # Load the agency
    name = data['name']
    slug = Agency.slug_for(name)
    a, created = Agency.objects.get_or_create(slug=slug, name=name)

    # Load the agency-specific values
    load_agency_fields(a, data)

    #   If the agency only has a single department the contactable fields
    if len(data['departments']) == 1:
        dept_rec = data['departments'][0]
        contactable_fields(a, dept_rec)

    a.save()
    add_request_time_statistics(data, a)

    # Load agency offices
    if len(data['departments']) > 1:
        for dept_rec in data['departments']:

            # If top-level=True office is saved as agency
            if dept_rec.get('top_level'):
                sub_agency_name = dept_rec['name']
                sub_agency_slug = Agency.slug_for(sub_agency_name)
                sub_agency, created = Agency.objects.get_or_create(
                    slug=sub_agency_slug, name=sub_agency_name)
                sub_agency.parent = a
                load_agency_fields(sub_agency, dept_rec)
                contactable_fields(sub_agency, dept_rec)
                sub_agency.save()
                add_request_time_statistics(dept_rec, sub_agency)

            else:
                # Just an office
                office_name = dept_rec['name']
                office_slug = Office.slug_for(office_name)
                full_slug = slug + '--' + office_slug

                o, created = Office.objects.get_or_create(agency=a,
                                                          slug=full_slug)

                o.office_slug = office_slug
                o.name = office_name
                contactable_fields(o, dept_rec)
                o.save()
                add_request_time_statistics(dept_rec, a, o)
Exemplo n.º 2
0
def load_data(data):
    """
    Loads data from each yaml file into the database.
    """

    # Load the agency
    name = data['name']
    slug = Agency.slug_for(name)
    a, created = Agency.objects.get_or_create(slug=slug, name=name)

    # Load the agency-specific values
    load_agency_fields(a, data)

    #   If the agency only has a single department the contactable fields
    if len(data['departments']) == 1:
        dept_rec = data['departments'][0]
        contactable_fields(a, dept_rec)

    a.save()
    add_request_time_statistics(data, a)

    # Load agency offices
    if len(data['departments']) > 1:
        for dept_rec in data['departments']:

            # If top-level=True office is saved as agency
            if dept_rec.get('top_level'):
                sub_agency_name = dept_rec['name']
                sub_agency_slug = Agency.slug_for(sub_agency_name)
                sub_agency, created = Agency.objects.get_or_create(
                    slug=sub_agency_slug, name=sub_agency_name)
                sub_agency.parent = a
                load_agency_fields(sub_agency, dept_rec)
                contactable_fields(sub_agency, dept_rec)
                sub_agency.save()
                add_request_time_statistics(dept_rec, sub_agency)

            else:
                # Just an office
                office_name = dept_rec['name']
                office_slug = Office.slug_for(office_name)
                full_slug = slug + '--' + office_slug

                o, created = Office.objects.get_or_create(
                    agency=a, slug=full_slug)

                o.office_slug = office_slug
                o.name = office_name
                contactable_fields(o, dept_rec)
                o.save()
                add_request_time_statistics(dept_rec, a, o)
def load_data(data):
    """
    Loads data from each yaml file into the database.
    """

    # Agencies
    name = data['name']
    slug = Agency.slug_for(name)

    a, created = Agency.objects.get_or_create(slug=slug, name=name)

    a.abbreviation = data['abbreviation']
    a.description = data.get('description')
    a.keywords = data.get('keywords')
    a.common_requests = data.get('common_requests', [])
    a.no_records_about = data.get('no_records_about', [])

    #   Only has a single, main branch/office
    if len(data['departments']) == 1:
        dept_rec = data['departments'][0]
        contactable_fields(a, dept_rec)

    a.save()
    add_request_time_statistics(data, a)

    # Offices
    if len(data['departments']) > 1:
        for dept_rec in data['departments']:
            if dept_rec.get('top_level'):
                # This is actually an agency
                sub_agency_name = dept_rec['name']
                sub_agency_slug = Agency.slug_for(sub_agency_name)

                sub_agency, created = Agency.objects.get_or_create(
                    slug=sub_agency_slug, name=sub_agency_name)
                sub_agency.parent = a

                abbreviation = dept_rec.get('abbreviation')
                if not abbreviation:
                    abbreviation = build_abbreviation(sub_agency_name)
                sub_agency.abbreviation = abbreviation

                sub_agency.description = dept_rec.get('description')
                sub_agency.keywords = dept_rec.get('keywords')
                sub_agency.common_requests = dept_rec.get(
                    'common_requests', [])
                sub_agency.no_records_about = dept_rec.get(
                    'no_records_about', [])
                contactable_fields(sub_agency, dept_rec)
                sub_agency.save()
                add_request_time_statistics(dept_rec, sub_agency)
            else:
                # Just an office
                office_name = dept_rec['name']
                office_slug = Office.slug_for(office_name)
                full_slug = slug + '--' + office_slug

                o, created = Office.objects.get_or_create(agency=a,
                                                          slug=full_slug)

                o.office_slug = office_slug
                o.name = office_name
                contactable_fields(o, dept_rec)
                o.save()
                add_request_time_statistics(dept_rec, a, o)
Exemplo n.º 4
0
def process_yamls(folder):

    # only load yaml files
    for item in iglob(folder + "/*.yaml"):
        data_file = os.path.join(folder, item)
        data = yaml.load(open(data_file))

        # Agencies
        name = data['name']
        slug = Agency.slug_for(name)

        a, created = Agency.objects.get_or_create(slug=slug, name=name)

        a.abbreviation = data['abbreviation']
        a.description = data.get('description')
        a.keywords = data.get('keywords')
        a.common_requests = data.get('common_requests', [])
        a.no_records_about = data.get('no_records_about', [])

        #   Only has a single, main branch/office
        if len(data['departments']) == 1:
            dept_rec = data['departments'][0]
            contactable_fields(a, dept_rec)

        a.save()
        add_request_time_statistics(data, a)

        # Offices
        if len(data['departments']) > 1:
            for dept_rec in data['departments']:
                if dept_rec.get('top_level'):
                    # This is actually an agency
                    sub_agency_name = dept_rec['name']
                    sub_agency_slug = Agency.slug_for(sub_agency_name)

                    sub_agency, created = Agency.objects.get_or_create(
                        slug=sub_agency_slug, name=sub_agency_name)
                    sub_agency.parent = a

                    abbreviation = build_abbreviation(sub_agency_name)
                    sub_agency.abbreviation = abbreviation
                    sub_agency.description = dept_rec.get('description')
                    sub_agency.keyword = dept_rec.get('keywords')
                    sub_agency.common_requests = dept_rec.get(
                        'common_requests', [])
                    sub_agency.no_records_about = dept_rec.get(
                        'no_records_about', [])
                    contactable_fields(sub_agency, dept_rec)
                    sub_agency.save()
                    add_request_time_statistics(dept_rec, sub_agency)
                else:
                    # Just an office
                    office_name = dept_rec['name']
                    office_slug = Office.slug_for(office_name)
                    full_slug = slug + '--' + office_slug

                    o, created = Office.objects.get_or_create(
                        agency=a, slug=full_slug)

                    o.office_slug = office_slug
                    o.name = office_name
                    contactable_fields(o, dept_rec)
                    o.save()
                    add_request_time_statistics(dept_rec, a, o)
Exemplo n.º 5
0
def process_yamls(folder):

    # only load yaml files
    for item in iglob(folder + "/*.yaml"):
        data_file = os.path.join(folder, item)
        data = yaml.load(open(data_file))

        # Agencies
        name = data['name']
        slug = Agency.slug_for(name)

        a, created = Agency.objects.get_or_create(slug=slug, name=name)

        a.abbreviation = data['abbreviation']
        a.description = data.get('description')
        a.keywords = data.get('keywords')
        a.common_requests = data.get('common_requests', [])
        a.no_records_about = data.get('no_records_about', [])

        #   Only has a single, main branch/office
        if len(data['departments']) == 1:
            dept_rec = data['departments'][0]
            contactable_fields(a, dept_rec)

        a.save()
        add_request_time_statistics(data, a)

        # Offices
        if len(data['departments']) > 1:
            for dept_rec in data['departments']:
                if dept_rec.get('top_level'):
                    # This is actually an agency
                    sub_agency_name = dept_rec['name']
                    sub_agency_slug = Agency.slug_for(sub_agency_name)

                    sub_agency, created = Agency.objects.get_or_create(
                        slug=sub_agency_slug, name=sub_agency_name)
                    sub_agency.parent = a

                    abbreviation = build_abbreviation(sub_agency_name)
                    sub_agency.abbreviation = abbreviation
                    sub_agency.description = dept_rec.get('description')
                    sub_agency.keyword = dept_rec.get('keywords')
                    sub_agency.common_requests = dept_rec.get(
                        'common_requests', [])
                    sub_agency.no_records_about = dept_rec.get(
                        'no_records_about', [])
                    contactable_fields(sub_agency, dept_rec)
                    sub_agency.save()
                    add_request_time_statistics(dept_rec, sub_agency)
                else:
                    # Just an office
                    office_name = dept_rec['name']
                    office_slug = Office.slug_for(office_name)
                    full_slug = slug + '--' + office_slug

                    o, created = Office.objects.get_or_create(agency=a,
                                                              slug=full_slug)

                    o.office_slug = office_slug
                    o.name = office_name
                    contactable_fields(o, dept_rec)
                    o.save()
                    add_request_time_statistics(dept_rec, a, o)