Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Add slugs to local authorities #20

Merged
merged 4 commits into from
Jun 10, 2016
Merged

Conversation

davidbasalla
Copy link

In order to add slugs to local authorities, we add a command to download the JSON file from the Frontend app, match the contained entries to Areas by 'gss' code and a new code of type 'govuk_slug' with the relevant slug.

We also update an existing script to check for any local authority Areas that we do not import a slug for.

)
code_type.save()

url = "https://raw.githubusercontent.com/alphagov/frontend/master/lib/data/authorities.json"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're putting slugs into MapIt so that they're available centrally and consistently to all apps, which means that MapIt should become the canonical source of LA slugs. Once we've got the slugs in MapIt we want to delete this file from Frontend and use the slugs from MapIt instead there, and also use the slugs from MapIt in local links manager and delete the import which uses this file. Instead of importing the slugs into MapIt from this file in Frontend we should store the data in this repo and load it from here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this while implementing and thought this might be step 1: "Import from frontend". We'd then follow this up with steps 2: "make frontend use mapit slugs instead of authorities.json", and 3: "move authorities.json out of frontend and into mapit as a fixture, changing this importer in the process". Was a bit worried about creating another list (even if the intention is that it becomes the canonical list) and someone has to remember to update it as well if (when?) any changes are made.

Happy to skip straight to the step 3 (with a copy instead of a move) and deal with the duplication later when we're finally ready to remove authorities.json post step 2.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think skipping straight to step 3 sounds reasonable. I've added the data file and the importer uses it to get the slugs.

@h-lame h-lame force-pushed the add-slugs-to-local-authorities branch from b989d96 to 8876420 Compare May 26, 2016 12:27
@davidbasalla davidbasalla force-pushed the add-slugs-to-local-authorities branch 2 times, most recently from 17a51a7 to 5014a76 Compare May 27, 2016 16:48
"north-down": {
"name": "North Down Borough Council",
"ons": "95W",
"gss": null
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not importing these slugs because they don't have GSS codes, so I wonder if we might as well delete them from the file?

Pro: smaller file, less to get confused about if you're not also looking at the importer
Con: we lose the history and the old slugs which would have existed as pages somewhere - perhaps if we do delete them we do it in a separate commit that only does the deletion so that there's some history.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to deleting these old local authorities from this file in a separate commit with some explanation.

@jennyd
Copy link

jennyd commented Jun 2, 2016

There are a few points in the second commit message which aren't quite accurate:

  • it refers to counties, which would be only CTY areas instead of all local authorities
  • it mentions LocalAuthority as though it's a class in this repo, which might be confusing to future us
  • it says that we import the JSON file from the 'frontend' app - having already said that we're copying the file over from Frontend it would be more accurate to omit this second reference to Frontend now

{
"buckinghamshire": {
"name": "Buckinghamshire County Council",
"ons": "11",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't using the SNACs or names from this file, so maybe we should remove them in a separate commit. We know we want to add more accurate names into MapIt for these areas so preserving this data structure has some value (instead of switching to a simpler structure like gss_code: slug) but these names aren't up-to-date at the moment and they aren't the ones in our database so it's probably less confusing to remove them (or change all the name values to null?).

@jennyd
Copy link

jennyd commented Jun 2, 2016

I don't have a working dev VM at the moment to try running any of this, but it looks to me like it should do the right thing...

@davidbasalla davidbasalla force-pushed the add-slugs-to-local-authorities branch 2 times, most recently from f644ba5 to 04b793a Compare June 7, 2016 08:38
defaults={'description': 'Slug for use by GOV.UK'}
)

file_path = os.path.join(dirname(__file__), '/../../data/authorities.json')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be os.path.dirname, and to remove the leading / on the path.

As part of the work to import local authority slugs, we need to be able to tell which Areas (that are Local Authorities) do not have a slug. We can reuse the existing 'mapit_UK_show_missing_codes' command by allowing it to accept arguments such as the `code_types` and `area_types`. We set the default values to be the previously hardcoded values so the script can still be called as it was before. However we do not want to check area_type 'EUR' for code_type 'govuk_slug', as we do not assign slugs to that area type. We add this exception to the code as a method call `is_code_type_required_for_area_type`.
MapIt will be the new canonical source for local authority slugs. We copy the authorities.json file from the Frontend app to MapIt. We also add the command to import the slugs from this file and assign them to the local authorities in MapIt.

We need to create a new CodeType called 'govuk_slug’. We step through each entry in the authorities.json file and retrieve the Area that matches the GSS code. For each matched Area, we create a new Code of CodeType 'govuk_slug' with the relevant slug.
We are not importing these entries as they have no GSS codes, so we delete them to avoid confusion about their presence in the file. These represent the old NI local authorities which were reformed in 2015. The new NI local authorities are already present in the file.
We are not using SNAC codes or names from this file, so we remove them. We retain the data structure (instead of switching to simpler structure like `gss_code: slug`) because we may want to reintroduce the `name` field with updated names in future.
@h-lame h-lame force-pushed the add-slugs-to-local-authorities branch from 04b793a to 4386c0a Compare June 8, 2016 11:05
@h-lame
Copy link

h-lame commented Jun 8, 2016

Left some comments about minor code problems, which I promptly fixup and rebased away. Probably wants someone else to merge this now as I worked with @davidbasalla on the original implementation as well as these latest fixes.

@sihugh
Copy link

sihugh commented Jun 10, 2016

I ran the import command:
GOVUK_ENV=development .venv/bin/python ./manage.py mapit_UK_add_slugs_to_local_authorities

Now, if I start up Mapit on the dev vm:
GOVUK_ENV=development ./startup.sh
and
curl http://mapit.dev.gov.uk/postcode/da157hq
then the codes returned include govuk_slug, e.g.
"codes": { "ons": "00AD", "gss": "E09000004", "govuk_slug": "bexley", "unit_id": "10759" },

👍

@sihugh sihugh merged commit 1f554f0 into master Jun 10, 2016
@sihugh sihugh deleted the add-slugs-to-local-authorities branch June 10, 2016 10:05
davidbasalla added a commit to alphagov/local-links-manager that referenced this pull request Jun 15, 2016
As of alphagov/mapit#20 MapIt returns the code type 'govuk_slug' for local authorities. We use it to set the slug for each LocalAuthority during the import.
davidbasalla added a commit to alphagov/local-links-manager that referenced this pull request Jun 15, 2016
As of alphagov/mapit#20 MapIt returns the code type 'govuk_slug' for local authorities. We use it to set the slug for each LocalAuthority during the import.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants