def get_countries(self, filter_for_book=False, filter_for_supervisor=False): book_filter = Q(in_book=True, visibility__visible_in_book=True) online_filter = Q(visibility__visible_online_public=True) places = Place.available_objects.filter( book_filter if filter_for_book else ( (book_filter | online_filter) if filter_for_supervisor else online_filter)) groups = Group.objects.exclude(user=None) countries = sort_by_name({p.country for p in places}) for country in countries: try: group = groups.get(name=country.code) country.supervisors = sorted( user.profile for user in group.user_set.filter( is_active=True, profile__isnull=False, profile__deleted_on__isnull=True)) except Group.DoesNotExist: pass places_for_country = places.filter(country=country) country.place_count = places_for_country.count() country.checked_count = places_for_country.filter( checked=True).count() country.only_confirmed_count = places_for_country.filter( confirmed=True, checked=False).count() return countries
def countries(self): places = Place.objects.filter(in_book=True) groups = Group.objects.exclude(user=None) countries = sort_by_name({p.country for p in places}) for country in countries: try: group = groups.get(name=str(country)) country.supervisors = sorted(user.profile for user in group.user_set.all()) except Group.DoesNotExist: pass country.place_count = places.filter(country=country).count() return countries
def countries(self): places = Place.available_objects.filter(in_book=True) groups = Group.objects.exclude(user=None) countries = sort_by_name({p.country for p in places}) for country in countries: try: group = groups.get(name=str(country)) country.supervisors = sorted(user.profile for user in group.user_set.all()) except Group.DoesNotExist: pass places_for_country = places.filter(country=country) country.place_count = places_for_country.count() country.checked_count = places_for_country.filter(checked=True).count() country.only_confirmed_count = places_for_country.filter( confirmed=True, checked=False).count() return countries
def countries(self): places = Place.available_objects.filter(in_book=True) groups = Group.objects.exclude(user=None) countries = sort_by_name({p.country for p in places}) for country in countries: try: group = groups.get(name=str(country)) country.supervisors = sorted(user.profile for user in group.user_set.all()) except Group.DoesNotExist: pass places_for_country = places.filter(country=country) country.place_count = places_for_country.count() country.checked_count = places_for_country.filter( checked=True).count() country.only_confirmed_count = places_for_country.filter( confirmed=True, checked=False).count() return countries
def get_countries(self, filter_for_book=False, filter_for_supervisor=False): book_filter = Q(in_book=True, visibility__visible_in_book=True) online_filter = Q(visibility__visible_online_public=True) places = Place.available_objects.filter( book_filter if filter_for_book else ((book_filter | online_filter) if filter_for_supervisor else online_filter) ) groups = Group.objects.exclude(user=None) countries = sort_by_name({p.country for p in places}) for country in countries: try: group = groups.get(name=country.code) country.supervisors = sorted( user.profile for user in group.user_set.filter( is_active=True, profile__isnull=False, profile__deleted_on__isnull=True) ) except Group.DoesNotExist: pass places_for_country = places.filter(country=country) country.place_count = places_for_country.count() country.checked_count = places_for_country.filter(checked=True).count() country.only_confirmed_count = places_for_country.filter( confirmed=True, checked=False).count() return countries