toolness/hive-django — pull request #27 by toolness (2014-06-26 20:17:22+00:00)
Title: Support multiple hive cities in one Django installation

Other cities (Chicago, Toronto, Chattanooga, Kansas City, etc) want to have their own Hive Directory.

I originally started this project as a single-city directory, assuming that other Hives could host their own instance, but there's a few wrinkles with this plan:

* Most/all the Hives don't actually have dedicated technical expertise required to deploy and maintain their own instance.
* Through interviews, we've found that there's a significant interest in having functionality that works *across* multiple Hive networks, e.g. making it possible for a Hive Toronto member to discover and connect with an expert in Fashion+Technology in Hive NYC.

One of the advantages of the current Hive Directory app, though, is the fact that it has a **local context**. People who have just joined Hive NYC, for example, don't usually want or need to connect with people in other cities, and showing them information about Hive networks around the world may be confusing. At the same time, though, there are use cases for cities to get up-and-running with their own directory quickly, and for some users to be able to explore the breadth of Hive networks around the world (particularly when their local context doesn't meet their needs).

To satisfy these needs, I propose adding a `City` model to the project, and use Django's [sites framework](https://docs.djangoproject.com/en/dev/ref/contrib/sites/) to make it possible for a site to represent either a specific city in its installation *or* the entire Hive ecosystem at large. The latter is indicated by setting a new setting, `settings.MULTI_CITY`, to `True`. Thus multiple sites could serve the needs of specific cities and the global ecosystem simultaneously.

When a site is multi-city, the URL structure changes such that the home page (`/`) is just a list of Hive cities, each of which is linked to a path like `/nyc/` or `/chicago/`, which contains a specific directory scoped to each city. By "directory" we mean organization list view and search functionality; organization detail pages are still hosted at `/orgs/`, users are still at `/users/`, and so forth. Views can subtly alter their display to cater to either the global or local context by examining the value of `MULTI_CITY` in templates; `site.city` can also be used to obtain information about the current city if the context is local. A new `city_url` template tag can also be used to reverse-map directory-related URLs regardless of the context.

New city-related filters and columns have been added to many admin views to make it possible to easily navigate the database for records pertaining to a specific city.

The Expertise Exchange app currently works in a global context: that is, if someone looks at the page for experts in Digital Solutions and Possibilities, they will see a list of everyone from all Hive cities that claim this expertise. This interface will be fine-tuned in the future.

Organization membership types are completely specific to particular cities: that is, because different Hives have completely different membership models for organizations, each city must define their membership types differently. A "community" member in Hive Chicago may mean something entirely different from a "community" member in Hive NYC, and individual Hives should have the freedom to define things the way they want.

The same goes for individual member roles. A "funding liason" in Hive Chicago may not mean anything in a Hive NYC context.

Potential risks:

* By putting all Hives into the same database, we're centralizing information in a way that may ultimately provide less flexibility than some Hive networks want or need. It also introduces a single point of failure into the operations of all Hive networks.
* Doing database migrations will require taking the directories for all Hive networks offline for a period of time.
* Accidental or intentional deletion of data through the Django admin UI could spill over from one city into another, e.g. an administrator from Hive Chicago could accidentally delete Hive NYC user data. (This can be alleviated by adding more access controls, but they're currently not implemented.)