Added test for `tags_for_session` ajax endpoint
Refactored tags_for_session
Moved get_installed_tags_with_time to Tag model

As that function returns tags instances, it's probably better to bundle
it with the Tag model.

See also: https://redbeacon.github.io/2014/01/28/Fat-Models-a-Django-Code-Organization-Strategy/
Refactored get_installed_tags_with_time
Database prefetch optimization in get_installed_tags_with_time

Originally, the function first did two SQL queries to fetch the device
associated with the current session and the sessions associated with
that device, and then created a new query for each session up until
today (to fetch the related tags). This caused a complexity of `O(n +
2)`, where n is the number of sessions <= today.

By using the `prefetch_related('tag_set')` method, the ORM first does a
single query where all related tags are queried. The result is then
joined in Python, reducing the complexity to `O(3)`.

Things like these can be debugged easily when the `django_extensions`
package is installed:

    python manage.py shell_plus --print-sql