followers.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from misago.conf import settings
  2. from misago.core.shortcuts import paginate, pagination_dict
  3. from django.http import Http404
  4. from misago.users.online.utils import make_users_status_aware
  5. from misago.users.serializers import UserCardSerializer
  6. class Followers(object):
  7. def __init__(self, request, profile, page=0, search=None):
  8. queryset = self.get_queryset(profile).select_related(
  9. 'rank', 'ban_cache', 'online_tracker').order_by('slug')
  10. if search:
  11. name_starts_with = search.strip().lower()
  12. if name_starts_with:
  13. queryset = queryset.filter(slug__startswith=name_starts_with)
  14. else:
  15. raise Http404()
  16. list_page = paginate(queryset, page, settings.MISAGO_USERS_PER_PAGE, 4)
  17. make_users_status_aware(request.user, list_page.object_list)
  18. self.users = list_page.object_list
  19. self.paginator = pagination_dict(list_page)
  20. def get_queryset(self, profile):
  21. return profile.followed_by
  22. def get_frontend_context(self):
  23. context = {
  24. 'results': UserCardSerializer(self.users, many=True).data
  25. }
  26. context.update(self.paginator)
  27. return context
  28. def get_template_context(self):
  29. return {
  30. 'followers': self.users,
  31. 'count': self.paginator['count'],
  32. }