Skip to content

Improve links #80

@ojongerius

Description

@ojongerius

Current "permalinks" use the pk, which we should not expose and which is not stable.

We could use UUIDs, slugs or a combination of the 2 to refer to individual jobs.

Adding UUIDs and slugs makes sense for all models, and we should probably link to the UUID instead of PK when establishing relationships.

Permalinks to jobs could look so. For this we'll need to create a slug based on the title.:

/job/{slug} ie: /job/nappy-changer-1

Some subtleties about this are:

  • The slug of an object needs to be unique for it work as a permalink, but titles of objects to not have this restriction. Hence the added "1" in the example.
  • Another awkwardness is the restriction on length 50 chars I believe, so we have to truncated the slug but keep the trailing digit(s).
  • Slugs should be created on object creation but not on updates. This is awkward when the title changes, but at least the object is stable, and the url communicates much more to humans and SEO than a UUID, or worse, the PK which is used in the current implementation.

And a job object would look like so -note that job, label, organisation and site ids have been replace by uuids:

{
  "id": bce3c97e-beb5-11e7-ad73-14109fd1f8cb,
  "title": "Marketing Coordinator | SEEK Volunteer",
  "text": "<SNIP>.",
  "labels": [
    370dda5e-4984-4653-9c16-c8107acec26e
  ],
  "organisation": {
    "id": 58abc8b0-676e-486d-9110-4fded2e84ee5,
    "name": "West Auckland Academic Mentoring | SEEK Volunteer",
    "description": "West Auckland Academic Mentoring provides free one-on-one academic support for West Auckland secondary school students.",
    "country": "NZ",
    "region": "placeholder",
    "city": "Auckland",
    "url": "https://seekvolunteer.co.nz/volunteering-organisations/903/west-auckland-academic-mentoring",
    "created_at": "2017-10-18T03:47:39.164728Z",
    "updated_at": "2017-10-18T03:47:39.164755Z"
  },
  "sites": [
    d305278e-5205-43ce-8c68-ecb89a6259ae
  ],
  "country": "NZ",
  "city": "Auckland",
  "region": null,
  "created_at": "2017-10-18T21:00:39.486002Z",
  "updated_at": "2017-10-18T21:00:39.486036Z",
  "url": "https://seekvolunteer.co.nz/volunteering/50715/marketing-coordinator",
  "seen": 0
}

UUIDs have been implemented in #87, ready to add slugs.

Blog post showing slugs in Django, includes adding a trailing incrementing number while truncating the non first part so that it fits in the 50 char limit. Have not read it closely yet but seems to tick all our boxes: https://keyerror.com/blog/automatically-generating-unique-slugs-in-django. http://django-autoslug.readthedocs.io/en/latest/fields.html does all the things for us.

This post looks useful for migrating existing data: https://stackoverflow.com/a/37310620/4372104

  • Add slugs for all models
  • Make sure all data is migrated forwards
  • Expose slug on Job card
  • Profit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions