Move trophies into the database.

Traditionally, when a trophy was awarded, it was just computed in an ad-hoc
manner every time the review request was displayed. This was fine for a basic
implementation, but made it impossible to do things like list all the trophies
that a user had been awarded, or extend the system with new trophy types.

This change lays the foundation for those features by creating a Trophy model,
an extensible set of trophy types, and the code to migrate old review requests
to this new system.

This is based on Behzad's change at /r/4857/. The only real changes I've made
were to clean up the rendering (through use of format_html and piggybacking
on the djblets_deco box template), include the image dimensions in the trophy
type definition, and make it work with users who don't specify their full name.
I've reproduced all of his original testing as well.

Testing Done:
* All unit tests pass.
* Checked with review requests 1000, 1001, and 3 and trophies were displayed
  correctly (or not at all).
* Also tested with a new database, filled with the fill-database script.
* Tested with review request ID's 1000, 10000, 1001, 2222, and 3. Appropriate
  trophies (or none at all) were awarded. The trophies' existence in the database
  was manually confirmed.

Reviewed at https://reviews.reviewboard.org/r/4857/
Use the new hosting service paginators for get_remote_repositories.

get_remote_repositories is now designed to support pagination, making
use of the new paginator classes. When calling get_remote_repositories,
the caller will get back an APIPaginator subclass that can be used to
paginate through all results.

The function also now takes a starting page for the pagination, and a
requested number of results per page.

This will make it easier to write web API that interfaces with
get_remote_repositories, allowing pagination to occur as expected by
callers.

Right now, only GitHub supports this function, so it's the only one that
is affected.

Reviewed at https://reviews.reviewboard.org/r/5886/
Add the missing trophies.py file.

I can use git, I swear.
Rename HostingServiceRepository to RemoteRepository and add new fields.

This standardizes on RemoteRepository as the name, which matches the
name of the upcoming API resource. It also adds some new fields to the
resource for storing the unique (per-service) ID of the repository and
the HostingService and account that the repository is linked to.

While in here, I noticed that the wrong field was being used to fetch
the repository's URL for GitHub. This updates to use `clone_url` instead
of `url`.

Reviewed at https://reviews.reviewboard.org/r/5896/
Provide reasonable defaults in get_remote_repositories.

get_remote_repositories() can now be called without passing any
information. Subclasses are expected to provide reasonable defaults,
like the account's username for the `owner` parameter.

Reviewed at https://reviews.reviewboard.org/r/5897/
Make the ID checks more restrict in the webapi test URL functions.

This enhances the logic of the various get_*_url() functions to be more
strict when they're willing to accept either an ID or an object.

A new function, _normalize_id(), checks if the value is an ID or an
instance (or subclass) of the allowed class type. If it's not any of
these things, then a ValueError will be raised.

This reduces the complexity of the code in the functions, prevents
duplication, and adds enhanced error checking.

Reviewed at https://reviews.reviewboard.org/r/5898/
Add unit tests for HostingServiceAccountResource.

This resource never had any accompanying tests when it was first
written. As we made changes to the resource or any other backing
services, we had no way of verifying that the code worked through the
API. It turns out, it didn't, as POSTing ended up calling save() on the
wrong object.

This introduces a basic test suite for this resource.

Reviewed at https://reviews.reviewboard.org/r/5891/
Add a link in the HostingService API to related accounts.

The HostingService resource now links to the HostingServiceAccounts
resource in order to easily query all accounts associated with that
service.

This required adding some filtering abilities to HostingServiceAccounts.
Callers can now filter on username or on the service ID.

Reviewed at https://reviews.reviewboard.org/r/5889/
Add a link in the HostingService API to related local repositories.

This adds a 'repositories' link in the HostingService item resource that
points to the Repository list resource, filtering on the given
service ID.

Reviewed https://reviews.reviewboard.org/r/5892/
Make use of FileDiff.is_new.

We have a property that does the comparison against PRE_CREATION for us, so we
might as well use it. This is just a simple cleanup.

Testing done:
* Ran unit tests.
* Checked diffs for new files.

Reviewed at https://reviews.reviewboard.org/r/5902/
Update imports to use the new djblets.webapi modules.

In /r/5899/, djblets.webapi.core was split into different modules. This
updates the Review Board imports to use the new modules, instead of
relying on the legacy core module.

Reviewed at https://reviews.reviewboard.org/r/5900/
Merge branch 'release-2.0.x'
Set a default for settings.AJAX_SERIAL when running unit tests.

The change to prevent extension reloading during tests needed an
accompanying trivial change to set settings.AJAX_SERIAL. This wasn't set
before, and unit tests depended on it. We were getting a working value,
though, because ExtensionManager recalculates it when loading
extensions.
Upgrade jquery.cookie to 1.4.1.

This is because of Bug 3387 where if any cookie exists on the domain that has
an invalid URL escaping, for example, a cookie like 'foo=%%', then the entire
site will roughly stop working. This was fixed upstream in jquery.cookie
between 1.3.1 and 1.4.1.

This can be verified by running the live 2.0.1 on a machine, and running the
following on a JS console:

```javascript
document.cookie = 'foo=%%';
```

and then refreshing the page. it will stop working; if you try to view a diff,
the parts will not load but will spin forever. This seems to be because the JS
fails to load. After applying this diff it will start working :). This
situation can occur if reviewboard is run on a subdomain like `rb.example.com`
and there are cookies on `example.com` that contain this kind of string. This
is a regression from 1.7

Testing Done:
Played around with the site and didn't see anything wrong. More testing would
be appreciated as this is my first review posted and whatnot. I'm just going to
roll this out internally to our site though and hope for the best :)

Bugs closed: 3387

Reviewed at https://reviews.reviewboard.org/r/5888/
Merge branch 'release-2.0.x'
Change the API for get_remote_repositories().

get_remote_repositories()'s API was using plan IDs as a way of
identifying users vs. organizations, which led to some redundancy.
For example, "private" and "public" for GitHub meant the same thing
(users). GitHub in particular was assuming certain filter types for
repositories, which would be handy to specify from a caller's point of
view.

The function has now been changed to remove the plan parameter and to
instead have a dedicated "owner_type" parameter that specifies what
"owner" refers to. The value is dependent on the hosting service, and
HostingService subclasses are expected to be smart about the defaults.

It also now takes a "filter_type" parameter that allows for filtering
repositories. Possible values are dependent on the hosting service as
well. For instance, GitHub's allowed values consist of what their API
natively allows for their "type=" parameter in repository queries.

Reviewed at https://reviews.reviewboard.org/r/5903/
Set a default for settings.AJAX_SERIAL when running unit tests.

The change to prevent extension reloading during tests needed an
accompanying trivial change to set settings.AJAX_SERIAL. This wasn't set
before, and unit tests depended on it. We were getting a working value,
though, because ExtensionManager recalculates it when loading
extensions.
Add support for API GET unit tests requiring admin logins.

The API unit test mixins now provide flags for specifying that the GET
tests require an admin account. This works just like the equivalent
tests for DELETE, POST, and PUT.

Reviewed at https://reviews.reviewboard.org/r/5912/
Add a profile field controlling whether users want to receive email.

Not everyone wants to get emails from Review Board. This change adds a flag to
the profile to control whether users will get anything directly addressed to
them.

This implementation was done on release-2.0.x because of the testing
infrastructure, but I also plan to backport this to release-1.7.x

Testing done:
* Ran unit tests
* Tested database evolution.
* Tested the account settings.

Reviewed at https://reviews.reviewboard.org/r/5907/
Merge branch 'release-2.0.x'