from django.views.generic import ListView from django.shortcuts import get_object_or_404 from django.conf import settings from functions.cache_mixin import JitterCacheMixin, CacheMixin from meta.views import MetadataMixin from accounts.models import User from country.models import Country from city.models import City from translator.models import Translator class TranslatorList(JitterCacheMixin, MetadataMixin, ListView): model = User template_name = 'client/accounts/translators/translators_list.html' paginate_by = settings.CLIENT_PAGINATION def get_queryset(self): # all users with translator profile qs = self.model.objects.select_related('profile', 'country', 'city').filter(translator__isnull=False) if self.kwargs.get('city'): city_slug = self.kwargs.get('city') city = get_object_or_404(City, url=city_slug) self.kwargs['city'] = city qs = qs.filter(profile__city=city) if self.kwargs.get('country'): country_slug = self.kwargs.get('country') country = get_object_or_404(Country, url=country_slug) self.kwargs['country'] = country qs = qs.filter(profile__country=country) return qs