Fix infinite recursion when serializing object loops.

If two objects reference each other, and the relevant fields are listed in the
'expand' parameter, the serialization of the response would get a recursion
depth RuntimeError and return 500. This manifested in Review Board using the
"Depends On" field, with two review requests that referenced each other.

I've added some code to make each resource name in "expand" apply only once
for the entire serialization. This makes it possible to still expand deep into
object trees, but prevents infinite loops. To expand multiple levels with the
same resource name, it can be listed twice in 'expand'.

Testing done:
- Tested setting a review request's "Depends On" to itself.
- Tested a loop of two objects in "Depends On".
- Tested recursing multiple levels via:
  curl /api/review-requests/1/?expand=depends_on,depends_on | python -mjson.tool

Fixes bug 3442.

Reviewed at https://reviews.reviewboard.org/r/6095/