def get_queryset(self): organizations = Organization.objects.all() if 'hub' in self.request.query_params: project_category = Hub.objects.get( url_slug=self.request.query_params.get( 'hub')).filter_parent_tags.all() project_category_ids = list(map(lambda c: c.id, project_category)) project_tags = ProjectTags.objects.filter( id__in=project_category_ids) project_tags_with_children = ProjectTags.objects.filter( Q(parent_tag__in=project_tags) | Q(id__in=project_tags)) organizations = organizations.filter( Q(project_parent_org__project__tag_project__project_tag__in= project_tags_with_children) | Q(field_tag_organization__field_tag__in= project_tags_with_children)).distinct() if 'organization_type' in self.request.query_params: organization_type_names = self.request.query_params.get( 'organization_type').split(',') organization_types = OrganizationTags.objects.filter( name__in=organization_type_names) organization_taggings = OrganizationTagging.objects.filter( organization_tag__in=organization_types) organizations = organizations.filter( tag_organization__in=organization_taggings).distinct('id') if 'place' in self.request.query_params and 'osm' in self.request.query_params: location_data = get_location_with_range(self.request.query_params) organizations = organizations.filter( Q(location__country=location_data['country']) & (Q(location__multi_polygon__coveredby=( location_data['location'])) | Q(location__centre_point__coveredby=( location_data['location'])))).annotate( distance=Distance( "location__centre_point", location_data['location'])).order_by('distance') if 'country' and 'city' in self.request.query_params: location_ids = Location.objects.filter( country=self.request.query_params.get('country'), city=self.request.query_params.get('city')) organizations = organizations.filter(location__in=location_ids) if 'city' in self.request.query_params and not 'country' in self.request.query_params: location_ids = Location.objects.filter( city=self.request.query_params.get('city')) organizations = organizations.filter(location__in=location_ids) if 'country' in self.request.query_params and not 'city' in self.request.query_params: location_ids = Location.objects.filter( country=self.request.query_params.get('country')) organizations = organizations.filter(location__in=location_ids) return organizations
def get_queryset(self): user_profiles = UserProfile.objects\ .filter(is_profile_verified=True)\ .annotate(is_image_null=Count("image", filter=Q(image="")))\ .order_by("is_image_null", "-id") if 'skills' in self.request.query_params: skill_names = self.request.query_params.get('skills').split(',') skills = Skill.objects.filter(name__in=skill_names) user_profiles = user_profiles.filter( skills__in=skills).distinct('id') if 'place' in self.request.query_params and 'osm' in self.request.query_params: location_data = get_location_with_range(self.request.query_params) user_profiles = user_profiles.filter( Q(location__country=location_data['country']) & (Q(location__multi_polygon__distance_lte=( location_data['location'], location_data['radius'])) | Q(location__centre_point__distance_lte=( location_data['location'], location_data['radius'])))).annotate(distance=Distance( "location__centre_point", location_data['location'])).order_by('distance') if 'country' and 'city' in self.request.query_params: location_ids = Location.objects.filter( country=self.request.query_params.get('country'), city=self.request.query_params.get('city')) user_profiles = user_profiles.filter(location__in=location_ids) if 'city' in self.request.query_params and not 'country' in self.request.query_params: location_ids = Location.objects.filter( city=self.request.query_params.get('city')) user_profiles = user_profiles.filter(location__in=location_ids) if 'country' in self.request.query_params and not 'city' in self.request.query_params: location_ids = Location.objects.filter( country=self.request.query_params.get('country')) user_profiles = user_profiles.filter(location__in=location_ids) return user_profiles
def get_queryset(self): projects = Project.objects.filter(is_draft=False,is_active=True) if 'hub' in self.request.query_params: project_category = Hub.objects.get(url_slug=self.request.query_params.get('hub')).filter_parent_tags.all() project_category_ids = list(map(lambda c: c.id, project_category)) project_tags = ProjectTags.objects.filter(id__in=project_category_ids) project_tags_with_children = ProjectTags.objects.filter(Q(parent_tag__in=project_tags) | Q(id__in=project_tags)) projects = projects.filter( tag_project__project_tag__in=project_tags_with_children ).distinct() if 'collaboration' in self.request.query_params: collaborators_welcome = self.request.query_params.get('collaboration') if collaborators_welcome == 'yes': projects = projects.filter(collaborators_welcome=True) if collaborators_welcome == 'no': projects = projects.filter(collaborators_welcome=False) if 'category' in self.request.query_params: project_category = self.request.query_params.get('category').split(',') project_tags = ProjectTags.objects.filter(name__in=project_category) # Use .distinct to dedupe selected rows. # https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.distinct # We then sort by rating, to show most relevant results projects = projects.filter( tag_project__project_tag__in=project_tags, is_active=True ).distinct() if 'status' in self.request.query_params: statuses = self.request.query_params.get('status').split(',') projects = projects.filter(status__name__in=statuses) if 'skills' in self.request.query_params: skill_names = self.request.query_params.get('skills').split(',') skills = Skill.objects.filter(name__in=skill_names) # Use .distinct to dedupe selected rows. # https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.distinct # We then sort by rating, to show most relevant results projects = projects.filter(skills__in=skills).distinct() if 'organization_type' in self.request.query_params: organization_type_names = self.request.query_params.get('organization_type').split(',') organization_types = OrganizationTags.objects.filter(name__in=organization_type_names) organization_taggings = OrganizationTagging.objects.filter(organization_tag__in=organization_types) project_parents = ProjectParents.objects.filter(parent_organization__tag_organization__in=organization_taggings) projects = projects.filter(project_parent__in=project_parents) if 'place' in self.request.query_params and 'osm' in self.request.query_params: location_data = get_location_with_range(self.request.query_params) projects = projects.filter( Q(loc__country=location_data['country']) & ( Q(loc__multi_polygon__distance_lte=(location_data['location'], location_data['radius'])) | Q(loc__centre_point__distance_lte=(location_data['location'], location_data['radius'])) ) ).annotate( distance=Distance("loc__centre_point", location_data['location']) ).order_by( 'distance' ) if 'country' and 'city' in self.request.query_params: location_ids = Location.objects.filter( country=self.request.query_params.get('country'), city=self.request.query_params.get('city') ) projects = projects.filter(loc__in=location_ids) if 'city' in self.request.query_params and not 'country' in self.request.query_params: location_ids = Location.objects.filter( city=self.request.query_params.get('city') ) projects = projects.filter(loc__in=location_ids) if 'country' in self.request.query_params and not 'city' in self.request.query_params: location_ids = Location.objects.filter( country=self.request.query_params.get('country') ) projects = projects.filter(loc__in=location_ids) return projects