Rebase stats pull request (#120)

I added all changed from #120 and updated other things in stats module to use django-aggregate-if.

All tests passed, but project pages are not really tested yet.